Skip to content
Snippets Groups Projects
Commit 065aba02 authored by Mia Wang's avatar Mia Wang
Browse files

connecting react with flask 3

parent f3a8f77d
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
"name": "react_app_metarl", "name": "react_app_metarl",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"proxy": "http://localhost:5000",
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.16.4", "@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1", "@testing-library/react": "^13.1.1",
...@@ -15,7 +14,7 @@ ...@@ -15,7 +14,7 @@
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"start-backend": "cd backend && flask run --no-debugger", "start-backend": "cd backend && env/bin/flask run --no-debugger",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
...@@ -37,5 +36,6 @@ ...@@ -37,5 +36,6 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
} },
"proxy": "http://127.0.0.1:5000"
} }
...@@ -2,64 +2,77 @@ import Home from './pages/Home'; ...@@ -2,64 +2,77 @@ import Home from './pages/Home';
import './App.css'; import './App.css';
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import axios from "axios"; import axios from "axios";
import logo from './logo.svg';
// import {BrowerRouter as Router, Route, Switch} from 'react-router-dom'; // import {BrowerRouter as Router, Route, Switch} from 'react-router-dom';
function App() { function App() {
// new line start
const [profileData, setProfileData] = useState(null)
const [formData, setFormData] = useState(null) function getData() {
axios({
method: "GET",
url:"/profile",
})
.then((response) => {
const res =response.data
setProfileData(({
profile_name: res.name,
about_me: res.about}))
}).catch((error) => {
if (error.response) {
console.log(error.response)
console.log(error.response.status)
console.log(error.response.headers)
}
})}
//end of new line
function getData() { return (
axios({ <div className="App">
method: "POST", <header className="App-header">
url:"/profile", <img src={logo} className="App-logo" alt="logo" />
}) <p>
.then((response) => { Edit <code>src/App.js</code> and save to reload.
const res =response.data </p>
setProfileData(({ <a
profile_name: res.name, className="App-link"
about_me: res.about})) href="https://reactjs.org"
}).catch((error) => { target="_blank"
if (error.response) { rel="noopener noreferrer"
console.log(error.response) >
console.log(error.response.status) Learn React
console.log(error.response.headers) </a>
}
})}
return ( {/* new line start*/}
<div className="App"> <p>To get your profile details: </p><button onClick={getData}>Click me</button>
<header className="App-header"> {profileData && <div>
<img src={logo} className="App-logo" alt="logo" /> <p>Profile name: {profileData.profile_name}</p>
<p> <p>About me: {profileData.about_me}</p>
Edit <code>src/App.js</code> and save to reload. </div>
</p> }
<a {/* end of new line */}
className="App-link" </header>
href="https://reactjs.org" </div>
target="_blank" );
rel="noopener noreferrer"
>
Learn React
</a>
{/* new line start*/}
<p>To get your profile details: </p><button onClick={getData}>Click me</button>
{profileData && <div>
<p>Profile name: {profileData.profile_name}</p>
<p>About me: {profileData.about_me}</p>
</div>
}
{/* end of new line */}
</header>
</div>
);
// return (
// <div>
// <Home />
// </div>
// );
} }
// useEffect(() => {
// fetch('/', {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({ })
// })
// .then((response) => response.json())
// .then((data) => console.log(data));
// }, []);
// return (
// <div>
// <Home />
// </div>
// );
// }
export default App; export default App;
...@@ -8,34 +8,34 @@ class Home extends React.Component{ ...@@ -8,34 +8,34 @@ class Home extends React.Component{
<div> <div>
<h1>Meta Reinforcement Learning for Data Augmentation</h1> <h1>Meta Reinforcement Learning for Data Augmentation</h1>
<h3>Choose your dataset</h3> <h3>Choose your dataset</h3>
<form action="/user_input" method="POST" enctype="multipart/form-data"> <form action="/user_input" method="POST" encType="multipart/form-data">
<label for="dataset_upload">You can upload your dataset folder here:</label> <label htmlFor="dataset_upload">You can upload your dataset folder here:</label>
<input type="file" id='dataset_upload' name="dataset_upload" class="upload" /><br></br> <input type="file" id='dataset_upload' name="dataset_upload" className="upload" /><br></br>
Or you can select a dataset from our database: <br/> Or you can select a dataset from our database: <br/>
<input type="radio" id="dataset1" <input type="radio" id="dataset1"
name="dataset_selection" value="MNIST" /> name="dataset_selection" value="MNIST" />
<label for="dataset1">MNIST dataset</label><br/> <label htmlFor="dataset1">MNIST dataset</label><br/>
<input type="radio" id="dataset2" <input type="radio" id="dataset2"
name="dataset_selection" value="KMNIST" /> name="dataset_selection" value="KMNIST" />
<label for="dataset2">KMNIST dataset</label><br /> <label htmlFor="dataset2">KMNIST dataset</label><br />
<input type="radio" id="dataset3" <input type="radio" id="dataset3"
name="dataset_selection" value="FashionMNIST" /> name="dataset_selection" value="FashionMNIST" />
<label for="dataset3">FashionMNIST dataset</label><br /> <label htmlFor="dataset3">FashionMNIST dataset</label><br />
<input type="radio" id="dataset4" <input type="radio" id="dataset4"
name="dataset_selection" value="CIFAR10" /> name="dataset_selection" value="CIFAR10" />
<label for="dataset4">CIFAR10 dataset</label><br /> <label htmlFor="dataset4">CIFAR10 dataset</label><br />
<input type="radio" id="dataset5" <input type="radio" id="dataset5"
name="dataset_selection" value="CIFAR100" /> name="dataset_selection" value="CIFAR100" />
<label for="dataset5">CIFAR100 dataset</label><br /> <label htmlFor="dataset5">CIFAR100 dataset</label><br />
<input type="radio" id="dataset6" <input type="radio" id="dataset6"
name="dataset_selection" value="Other" /> name="dataset_selection" value="Other" />
<label for="dataset6">Other dataset DIFFERENT</label><br /><br /> <label htmlFor="dataset6">Other dataset DIFFERENT</label><br /><br />
<input type="submit"></input> <input type="submit"></input>
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment