Skip to content

Commit 7ab4b4f

Browse files
authoredJun 26, 2022
Merge pull request #36 from nadinCodeHat/fix/update
Fix/update
2 parents e098e0a + af6f44a commit 7ab4b4f

File tree

8 files changed

+88
-88
lines changed

8 files changed

+88
-88
lines changed
 

‎api/api.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
api = Flask(__name__)
77
cors = CORS(api)
88

9+
910
@api.route('/translate/post', methods=['POST'])
1011
def recieve():
1112
data = request.get_json()
1213
json_str = json.dumps(data)
1314
resp = json.loads(json_str)
14-
15+
1516
global inputText, src, dst
1617

1718
inputText = resp['inputText']
1819
src = resp['srctext']
1920
dst = resp['dsttext']
20-
21+
2122
return "200 OK"
2223

2324

‎api/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
flask
44
flask-cors
5-
transformers==4.12.4
5+
python-dotenv
6+
transformers[torch]
67
sentencepiece

‎src/App.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import './App.scss';
2-
import React from 'react'
3-
import Layout from './layouts';
1+
import "./App.scss";
2+
import React from "react";
3+
import Layout from "./layouts";
44

55
function App() {
6-
return (
7-
<Layout />
8-
);
6+
return <Layout />;
97
}
108

119
export default App;

‎src/components/appbar.js

+21-31
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
1-
import * as React from 'react';
2-
import AppBar from '@mui/material/AppBar';
3-
import Toolbar from '@mui/material/Toolbar';
4-
import Typography from '@mui/material/Typography';
5-
import Container from '@mui/material/Container';
1+
import * as React from "react";
2+
import AppBar from "@mui/material/AppBar";
3+
import Toolbar from "@mui/material/Toolbar";
4+
import Typography from "@mui/material/Typography";
5+
import Container from "@mui/material/Container";
66

77
const ResponsiveAppBar = () => {
8-
return (
9-
<AppBar position="static">
10-
<Container maxWidth="xl">
11-
<Toolbar disableGutters>
12-
<Typography
13-
variant="h6"
14-
noWrap
15-
component="div"
16-
sx={{ mr: 2, display: { xs: 'none', md: 'flex' } }}
17-
>
18-
OpenTranslate
19-
</Typography>
20-
21-
22-
<Typography
23-
variant="h6"
24-
noWrap
25-
component="div"
26-
sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}
27-
>
28-
OpenTranslate
29-
</Typography>
30-
</Toolbar>
31-
</Container>
32-
</AppBar>
33-
);
8+
return (
9+
<AppBar position="static">
10+
<Container maxWidth="xl">
11+
<Toolbar disableGutters>
12+
<Typography
13+
variant="h6"
14+
noWrap
15+
component="div"
16+
sx={{ flexGrow: 1, textAlign: "center" }}
17+
>
18+
OpenTranslate (Machine Translation using HuggingFace Transformers)
19+
</Typography>
20+
</Toolbar>
21+
</Container>
22+
</AppBar>
23+
);
3424
};
3525
export default ResponsiveAppBar;

‎src/layouts/index.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import React from "react";
2-
import {
3-
BrowserRouter as Router
4-
} from "react-router-dom";
2+
import { BrowserRouter as Router } from "react-router-dom";
53
import PrimarySearchAppBar from "../components/appbar";
64
import routes from "../routes/routes";
75

8-
96
export default function Layout() {
10-
return (
11-
<Router>
12-
<div>
13-
<PrimarySearchAppBar />
7+
return (
8+
<Router>
9+
<div>
10+
<PrimarySearchAppBar />
1411

15-
{/*
12+
{/*
1613
A <Switch> looks through all its children <Route>
1714
elements and renders the first one whose path
1815
matches the current URL. Use a <Switch> any time
1916
you have multiple routes, but you want only one
2017
of them to render at a time
2118
*/}
22-
{routes}
23-
</div>
24-
</Router>
25-
);
26-
}
19+
{routes}
20+
</div>
21+
</Router>
22+
);
23+
}

‎src/pages/home.js

+30-15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Box from "@mui/material/Box";
88
import MuiGrid from "@mui/material/Grid";
99
import CompareArrowsIcon from "@mui/icons-material/CompareArrows";
1010
import TextField from "@mui/material/TextField";
11+
import Button from "@mui/material/Button";
1112
import "./home.scss";
1213
import axios from "axios";
1314

@@ -23,11 +24,14 @@ const TRANSLATION_API_BASE_URL_POST = "http://localhost:5000/translate/post";
2324
const TRANSLATION_API_BASE_URL_GET = "http://localhost:5000/translate/get";
2425

