Spaces:
Runtime error
Runtime error
grosenthal
commited on
Commit
•
a94b00b
1
Parent(s):
b424351
try to add frontend
Browse files- Dockerfile +7 -1
- app.py +10 -0
- src/aineid/.gitignore +23 -0
- src/aineid/README.md +59 -0
- src/aineid/package-lock.json +0 -0
- src/aineid/package.json +46 -0
- src/aineid/public/favicon.ico +0 -0
- src/aineid/public/index.html +43 -0
- src/aineid/public/logo192.png +0 -0
- src/aineid/public/logo512.png +0 -0
- src/aineid/public/manifest.json +25 -0
- src/aineid/public/robots.txt +3 -0
- src/aineid/src/App.test.tsx +10 -0
- src/aineid/src/App.tsx +33 -0
- src/aineid/src/ColorModeSwitcher.tsx +30 -0
- src/aineid/src/Logo.tsx +24 -0
- src/aineid/src/MainPage.jsx +107 -0
- src/aineid/src/TopBar.tsx +46 -0
- src/aineid/src/index.tsx +29 -0
- src/aineid/src/logo.svg +10 -0
- src/aineid/src/react-app-env.d.ts +1 -0
- src/aineid/src/reportWebVitals.ts +15 -0
- src/aineid/src/serviceWorker.ts +146 -0
- src/aineid/src/setupTests.ts +5 -0
- src/aineid/src/test-utils.tsx +12 -0
- src/aineid/tsconfig.json +27 -0
Dockerfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
# you will also find guides on how best to write your Dockerfile
|
3 |
|
4 |
-
FROM python:
|
5 |
|
6 |
WORKDIR /code
|
7 |
COPY lib/libgnat-4.9.so /usr/lib
|
@@ -22,7 +22,13 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
22 |
|
23 |
COPY --chown=user . .
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
26 |
|
27 |
RUN python -c "from cltk.data.fetch import FetchCorpus; corpus_downloader = FetchCorpus(language='lat');corpus_downloader.import_corpus('lat_models_cltk')"
|
28 |
|
|
|
1 |
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
# you will also find guides on how best to write your Dockerfile
|
3 |
|
4 |
+
FROM nikolaik/python-nodejs:python3.9-nodejs16
|
5 |
|
6 |
WORKDIR /code
|
7 |
COPY lib/libgnat-4.9.so /usr/lib
|
|
|
22 |
|
23 |
COPY --chown=user . .
|
24 |
|
25 |
+
COPY package.json yarn.lock ./
|
26 |
+
COPY ./src ./src
|
27 |
+
COPY ./public ./public
|
28 |
+
RUN yarn install
|
29 |
+
RUN yarn build
|
30 |
|
31 |
+
RUN ls
|
32 |
|
33 |
RUN python -c "from cltk.data.fetch import FetchCorpus; corpus_downloader = FetchCorpus(language='lat');corpus_downloader.import_corpus('lat_models_cltk')"
|
34 |
|
app.py
CHANGED
@@ -17,6 +17,7 @@ from cltk.text.processes import DefaultPunctuationRemovalProcess
|
|
17 |
from fastapi import FastAPI
|
18 |
from fastapi.responses import FileResponse
|
19 |
from fastapi.staticfiles import StaticFiles
|
|
|
20 |
from typing import Optional
|
21 |
import json
|
22 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
@@ -25,6 +26,15 @@ import json
|
|
25 |
import os
|
26 |
|
27 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
@dataclass
|
30 |
class LatinWhitakersWordsMorphology(Process):
|
|
|
17 |
from fastapi import FastAPI
|
18 |
from fastapi.responses import FileResponse
|
19 |
from fastapi.staticfiles import StaticFiles
|
20 |
+
from fastapi.middleware.cors import CORSMiddleware
|
21 |
from typing import Optional
|
22 |
import json
|
23 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
26 |
import os
|
27 |
|
28 |
app = FastAPI()
|
29 |
+
origins = ["*"]
|
30 |
+
|
31 |
+
app.add_middleware(
|
32 |
+
CORSMiddleware,
|
33 |
+
allow_origins=origins,
|
34 |
+
allow_credentials=True,
|
35 |
+
allow_methods=["*"],
|
36 |
+
allow_headers=["*"],
|
37 |
+
)
|
38 |
|
39 |
@dataclass
|
40 |
class LatinWhitakersWordsMorphology(Process):
|
src/aineid/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
2 |
+
|
3 |
+
# dependencies
|
4 |
+
/node_modules
|
5 |
+
/.pnp
|
6 |
+
.pnp.js
|
7 |
+
|
8 |
+
# testing
|
9 |
+
/coverage
|
10 |
+
|
11 |
+
# production
|
12 |
+
/build
|
13 |
+
|
14 |
+
# misc
|
15 |
+
.DS_Store
|
16 |
+
.env.local
|
17 |
+
.env.development.local
|
18 |
+
.env.test.local
|
19 |
+
.env.production.local
|
20 |
+
|
21 |
+
npm-debug.log*
|
22 |
+
yarn-debug.log*
|
23 |
+
yarn-error.log*
|
src/aineid/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
This project was bootstrapped with
|
2 |
+
[Create React App](https://github.com/facebook/create-react-app).
|
3 |
+
|
4 |
+
## Available Scripts
|
5 |
+
|
6 |
+
In the project directory, you can run:
|
7 |
+
|
8 |
+
### `npm start`
|
9 |
+
|
10 |
+
Runs the app in the development mode.<br /> Open
|
11 |
+
[http://localhost:3000](http://localhost:3000) to view it in the browser.
|
12 |
+
|
13 |
+
The page will reload if you make edits.<br /> You will also see any lint errors
|
14 |
+
in the console.
|
15 |
+
|
16 |
+
### `npm test`
|
17 |
+
|
18 |
+
Launches the test runner in the interactive watch mode.<br /> See the section
|
19 |
+
about
|
20 |
+
[running tests](https://facebook.github.io/create-react-app/docs/running-tests)
|
21 |
+
for more information.
|
22 |
+
|
23 |
+
### `npm run build`
|
24 |
+
|
25 |
+
Builds the app for production to the `build` folder.<br /> It correctly bundles
|
26 |
+
React in production mode and optimizes the build for the best performance.
|
27 |
+
|
28 |
+
The build is minified and the filenames include the hashes.<br /> Your app is
|
29 |
+
ready to be deployed!
|
30 |
+
|
31 |
+
See the section about
|
32 |
+
[deployment](https://facebook.github.io/create-react-app/docs/deployment) for
|
33 |
+
more information.
|
34 |
+
|
35 |
+
### `npm run eject`
|
36 |
+
|
37 |
+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
38 |
+
|
39 |
+
If you aren’t satisfied with the build tool and configuration choices, you can
|
40 |
+
`eject` at any time. This command will remove the single build dependency from
|
41 |
+
your project.
|
42 |
+
|
43 |
+
Instead, it will copy all the configuration files and the transitive
|
44 |
+
dependencies (webpack, Babel, ESLint, etc) right into your project so you have
|
45 |
+
full control over them. All of the commands except `eject` will still work, but
|
46 |
+
they will point to the copied scripts so you can tweak them. At this point
|
47 |
+
you’re on your own.
|
48 |
+
|
49 |
+
You don’t have to ever use `eject`. The curated feature set is suitable for
|
50 |
+
small and middle deployments, and you shouldn’t feel obligated to use this
|
51 |
+
feature. However we understand that this tool wouldn’t be useful if you couldn’t
|
52 |
+
customize it when you are ready for it.
|
53 |
+
|
54 |
+
## Learn More
|
55 |
+
|
56 |
+
You can learn more in the
|
57 |
+
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
58 |
+
|
59 |
+
To learn React, check out the [React documentation](https://reactjs.org/).
|
src/aineid/package-lock.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
src/aineid/package.json
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "aineid",
|
3 |
+
"version": "0.1.0",
|
4 |
+
"private": true,
|
5 |
+
"dependencies": {
|
6 |
+
"@chakra-ui/react": "^2.5.3",
|
7 |
+
"@emotion/react": "^11.10.6",
|
8 |
+
"@emotion/styled": "^11.10.6",
|
9 |
+
"@testing-library/jest-dom": "^5.16.5",
|
10 |
+
"@testing-library/react": "^13.4.0",
|
11 |
+
"@testing-library/user-event": "^14.4.3",
|
12 |
+
"@types/jest": "^28.1.8",
|
13 |
+
"@types/node": "^12.20.55",
|
14 |
+
"@types/react": "^18.0.29",
|
15 |
+
"@types/react-dom": "^18.0.11",
|
16 |
+
"axios": "^1.3.4",
|
17 |
+
"framer-motion": "^6.5.1",
|
18 |
+
"react": "^18.2.0",
|
19 |
+
"react-dom": "^18.2.0",
|
20 |
+
"react-icons": "^3.11.0",
|
21 |
+
"react-scripts": "5.0.1",
|
22 |
+
"typescript": "^4.9.5",
|
23 |
+
"web-vitals": "^2.1.4"
|
24 |
+
},
|
25 |
+
"scripts": {
|
26 |
+
"start": "react-scripts start",
|
27 |
+
"build": "react-scripts build",
|
28 |
+
"test": "react-scripts test",
|
29 |
+
"eject": "react-scripts eject"
|
30 |
+
},
|
31 |
+
"eslintConfig": {
|
32 |
+
"extends": "react-app"
|
33 |
+
},
|
34 |
+
"browserslist": {
|
35 |
+
"production": [
|
36 |
+
">0.2%",
|
37 |
+
"not dead",
|
38 |
+
"not op_mini all"
|
39 |
+
],
|
40 |
+
"development": [
|
41 |
+
"last 1 chrome version",
|
42 |
+
"last 1 firefox version",
|
43 |
+
"last 1 safari version"
|
44 |
+
]
|
45 |
+
}
|
46 |
+
}
|
src/aineid/public/favicon.ico
ADDED
src/aineid/public/index.html
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
7 |
+
<meta name="theme-color" content="#000000" />
|
8 |
+
<meta
|
9 |
+
name="description"
|
10 |
+
content="Web site created using create-react-app"
|
11 |
+
/>
|
12 |
+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
13 |
+
<!--
|
14 |
+
manifest.json provides metadata used when your web app is installed on a
|
15 |
+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
16 |
+
-->
|
17 |
+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
18 |
+
<!--
|
19 |
+
Notice the use of %PUBLIC_URL% in the tags above.
|
20 |
+
It will be replaced with the URL of the `public` folder during the build.
|
21 |
+
Only files inside the `public` folder can be referenced from the HTML.
|
22 |
+
|
23 |
+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
24 |
+
work correctly both with client-side routing and a non-root public URL.
|
25 |
+
Learn how to configure a non-root public URL by running `npm run build`.
|
26 |
+
-->
|
27 |
+
<title>React App</title>
|
28 |
+
</head>
|
29 |
+
<body>
|
30 |
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
31 |
+
<div id="root"></div>
|
32 |
+
<!--
|
33 |
+
This HTML file is a template.
|
34 |
+
If you open it directly in the browser, you will see an empty page.
|
35 |
+
|
36 |
+
You can add webfonts, meta tags, or analytics to this file.
|
37 |
+
The build step will place the bundled scripts into the <body> tag.
|
38 |
+
|
39 |
+
To begin the development, run `npm start` or `yarn start`.
|
40 |
+
To create a production bundle, use `npm run build` or `yarn build`.
|
41 |
+
-->
|
42 |
+
</body>
|
43 |
+
</html>
|
src/aineid/public/logo192.png
ADDED
src/aineid/public/logo512.png
ADDED
src/aineid/public/manifest.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"short_name": "React App",
|
3 |
+
"name": "Create React App Sample",
|
4 |
+
"icons": [
|
5 |
+
{
|
6 |
+
"src": "favicon.ico",
|
7 |
+
"sizes": "64x64 32x32 24x24 16x16",
|
8 |
+
"type": "image/x-icon"
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"src": "logo192.png",
|
12 |
+
"type": "image/png",
|
13 |
+
"sizes": "192x192"
|
14 |
+
},
|
15 |
+
{
|
16 |
+
"src": "logo512.png",
|
17 |
+
"type": "image/png",
|
18 |
+
"sizes": "512x512"
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"start_url": ".",
|
22 |
+
"display": "standalone",
|
23 |
+
"theme_color": "#000000",
|
24 |
+
"background_color": "#ffffff"
|
25 |
+
}
|
src/aineid/public/robots.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# https://www.robotstxt.org/robotstxt.html
|
2 |
+
User-agent: *
|
3 |
+
Disallow:
|
src/aineid/src/App.test.tsx
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react"
|
2 |
+
import { screen } from "@testing-library/react"
|
3 |
+
import { render } from "./test-utils"
|
4 |
+
import { App } from "./App"
|
5 |
+
|
6 |
+
test("renders learn react link", () => {
|
7 |
+
render(<App />)
|
8 |
+
const linkElement = screen.getByText(/learn chakra/i)
|
9 |
+
expect(linkElement).toBeInTheDocument()
|
10 |
+
})
|
src/aineid/src/App.tsx
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as React from "react"
|
2 |
+
import {
|
3 |
+
ChakraProvider,
|
4 |
+
Box,
|
5 |
+
Text,
|
6 |
+
Link,
|
7 |
+
VStack,
|
8 |
+
Spacer,
|
9 |
+
Flex,
|
10 |
+
theme,
|
11 |
+
useColorModeValue,
|
12 |
+
} from "@chakra-ui/react"
|
13 |
+
import { ColorModeSwitcher } from "./ColorModeSwitcher"
|
14 |
+
import { Logo } from "./Logo"
|
15 |
+
import TopBar from "./TopBar"
|
16 |
+
import MainPage from "./MainPage"
|
17 |
+
export const App = () => {
|
18 |
+
const bg = useColorModeValue("brand.800", "brand.200");
|
19 |
+
|
20 |
+
return (
|
21 |
+
<ChakraProvider theme={theme}>
|
22 |
+
<Flex direction="column" overflow='hidden'>
|
23 |
+
<Box>
|
24 |
+
<TopBar />
|
25 |
+
</Box>
|
26 |
+
<Box pt={73} mb={-73} >
|
27 |
+
<MainPage />
|
28 |
+
</Box>
|
29 |
+
|
30 |
+
</Flex>
|
31 |
+
</ChakraProvider>
|
32 |
+
)
|
33 |
+
}
|
src/aineid/src/ColorModeSwitcher.tsx
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as React from "react"
|
2 |
+
import {
|
3 |
+
useColorMode,
|
4 |
+
useColorModeValue,
|
5 |
+
IconButton,
|
6 |
+
IconButtonProps,
|
7 |
+
} from "@chakra-ui/react"
|
8 |
+
import { FaMoon, FaSun } from "react-icons/fa"
|
9 |
+
|
10 |
+
type ColorModeSwitcherProps = Omit<IconButtonProps, "aria-label">
|
11 |
+
|
12 |
+
export const ColorModeSwitcher: React.FC<ColorModeSwitcherProps> = (props) => {
|
13 |
+
const { toggleColorMode } = useColorMode()
|
14 |
+
const text = useColorModeValue("light", "dark")
|
15 |
+
const SwitchIcon = useColorModeValue(FaMoon, FaSun)
|
16 |
+
|
17 |
+
return (
|
18 |
+
<IconButton
|
19 |
+
size="md"
|
20 |
+
fontSize="lg"
|
21 |
+
variant="ghost"
|
22 |
+
color="current"
|
23 |
+
marginLeft="2"
|
24 |
+
onClick={toggleColorMode}
|
25 |
+
icon={<SwitchIcon />}
|
26 |
+
aria-label={`Switch to ${text} mode`}
|
27 |
+
{...props}
|
28 |
+
/>
|
29 |
+
)
|
30 |
+
}
|
src/aineid/src/Logo.tsx
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as React from "react"
|
2 |
+
import {
|
3 |
+
chakra,
|
4 |
+
keyframes,
|
5 |
+
ImageProps,
|
6 |
+
forwardRef,
|
7 |
+
usePrefersReducedMotion,
|
8 |
+
} from "@chakra-ui/react"
|
9 |
+
import logo from "./logo.svg"
|
10 |
+
|
11 |
+
const spin = keyframes`
|
12 |
+
from { transform: rotate(0deg); }
|
13 |
+
to { transform: rotate(360deg); }
|
14 |
+
`
|
15 |
+
|
16 |
+
export const Logo = forwardRef<ImageProps, "img">((props, ref) => {
|
17 |
+
const prefersReducedMotion = usePrefersReducedMotion()
|
18 |
+
|
19 |
+
const animation = prefersReducedMotion
|
20 |
+
? undefined
|
21 |
+
: `${spin} infinite 20s linear`
|
22 |
+
|
23 |
+
return <chakra.img animation={animation} src={logo} ref={ref} {...props} />
|
24 |
+
})
|
src/aineid/src/MainPage.jsx
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useState } from "react";
|
2 |
+
import {
|
3 |
+
Box,
|
4 |
+
Flex,
|
5 |
+
Heading,
|
6 |
+
useColorMode,
|
7 |
+
Input,
|
8 |
+
Textarea,
|
9 |
+
Text,
|
10 |
+
Button,
|
11 |
+
} from "@chakra-ui/react";
|
12 |
+
import axios from "axios";
|
13 |
+
|
14 |
+
function MainPage() {
|
15 |
+
const { colorMode } = useColorMode();
|
16 |
+
|
17 |
+
const bgColor = { light: "white", dark: "gray.800" };
|
18 |
+
const textColor = { light: "gray.700", dark: "gray.50" };
|
19 |
+
const placeholderColor = { light: "gray.400", dark: "gray.500" };
|
20 |
+
|
21 |
+
const [inputText, setInputText] = useState("");
|
22 |
+
const [translation, setTranslation] = useState({});
|
23 |
+
|
24 |
+
const handleInputChange = (event) => {
|
25 |
+
setInputText(event.target.value);
|
26 |
+
};
|
27 |
+
|
28 |
+
const handleSubmit = () => {
|
29 |
+
axios
|
30 |
+
.get(`https://grosenthal-latin-english-eco.hf.space/translate_all/?text=${inputText}`)
|
31 |
+
.then((response) => {
|
32 |
+
setTranslation(response.data);
|
33 |
+
})
|
34 |
+
.catch((error) => {
|
35 |
+
console.error(error);
|
36 |
+
});
|
37 |
+
};
|
38 |
+
|
39 |
+
return (
|
40 |
+
<Box mt="0rem">
|
41 |
+
<Flex
|
42 |
+
justify="center"
|
43 |
+
minH="100vh"
|
44 |
+
bgGradient={
|
45 |
+
colorMode == "dark"
|
46 |
+
? "linear(to-b, teal.400, teal.800)"
|
47 |
+
: "linear(red.100 0%, orange.100 25%, yellow.100 50%)"
|
48 |
+
}
|
49 |
+
mt={0}
|
50 |
+
>
|
51 |
+
<Flex direction="column" align="center">
|
52 |
+
<Box maxW="6xl" p={8} rounded="md" textAlign="center" mb={4}>
|
53 |
+
<Box>
|
54 |
+
<Heading as="h2" size="4xl" mb={8}>
|
55 |
+
The first open-source Latin to English translation system
|
56 |
+
</Heading>
|
57 |
+
<Text fontSize="xl" mb={8}>
|
58 |
+
AIneid beats Google Translate while offering a customizable and
|
59 |
+
transparent translation pipeline. The translations are not
|
60 |
+
guaranteed to be perfect.
|
61 |
+
</Text>
|
62 |
+
</Box>
|
63 |
+
</Box>
|
64 |
+
<Box
|
65 |
+
maxW="xl"
|
66 |
+
bg={bgColor[colorMode]}
|
67 |
+
boxShadow="xl"
|
68 |
+
p={8}
|
69 |
+
rounded="md"
|
70 |
+
textAlign="center"
|
71 |
+
>
|
72 |
+
{Object.keys(translation).length === 0 ? (
|
73 |
+
<Box>
|
74 |
+
<Textarea
|
75 |
+
placeholder="Latin to Translate"
|
76 |
+
size="lg"
|
77 |
+
_placeholder={{ color: placeholderColor[colorMode] }}
|
78 |
+
value={inputText}
|
79 |
+
onChange={handleInputChange}
|
80 |
+
resize="vertical"
|
81 |
+
mb={4}
|
82 |
+
/>
|
83 |
+
<Button colorScheme="teal" size="lg" onClick={handleSubmit}>
|
84 |
+
Submit
|
85 |
+
</Button>
|
86 |
+
</Box>
|
87 |
+
) : (
|
88 |
+
<Box>
|
89 |
+
{Object.entries(translation).map(([key, value]) => (
|
90 |
+
<Box key={key} mb={4}>
|
91 |
+
<Text fontWeight="bold">{key}:</Text>
|
92 |
+
<Text>{value[0]}</Text>
|
93 |
+
</Box>
|
94 |
+
))}
|
95 |
+
<Button colorScheme="teal" size="lg" onClick={() => setTranslation({})}>
|
96 |
+
Translate another text
|
97 |
+
</Button>
|
98 |
+
</Box>
|
99 |
+
)}
|
100 |
+
</Box>
|
101 |
+
</Flex>
|
102 |
+
</Flex>
|
103 |
+
</Box>
|
104 |
+
);
|
105 |
+
}
|
106 |
+
|
107 |
+
export default MainPage;
|
src/aineid/src/TopBar.tsx
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Box, Flex, useColorMode } from "@chakra-ui/react";
|
2 |
+
import { ColorModeSwitcher } from "./ColorModeSwitcher";
|
3 |
+
import { Heading } from "@chakra-ui/layout";
|
4 |
+
|
5 |
+
function TopBar() {
|
6 |
+
const { colorMode } = useColorMode();
|
7 |
+
const textColor = {
|
8 |
+
light: "gray.700",
|
9 |
+
dark: "gray.50"
|
10 |
+
};
|
11 |
+
|
12 |
+
return (
|
13 |
+
<Box
|
14 |
+
pos="fixed"
|
15 |
+
w="100%"
|
16 |
+
bg={colorMode === "light" ? "white" : "gray.800"}
|
17 |
+
borderBottom="1px"
|
18 |
+
borderColor={colorMode === "light" ? "gray.200" : "gray.900"}
|
19 |
+
zIndex="docked"
|
20 |
+
as="header"
|
21 |
+
mb={8}
|
22 |
+
>
|
23 |
+
<Flex
|
24 |
+
alignItems="center"
|
25 |
+
justifyContent="space-between"
|
26 |
+
py={4}
|
27 |
+
px={8}
|
28 |
+
>
|
29 |
+
<Heading
|
30 |
+
fontSize="xl"
|
31 |
+
fontWeight="bold"
|
32 |
+
color={textColor[colorMode]}
|
33 |
+
textAlign="center"
|
34 |
+
w="100%"
|
35 |
+
maxW="400px"
|
36 |
+
mx="auto"
|
37 |
+
>
|
38 |
+
AIneid
|
39 |
+
</Heading>
|
40 |
+
<ColorModeSwitcher justifySelf="flex-end" />
|
41 |
+
</Flex>
|
42 |
+
</Box>
|
43 |
+
);
|
44 |
+
}
|
45 |
+
|
46 |
+
export default TopBar;
|
src/aineid/src/index.tsx
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { ColorModeScript } from "@chakra-ui/react"
|
2 |
+
import * as React from "react"
|
3 |
+
import * as ReactDOM from "react-dom/client"
|
4 |
+
import { App } from "./App"
|
5 |
+
import reportWebVitals from "./reportWebVitals"
|
6 |
+
import * as serviceWorker from "./serviceWorker"
|
7 |
+
|
8 |
+
|
9 |
+
const container = document.getElementById("root")
|
10 |
+
if (!container) throw new Error('Failed to find the root element');
|
11 |
+
const root = ReactDOM.createRoot(container)
|
12 |
+
|
13 |
+
root.render(
|
14 |
+
<React.StrictMode>
|
15 |
+
<ColorModeScript />
|
16 |
+
<App />
|
17 |
+
</React.StrictMode>,
|
18 |
+
)
|
19 |
+
|
20 |
+
// If you want your app to work offline and load faster, you can change
|
21 |
+
// unregister() to register() below. Note this comes with some pitfalls.
|
22 |
+
// Learn more about service workers: https://cra.link/PWA
|
23 |
+
serviceWorker.unregister()
|
24 |
+
|
25 |
+
// If you want to start measuring performance in your app, pass a function
|
26 |
+
// to log results (for example: reportWebVitals(console.log))
|
27 |
+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
28 |
+
reportWebVitals()
|
29 |
+
|
src/aineid/src/logo.svg
ADDED
src/aineid/src/react-app-env.d.ts
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/// <reference types="react-scripts" />
|
src/aineid/src/reportWebVitals.ts
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { ReportHandler } from "web-vitals"
|
2 |
+
|
3 |
+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
4 |
+
if (onPerfEntry && onPerfEntry instanceof Function) {
|
5 |
+
import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
6 |
+
getCLS(onPerfEntry)
|
7 |
+
getFID(onPerfEntry)
|
8 |
+
getFCP(onPerfEntry)
|
9 |
+
getLCP(onPerfEntry)
|
10 |
+
getTTFB(onPerfEntry)
|
11 |
+
})
|
12 |
+
}
|
13 |
+
}
|
14 |
+
|
15 |
+
export default reportWebVitals
|
src/aineid/src/serviceWorker.ts
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// This optional code is used to register a service worker.
|
2 |
+
// register() is not called by default.
|
3 |
+
|
4 |
+
// This lets the app load faster on subsequent visits in production, and gives
|
5 |
+
// it offline capabilities. However, it also means that developers (and users)
|
6 |
+
// will only see deployed updates on subsequent visits to a page, after all the
|
7 |
+
// existing tabs open on the page have been closed, since previously cached
|
8 |
+
// resources are updated in the background.
|
9 |
+
|
10 |
+
// To learn more about the benefits of this model and instructions on how to
|
11 |
+
// opt-in, read https://cra.link/PWA
|
12 |
+
|
13 |
+
const isLocalhost = Boolean(
|
14 |
+
window.location.hostname === "localhost" ||
|
15 |
+
// [::1] is the IPv6 localhost address.
|
16 |
+
window.location.hostname === "[::1]" ||
|
17 |
+
// 127.0.0.0/8 are considered localhost for IPv4.
|
18 |
+
window.location.hostname.match(
|
19 |
+
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
|
20 |
+
),
|
21 |
+
)
|
22 |
+
|
23 |
+
type Config = {
|
24 |
+
onSuccess?: (registration: ServiceWorkerRegistration) => void
|
25 |
+
onUpdate?: (registration: ServiceWorkerRegistration) => void
|
26 |
+
}
|
27 |
+
|
28 |
+
export function register(config?: Config) {
|
29 |
+
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
|
30 |
+
// The URL constructor is available in all browsers that support SW.
|
31 |
+
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href)
|
32 |
+
if (publicUrl.origin !== window.location.origin) {
|
33 |
+
// Our service worker won't work if PUBLIC_URL is on a different origin
|
34 |
+
// from what our page is served on. This might happen if a CDN is used to
|
35 |
+
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
36 |
+
return
|
37 |
+
}
|
38 |
+
|
39 |
+
window.addEventListener("load", () => {
|
40 |
+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
|
41 |
+
|
42 |
+
if (isLocalhost) {
|
43 |
+
// This is running on localhost. Let's check if a service worker still exists or not.
|
44 |
+
checkValidServiceWorker(swUrl, config)
|
45 |
+
|
46 |
+
// Add some additional logging to localhost, pointing developers to the
|
47 |
+
// service worker/PWA documentation.
|
48 |
+
navigator.serviceWorker.ready.then(() => {
|
49 |
+
console.log(
|
50 |
+
"This web app is being served cache-first by a service " +
|
51 |
+
"worker. To learn more, visit https://cra.link/PWA",
|
52 |
+
)
|
53 |
+
})
|
54 |
+
} else {
|
55 |
+
// Is not localhost. Just register service worker
|
56 |
+
registerValidSW(swUrl, config)
|
57 |
+
}
|
58 |
+
})
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
function registerValidSW(swUrl: string, config?: Config) {
|
63 |
+
navigator.serviceWorker
|
64 |
+
.register(swUrl)
|
65 |
+
.then((registration) => {
|
66 |
+
registration.onupdatefound = () => {
|
67 |
+
const installingWorker = registration.installing
|
68 |
+
if (installingWorker == null) {
|
69 |
+
return
|
70 |
+
}
|
71 |
+
installingWorker.onstatechange = () => {
|
72 |
+
if (installingWorker.state === "installed") {
|
73 |
+
if (navigator.serviceWorker.controller) {
|
74 |
+
// At this point, the updated precached content has been fetched,
|
75 |
+
// but the previous service worker will still serve the older
|
76 |
+
// content until all client tabs are closed.
|
77 |
+
console.log(
|
78 |
+
"New content is available and will be used when all " +
|
79 |
+
"tabs for this page are closed. See https://cra.link/PWA.",
|
80 |
+
)
|
81 |
+
|
82 |
+
// Execute callback
|
83 |
+
if (config && config.onUpdate) {
|
84 |
+
config.onUpdate(registration)
|
85 |
+
}
|
86 |
+
} else {
|
87 |
+
// At this point, everything has been precached.
|
88 |
+
// It is the perfect time to display a
|
89 |
+
// "Content is cached for offline use." message.
|
90 |
+
console.log("Content is cached for offline use.")
|
91 |
+
|
92 |
+
// Execute callback
|
93 |
+
if (config && config.onSuccess) {
|
94 |
+
config.onSuccess(registration)
|
95 |
+
}
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
})
|
101 |
+
.catch((error) => {
|
102 |
+
console.error("Error during service worker registration:", error)
|
103 |
+
})
|
104 |
+
}
|
105 |
+
|
106 |
+
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
107 |
+
// Check if the service worker can be found. If it can't reload the page.
|
108 |
+
fetch(swUrl, {
|
109 |
+
headers: { "Service-Worker": "script" },
|
110 |
+
})
|
111 |
+
.then((response) => {
|
112 |
+
// Ensure service worker exists, and that we really are getting a JS file.
|
113 |
+
const contentType = response.headers.get("content-type")
|
114 |
+
if (
|
115 |
+
response.status === 404 ||
|
116 |
+
(contentType != null && contentType.indexOf("javascript") === -1)
|
117 |
+
) {
|
118 |
+
// No service worker found. Probably a different app. Reload the page.
|
119 |
+
navigator.serviceWorker.ready.then((registration) => {
|
120 |
+
registration.unregister().then(() => {
|
121 |
+
window.location.reload()
|
122 |
+
})
|
123 |
+
})
|
124 |
+
} else {
|
125 |
+
// Service worker found. Proceed as normal.
|
126 |
+
registerValidSW(swUrl, config)
|
127 |
+
}
|
128 |
+
})
|
129 |
+
.catch(() => {
|
130 |
+
console.log(
|
131 |
+
"No internet connection found. App is running in offline mode.",
|
132 |
+
)
|
133 |
+
})
|
134 |
+
}
|
135 |
+
|
136 |
+
export function unregister() {
|
137 |
+
if ("serviceWorker" in navigator) {
|
138 |
+
navigator.serviceWorker.ready
|
139 |
+
.then((registration) => {
|
140 |
+
registration.unregister()
|
141 |
+
})
|
142 |
+
.catch((error) => {
|
143 |
+
console.error(error.message)
|
144 |
+
})
|
145 |
+
}
|
146 |
+
}
|
src/aineid/src/setupTests.ts
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
2 |
+
// allows you to do things like:
|
3 |
+
// expect(element).toHaveTextContent(/react/i)
|
4 |
+
// learn more: https://github.com/testing-library/jest-dom
|
5 |
+
import "@testing-library/jest-dom"
|
src/aineid/src/test-utils.tsx
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as React from "react"
|
2 |
+
import { render, RenderOptions } from "@testing-library/react"
|
3 |
+
import { ChakraProvider, theme } from "@chakra-ui/react"
|
4 |
+
|
5 |
+
const AllProviders = ({ children }: { children?: React.ReactNode }) => (
|
6 |
+
<ChakraProvider theme={theme}>{children}</ChakraProvider>
|
7 |
+
)
|
8 |
+
|
9 |
+
const customRender = (ui: React.ReactElement, options?: RenderOptions) =>
|
10 |
+
render(ui, { wrapper: AllProviders, ...options })
|
11 |
+
|
12 |
+
export { customRender as render }
|
src/aineid/tsconfig.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"compilerOptions": {
|
3 |
+
"target": "es5",
|
4 |
+
"lib": [
|
5 |
+
"dom",
|
6 |
+
"dom.iterable",
|
7 |
+
"esnext"
|
8 |
+
],
|
9 |
+
"allowJs": true,
|
10 |
+
"skipLibCheck": true,
|
11 |
+
"esModuleInterop": true,
|
12 |
+
"allowSyntheticDefaultImports": true,
|
13 |
+
"strict": true,
|
14 |
+
"forceConsistentCasingInFileNames": true,
|
15 |
+
"noFallthroughCasesInSwitch": true,
|
16 |
+
"module": "esnext",
|
17 |
+
"moduleResolution": "node",
|
18 |
+
"resolveJsonModule": true,
|
19 |
+
"isolatedModules": true,
|
20 |
+
"noEmit": true,
|
21 |
+
"jsx": "react-jsx",
|
22 |
+
"useUnknownInCatchVariables": false
|
23 |
+
},
|
24 |
+
"include": [
|
25 |
+
"src"
|
26 |
+
]
|
27 |
+
}
|