diff --git a/backend/__pycache__/react_app.cpython-38.pyc b/backend/__pycache__/react_app.cpython-38.pyc index ecc590f085e748de904d61d2f09cdf6924ceb902..485dcd8a662b2ee5ac691696d4aced6381802ab2 100644 Binary files a/backend/__pycache__/react_app.cpython-38.pyc and b/backend/__pycache__/react_app.cpython-38.pyc differ diff --git a/backend/react_app.py b/backend/react_app.py index 0e5f462b6f0bd0d982dff6e9f9a59a30b0ebc567..aafb3de63f9aceb1dfc1416c65b8954b2cacef50 100644 --- a/backend/react_app.py +++ b/backend/react_app.py @@ -4,8 +4,9 @@ from flask import Flask, request app = Flask(__name__) -@app.route('/home', methods=["POST"]) +@app.route('/home', methods=["GET", "POST"]) def home(): - data = request.json + print('in flask home') + data = request.get('') return data diff --git a/package.json b/package.json index 37a93f09ae113905cdcb94f358824a19988d2cf9..1ee4d3c5b33a5c3d084cfa62cc03efd5f2781bda 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "react_app_metarl", "version": "0.1.0", "private": true, + "proxy": "http://localhost:5000", "dependencies": { "@emotion/react": "^11.9.0", "@emotion/styled": "^11.8.1", diff --git a/src/App.js b/src/App.js index 55eae0354fa094e877669aee48492abe13beacb0..cb4b2354807ab84baba22cc52d5137d1a7224466 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,4 @@ -import Home from './pages/Home'; -import HomeOld from './pages/home_old' +import Home from './pages/Home' import './App.css'; import React, { useState, useEffect } from "react"; import axios from "axios"; @@ -8,20 +7,20 @@ import logo from './logo.svg'; // import {BrowerRouter as Router, Route, Switch} from 'react-router-dom'; function App() { - // useEffect(() => { - // fetch('/home', { - // method: 'POST', - // headers: { 'Content-Type': 'application/json' }, - // body: JSON.stringify({ }) - // }) - // .then((response) => response.text()) - // .then((data) => console.log(data)); - // }, []); + useEffect(() => { + console.log('print here') + fetch('/home', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ }) + }) + .then((response) => console.log(response.text())) + .then((data) => console.log(data)); + }, []); return ( <div> - {/* <Home /> */} - <HomeOld /> + <Home /> </div> ); } diff --git a/src/pages/Home.js b/src/pages/Home.js old mode 100755 new mode 100644 index 785403b23f79b637f5d8f43f0415a0479d9c1faa..c31eb21ab0619c048fcbcb85b4a875f9df8f9b94 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react"; -import { Grid, RadioGroup, FormControlLabel, FormControl, FormLabel, Radio, Card, CardContent, Typography } from '@mui/material'; -import {Button, TextField, Checkbox, FormGroup} from '@mui/material'; +import { Grid, RadioGroup, FormControlLabel, FormControl, FormLabel, Radio, Card, CardContent, Typography, AlertTitle } from '@mui/material'; +import {Button, TextField, Checkbox, Alert} from '@mui/material'; import { useForm, Controller} from "react-hook-form"; import SendIcon from '@mui/icons-material/Send'; import { CardActions, Collapse, IconButton } from "@mui/material"; @@ -21,16 +21,20 @@ const ExpandMore = styled((props) => { -// class Home extends React.Component{ + export default function Home() { const [selectLearner, setSelectLearner] = useState([]); + const [selectAction, setSelectAction] = useState([]); -// for form submission - const { control, handleSubmit, setValue} = useForm(); - const onSubmit = data => console.log(data); + // for form submission + const {register, control, handleSubmit, setValue, watch, formState: { errors, dirtyFields}} = useForm(); + const watchFileds = watch(['select_dataset', 'select_network']); + const onSubmit = data => console.log('data', data); + + console.log('errors', errors); -// handling learner selection + // handling learner selection const handleLearnerSelect = (value) => { const isPresent = selectLearner.indexOf(value); if (isPresent !== -1) { @@ -42,22 +46,35 @@ export default function Home() { }; useEffect(() => { - setValue('select-learner', selectLearner); + setValue('select_learner', selectLearner); }, [selectLearner]); -// collpase + // handling action selection + const handleActionSelect = (value) => { + const isPresent = selectAction.indexOf(value); + if (isPresent !== -1) { + const remaining = selectAction.filter((item) => item !== value); + setSelectAction(remaining); + } else { + setSelectAction((prevItems) => [...prevItems, value]); + } + }; + + useEffect(() => { + setValue('select_action', selectAction); + }, [selectAction]); + + // collpase const [expanded, setExpanded] = React.useState(false); const handleExpandClick = () => { setExpanded(!expanded); }; - return ( - <div className="App" style={{padding:"60px"}}> <Typography gutterBottom variant="h3" align="center" > - Data Auto-Augmentation + Data Auto-Augmentation Old </Typography> <Grid > <form action="/home" method="POST" onSubmit={handleSubmit(onSubmit)}> @@ -68,20 +85,20 @@ export default function Home() { Dataset Uploading </Typography> - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-dataset" align="left" variant="h6"> + <FormControl style={{ maxWidth: 800, padding:"20px"}} error={Boolean(errors.select_dataset)}> + <FormLabel id="select_dataset" align="left" variant="h6"> Please select the dataset you'd like to use here or select 'Other' if you would like to upload your own dataset </FormLabel> <Controller - name='select-dataset' + name='select_dataset' control={control} rules={{ required: true }} render={({field: { onChange, value }}) => ( <RadioGroup row - aria-labelledby="select-dataset" + aria-labelledby="select_dataset" // defaultValue="Other" - name="select-dataset" + name="select_dataset" align="centre" value={value ?? ""} onChange={onChange} @@ -92,19 +109,26 @@ export default function Home() { <FormControlLabel value="CIFAR10" control={<Radio />} label="CIFAR10" /> <FormControlLabel value="CIFAR100" control={<Radio />} label="CIFAR100" /> <FormControlLabel value="Other" control={<Radio />} label="Other" /> - </RadioGroup> )} + </RadioGroup> + )} /> + {errors.select_dataset && errors.select_dataset.type === "required" && + <Alert severity="error"> + <AlertTitle>This field is required</AlertTitle> + </Alert>} <Button variant="contained" component="label" - > Upload File <input + {...register('ds_upload')} + name="ds_upload" type="file" hidden /> </Button> + {dirtyFields.ds_upload && <Alert severity="success" variant='outlined'>File Submitted</Alert>} </FormControl> </CardContent> </Card> @@ -116,19 +140,19 @@ export default function Home() { Network Uploading </Typography> - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-network" align="left" variant="h6"> + <FormControl style={{ maxWidth: 800, padding:"20px"}} error={Boolean(errors.select_network)}> + <FormLabel id="select_network" align="left" variant="h6"> Please select the network you'd like to use here or select 'Other' if you would like to upload your own network </FormLabel> <Controller - name='select-network' + name='select_network' control={control} rules={{ required: true }} render={({field: { onChange, value }}) => ( <RadioGroup row - aria-labelledby="select-network" - name="select-network" + aria-labelledby="select_network" + name="select_network" align="centre" value={value ?? ""} onChange={onChange} @@ -139,6 +163,10 @@ export default function Home() { <FormControlLabel value="Other" control={<Radio />} label="Other" /> </RadioGroup> )} /> + {errors.select_network && errors.select_network.type === "required" && + <Alert severity="error"> + <AlertTitle>This field is required</AlertTitle> + </Alert>} <Typography style={{ maxWidth: 750}} variant="body2" color="textSecondary" component="p" gutterBottom align="left"> The networks provided above are for demonstration purposes. The relative training time is: LeNet {'>'} SimpleNet {'>'} EasyNet. We recommend you to choose EasyNet for a quick demonstration of how well our auto-augment agents can perform. @@ -149,10 +177,13 @@ export default function Home() { > Upload File <input + {...register('network_upload')} + name="network_upload" type="file" hidden /> </Button> + {dirtyFields.network_upload && <Alert severity="success" variant='outlined'>File Submitted</Alert>} </FormControl> </CardContent> </Card> @@ -165,9 +196,9 @@ export default function Home() { Auto-augment Learner Selection </Typography> - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-learner" align="left" variant="h6"> - Please select the auto-augment learner you'd like to use + <FormControl style={{ maxWidth: 800, padding:"20px"}} error={Boolean(errors.select_learner)}> + <FormLabel id="select_learner" align="left" variant="h6"> + Please select the auto-augment learners you'd like to use (multiple learners can be selected) </FormLabel> <div> {['UCB learner', 'Evolutionary learner', 'Random Searcher', 'GRU Learner'].map((option) => { @@ -175,7 +206,7 @@ export default function Home() { <FormControlLabel control={ <Controller - name='select-learner' + name='select_learner' render={({}) => { return ( <Checkbox @@ -183,6 +214,7 @@ export default function Home() { onChange={() => handleLearnerSelect(option)}/> ); }} control={control} + rules={{ required: true }} />} label={option} key={option} @@ -190,6 +222,10 @@ export default function Home() { ); })} </div> + {errors.select_learner && errors.select_learner.type === "required" && + <Alert severity="error"> + <AlertTitle>This field is required</AlertTitle> + </Alert>} <Typography style={{ maxWidth: 800}} variant="body2" color="textSecondary" component="p" gutterBottom align="left"> (give user some recommendation here...) </Typography> @@ -228,16 +264,16 @@ export default function Home() { </Typography> <Grid container spacing={1} style={{maxWidth:800, padding:"10px 10px"}}> <Grid xs={12} sm={6} item> - <TextField name="batch_size" placeholder="Batch Size" label="Batch Size" variant="outlined" fullWidth /> + <TextField {...register("batch_size")} name="batch_size" placeholder="Batch Size" label="Batch Size" variant="outlined" fullWidth /> </Grid> <Grid xs={12} sm={6} item> - <TextField name="learning_rate" placeholder="Learning Rate" label="Learning Rate" variant="outlined" fullWidth /> + <TextField {...register("learning_rate")} name="learning_rate" placeholder="Learning Rate" label="Learning Rate" variant="outlined" fullWidth /> </Grid> <Grid xs={12} sm={6} item> - <TextField name="iterations" placeholder="Number of Iterations" label="Iterations" variant="outlined" fullWidth /> + <TextField {...register("iterations")} name="iterations" placeholder="Number of Iterations" label="Iterations" variant="outlined" fullWidth /> </Grid> <Grid xs={12} sm={6} item> - <TextField name="toy_size" placeholder="Dataset Proportion" label="Dataset Proportion" variant="outlined" fullWidth /> + <TextField {...register("toy_size")} name="toy_size" placeholder="Dataset Proportion" label="Dataset Proportion" variant="outlined" fullWidth /> </Grid> <FormLabel variant="h8" align='centre'> * Dataset Proportion defines the percentage of original dataset our auto-augment learner will use to find the @@ -249,34 +285,29 @@ export default function Home() { <Typography gutterBottom variant="subtitle1" align='left'> Please select augmentation methods you'd like to exclude </Typography> - <Controller - name='select-action' - control={control} - rules={{ required: true }} - render={({field: { onChange, value }}) => ( - <FormGroup - row - aria-labelledby="select-action" - name="select-action" - value={value ?? ""} - onChange={onChange} - > - <FormControlLabel value="ShearX" control={<Checkbox />} label="ShearX" /> - <FormControlLabel value="ShearY" control={<Checkbox />} label="ShearY" /> - <FormControlLabel value="TranslateX" control={<Checkbox />} label="TranslateX" /> - <FormControlLabel value="TranslateY" control={<Checkbox />} label="TranslateY" /> - <FormControlLabel value="Rotate" control={<Checkbox />} label="Rotate" /> - <FormControlLabel value="Brightness" control={<Checkbox />} label="Brightness" /> - <FormControlLabel value="Color" control={<Checkbox />} label="Color" /> - <FormControlLabel value="Contrast" control={<Checkbox />} label="Contrast" /> - <FormControlLabel value="Sharpness" control={<Checkbox />} label="Sharpness" /> - <FormControlLabel value="Posterize" control={<Checkbox />} label="Posterize" /> - <FormControlLabel value="Solarize" control={<Checkbox />} label="Solarize" /> - <FormControlLabel value="AutoContrast" control={<Checkbox />} label="AutoContrast" /> - <FormControlLabel value="Equalize" control={<Checkbox />} label="Equalize" /> - <FormControlLabel value="Invert" control={<Checkbox />} label="Invert" /> - </FormGroup> )} - /> + <div> + {['ShearX', 'ShearY', 'TranslateX', 'TranslateY', 'Rotate', 'Brightness', + 'Color', 'Contrast', 'Sharpness', 'Posterize', 'Solarize', 'AutoContrast', + 'Equalize', 'Invert'].map((option) => { + return ( + <FormControlLabel + control={ + <Controller + name='select_action' + render={({}) => { + return ( + <Checkbox + checked={selectAction.includes(option)} + onChange={() => handleActionSelect(option)}/> ); + }} + control={control} + />} + label={option} + key={option} + /> + ); + })} + </div> </Grid> </CardContent> </Grid> @@ -284,6 +315,7 @@ export default function Home() { </Card> </Grid> + <Button type="submit" variant="contained" @@ -293,6 +325,12 @@ export default function Home() { > Submit Form </Button> + {watchFileds[0]==='Other' && !dirtyFields.ds_upload && + <Alert severity="error" variant='standard'>Please upload your dataset + zip file or select one of the dataset we have provided</Alert>} + {watchFileds[1]==='Other' && !dirtyFields.network_upload && + <Alert severity="error" variant='standard'>Please upload your network + .pkl file or select one of the network we have provided</Alert>} </form> </Grid> diff --git a/src/pages/home_old.js b/src/pages/home_old.js deleted file mode 100644 index 7ea55c0971a72a9e9032054204f26e283e2e6cc0..0000000000000000000000000000000000000000 --- a/src/pages/home_old.js +++ /dev/null @@ -1,318 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { Grid, RadioGroup, FormControlLabel, FormControl, FormLabel, Radio, Card, CardContent, Typography } from '@mui/material'; -import {Button, TextField, Checkbox, FormGroup} from '@mui/material'; -import { useForm, Controller} from "react-hook-form"; -import SendIcon from '@mui/icons-material/Send'; -import { CardActions, Collapse, IconButton } from "@mui/material"; -import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; -import { styled } from '@mui/material/styles'; - - -const ExpandMore = styled((props) => { - const { expand, ...other } = props; - return <IconButton {...other} />; - })(({ theme, expand }) => ({ - transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)', - marginLeft: 'auto', - transition: theme.transitions.create('transform', { - duration: theme.transitions.duration.shortest, - }), - })); - - - - -export default function Home() { - const [selectLearner, setSelectLearner] = useState([]); - const [selectAction, setSelectAction] = useState([]); - - // for form submission - const {register, control, handleSubmit, setValue} = useForm(); - const onSubmit = data => console.log(data); - - - // handling learner selection - const handleLearnerSelect = (value) => { - const isPresent = selectLearner.indexOf(value); - if (isPresent !== -1) { - const remaining = selectLearner.filter((item) => item !== value); - setSelectLearner(remaining); - } else { - setSelectLearner((prevItems) => [...prevItems, value]); - } - }; - - useEffect(() => { - setValue('select-learner', selectLearner); - }, [selectLearner]); - - // handling action selection - const handleActionSelect = (value) => { - const isPresent = selectAction.indexOf(value); - if (isPresent !== -1) { - const remaining = selectAction.filter((item) => item !== value); - setSelectAction(remaining); - } else { - setSelectAction((prevItems) => [...prevItems, value]); - } - }; - - useEffect(() => { - setValue('select-action', selectAction); - }, [selectAction]); - - // collpase - const [expanded, setExpanded] = React.useState(false); - - const handleExpandClick = () => { - setExpanded(!expanded); - }; - - - return ( - <div className="App" style={{padding:"60px"}}> - <Typography gutterBottom variant="h3" align="center" > - Data Auto-Augmentation Old - </Typography> - <Grid > - <form action="/home" method="POST" onSubmit={handleSubmit(onSubmit)}> - <Grid style={{padding:"30px 0px"}}> - <Card style={{ maxWidth: 900, padding: "10px 5px", margin: "0 auto" }}> - <CardContent> - <Typography gutterBottom variant="h5" align="left"> - Dataset Uploading - </Typography> - - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-dataset" align="left" variant="h6"> - Please select the dataset you'd like to use here or select 'Other' if you would like to upload your own dataset - </FormLabel> - <Controller - name='select-dataset' - control={control} - rules={{ required: true }} - render={({field: { onChange, value }}) => ( - <RadioGroup - row - aria-labelledby="select-dataset" - // defaultValue="Other" - name="select-dataset" - align="centre" - value={value ?? ""} - onChange={onChange} - > - <FormControlLabel value="MNIST" control={<Radio />} label="MNIST" /> - <FormControlLabel value="KMNIST" control={<Radio />} label="KMNIST" /> - <FormControlLabel value="FashionMNIST" control={<Radio />} label="FashionMNIST" /> - <FormControlLabel value="CIFAR10" control={<Radio />} label="CIFAR10" /> - <FormControlLabel value="CIFAR100" control={<Radio />} label="CIFAR100" /> - <FormControlLabel value="Other" control={<Radio />} label="Other" /> - </RadioGroup> )} - /> - <Button - variant="contained" - component="label" - > - Upload File - <input - // name="ds_upload" - // ref={register} - type="file" - hidden - /> - </Button> - </FormControl> - </CardContent> - </Card> - </Grid> - <Grid style={{padding:"30px 0px"}}> - <Card style={{ maxWidth: 900, padding: "10px 5px", margin: "0 auto" }}> - <CardContent> - <Typography gutterBottom variant="h5" align="left"> - Network Uploading - </Typography> - - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-network" align="left" variant="h6"> - Please select the network you'd like to use here or select 'Other' if you would like to upload your own network - </FormLabel> - <Controller - name='select-network' - control={control} - rules={{ required: true }} - render={({field: { onChange, value }}) => ( - <RadioGroup - row - aria-labelledby="select-network" - name="select-network" - align="centre" - value={value ?? ""} - onChange={onChange} - > - <FormControlLabel value="LeNet" control={<Radio />} label="LeNet" /> - <FormControlLabel value="SimpleNet" control={<Radio />} label="SimpleNet" /> - <FormControlLabel value="EasyNet" control={<Radio />} label="EasyNet" /> - <FormControlLabel value="Other" control={<Radio />} label="Other" /> - </RadioGroup> )} - /> - <Typography style={{ maxWidth: 750}} variant="body2" color="textSecondary" component="p" gutterBottom align="left"> - The networks provided above are for demonstration purposes. The relative training time is: LeNet {'>'} SimpleNet {'>'} EasyNet. - We recommend you to choose EasyNet for a quick demonstration of how well our auto-augment agents can perform. - </Typography> - <Button - variant="contained" - component="label" - > - Upload File - <input - // name="network_upload" - // ref={register} - type="file" - hidden - /> - </Button> - - </FormControl> - </CardContent> - </Card> - </Grid> - - <Grid style={{padding:"30px 0px"}}> - <Card style={{ maxWidth: 900, padding: "10px 5px", margin: "0 auto" }}> - <CardContent> - <Typography gutterBottom variant="h5" align="left"> - Auto-augment Learner Selection - </Typography> - - <FormControl style={{ maxWidth: 800, padding:"20px"}}> - <FormLabel id="select-learner" align="left" variant="h6"> - Please select the auto-augment learner you'd like to use - </FormLabel> - <div> - {['UCB learner', 'Evolutionary learner', 'Random Searcher', 'GRU Learner'].map((option) => { - return ( - <FormControlLabel - control={ - <Controller - name='select-learner' - render={({}) => { - return ( - <Checkbox - checked={selectLearner.includes(option)} - onChange={() => handleLearnerSelect(option)}/> ); - }} - control={control} - />} - label={option} - key={option} - /> - ); - })} - </div> - <Typography style={{ maxWidth: 800}} variant="body2" color="textSecondary" component="p" gutterBottom align="left"> - (give user some recommendation here...) - </Typography> - </FormControl> - </CardContent> - </Card> - </Grid> - - - <Grid style={{padding:"30px 0px", maxWidth: 900, margin: "0 auto"}}> - <Card style={{ maxWidth: 900, padding: "10px 5px", margin: "0 auto" }}> - <CardContent> - <Typography variant="h5" align="left"> - Advanced Search - </Typography> - </CardContent> - <CardActions disableSpacing> - <ExpandMore - expand={expanded} - onClick={handleExpandClick} - aria-expanded={expanded} - aria-label="show more" - > - <ExpandMoreIcon /> - </ExpandMore> - </CardActions> - <Collapse in={expanded} timeout="auto" unmountOnExit> - <Grid container - spacing={0} - direction="column" - alignItems="center" - justify="center"> - <CardContent> - <Typography gutterBottom variant="subtitle1" align='left'> - Please input the hyperparameter you'd like to train your dataset with - </Typography> - <Grid container spacing={1} style={{maxWidth:800, padding:"10px 10px"}}> - <Grid xs={12} sm={6} item> - <TextField {...register("batch_size")} name="batch_size" placeholder="Batch Size" label="Batch Size" variant="outlined" fullWidth /> - </Grid> - <Grid xs={12} sm={6} item> - <TextField {...register("learning_rate")} name="learning_rate" placeholder="Learning Rate" label="Learning Rate" variant="outlined" fullWidth /> - </Grid> - <Grid xs={12} sm={6} item> - <TextField {...register("iterations")} name="iterations" placeholder="Number of Iterations" label="Iterations" variant="outlined" fullWidth /> - </Grid> - <Grid xs={12} sm={6} item> - <TextField {...register("toy_size")} name="toy_size" placeholder="Dataset Proportion" label="Dataset Proportion" variant="outlined" fullWidth /> - </Grid> - <FormLabel variant="h8" align='centre'> - * Dataset Proportion defines the percentage of original dataset our auto-augment learner will use to find the - augmentation policy. If your dataset is large, we recommend you to set Dataset Proportion a small value (0.1-0.3). - </FormLabel> - </Grid> - - <Grid style={{maxWidth:800, padding:"40px 10px"}}> - <Typography gutterBottom variant="subtitle1" align='left'> - Please select augmentation methods you'd like to exclude - </Typography> - <div> - {['ShearX', 'ShearY', 'TranslateX', 'TranslateY', 'Rotate', 'Brightness', - 'Color', 'Contrast', 'Sharpness', 'Posterize', 'Solarize', 'AutoContrast', - 'Equalize', 'Invert'].map((option) => { - return ( - <FormControlLabel - control={ - <Controller - name='select-action' - render={({}) => { - return ( - <Checkbox - checked={selectAction.includes(option)} - onChange={() => handleActionSelect(option)}/> ); - }} - control={control} - />} - label={option} - key={option} - /> - ); - })} - </div> - </Grid> - </CardContent> - </Grid> - </Collapse> - - </Card> - </Grid> - <Button - type="submit" - variant="contained" - color='success' - size='large' - endIcon={<SendIcon />} - > - Submit Form - </Button> - </form> - - </Grid> - </div> - - ); - } - -// export default Home; diff --git a/src/setupProxy.js b/src/setupProxy.js deleted file mode 100644 index 928c19b9f6df4e0c8b9f7765c52e93334704cdb5..0000000000000000000000000000000000000000 --- a/src/setupProxy.js +++ /dev/null @@ -1,11 +0,0 @@ -const { createProxyMiddleware } = require('http-proxy-middleware'); - -module.exports = function(app) { - app.use( - '/api', - createProxyMiddleware({ - target: 'http://localhost:5000', - changeOrigin: true, - }) - ); -}; \ No newline at end of file