2526
export default function Home() {
26-
const languages = [
27+
const flanguage = [
2728
{
2829
value: "en",
2930
label: "English",
3031
},
32+
];
33+
34+
const tlanguage = [
3135
{
3236
value: "de",
3337
label: "German",
@@ -62,14 +66,13 @@ export default function Home() {
6266
setTranslateToLang(event.value);
6367
};
6468

65-
// Handle input text
69+
// Handle text translation
6670
const handleChangeTranslate = async (event) => {
67-
setTranslateText(event.target.value);
6871
//POST input text
6972
try {
7073
await axios
7174
.post(TRANSLATION_API_BASE_URL_POST, {
72-
inputText: event.target.value,
75+
inputText: translateText,
7376
srctext: translateFromLang,
7477
dsttext: translateToLang,
7578
})
@@ -81,7 +84,6 @@ export default function Home() {
8184
}
8285

8386
//GET translated text
84-
8587
try {
8688
await axios.get(TRANSLATION_API_BASE_URL_GET).then((response) => {
8789
setTranslatedText({
@@ -98,34 +100,36 @@ export default function Home() {
98100
};
99101

100102
return (
101-
<div style={{ marginTop: "1em" }}>
103+
<div style={{ marginTop: "5em" }}>
102104
<div className="translate-div">
105+
{/* Translate language from */}
103106
<div style={{ width: 500 }}>
104107
<Box sx={{ minWidth: 120 }}>
105108
<Select
106109
placeholder="Translate From"
107-
value={languages.find((obj) => obj.value === translateFromLang)}
108-
options={languages}
110+
value={flanguage.find((obj) => obj.value === translateFromLang)}
111+
options={flanguage}
109112
onChange={handleChangeTranslationFrom}
110113
></Select>
111114
</Box>
112115
</div>
113116

114117
<CompareArrowsIcon />
115118

119+
{/* Translate language to */}
116120
<div style={{ width: 500 }}>
117121
<Box sx={{ minWidth: 120 }}>
118122
<Select
119123
placeholder="Translate To"
120-
value={languages.find((obj) => obj.value === translateToLang)}
121-
options={languages}
124+
value={tlanguage.find((obj) => obj.value === translateToLang)}
125+
options={tlanguage}
122126
onChange={handleChangeTranslationTo}
123127
></Select>
124128
</Box>
125129
</div>
126130
</div>
127131

128-
<div className="card-div">
132+
<div className="cards-div">
129133
<Card
130134
sx={{
131135
width: 520,
@@ -142,13 +146,12 @@ export default function Home() {
142146
<TextField
143147
variant="standard"
144148
id="outlined-textarea"
145-
placeholder="Enter some text"
149+
placeholder="Enter some text here..."
146150
multiline
147151
autoFocus={true}
148152
fullWidth
149153
rows={13}
150-
value={translateText}
151-
onChange={handleChangeTranslate}
154+
onChange={(e) => setTranslateText(e.target.value)}
152155
InputProps={{
153156
disableUnderline: true,
154157
}}
@@ -182,6 +185,18 @@ export default function Home() {
182185
</CardContent>
183186
</Card>
184187
</div>
188+
<Button
189+
sx={{
190+
display: "block",
191+
width: "74em",
192+
height: "3em",
193+
margin: "10px auto 0px auto",
194+
}}
195+
variant="contained"
196+
onClick={handleChangeTranslate}
197+
>
198+
Translate
199+
</Button>
185200
</div>
186201
);
187-
}
202+
}

‎src/pages/home.scss

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
.translate-div {
2-
align-items: center;
3-
display: flex;
4-
justify-content: space-between;
5-
max-width: 65em;
6-
margin: 0 auto;
2+
align-items: center;
3+
display: flex;
4+
justify-content: space-between;
5+
max-width: 65em;
6+
margin: 0 auto;
7+
margin-bottom: 2em;
78
}
89

9-
.card-div {
10-
position: fixed;
11-
top: 50%;
12-
left: 50%;
13-
transform: translate( -50%, -50%);
14-
display: flex;
15-
justify-content: space-between;
16-
max-width: 67em;
17-
margin: 0 auto;
18-
}
10+
.cards-div {
11+
display: flex;
12+
justify-content: space-between;
13+
max-width: 67em;
14+
margin: 0 auto;
15+
margin-bottom: 1em;
16+
}

‎src/routes/routes.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Route, Routes } from "react-router-dom";
33
import Home from "../pages/home";
44

55
const routes = (
6-
<Routes>
7-
<Route path="/" element={<Home />} />
8-
</Routes>
6+
<Routes>
7+
<Route path="/" element={<Home />} />
8+
</Routes>
99
);
1010

11-
export default routes;
11+
export default routes;

0 commit comments

Comments
 (0)
Please sign in to comment.