pushing more stuff
Browse files- .eslintrc.cjs +21 -0
- .firebase/hosting.YnVpbGQ.cache +1 -0
- .firebase/hosting.ZGlzdA.cache +5 -0
- .firebaserc +5 -0
- .github/workflows/firebase-hosting-merge.yml +20 -0
- .github/workflows/firebase-hosting-pull-request.yml +17 -0
- .gitignore +24 -0
- build/index.html +89 -0
- firebase.json +16 -0
- index.html +13 -0
- package-lock.json +0 -0
- package.json +27 -0
- public/vite.svg +1 -0
- src/App.css +69 -0
- src/App.jsx +126 -0
- src/assets/react.svg +1 -0
- src/components/LanguageSelector.jsx +223 -0
- src/components/Progress.jsx +9 -0
- src/index.css +76 -0
- src/main.jsx +10 -0
- src/worker.js +55 -0
- vite.config.js +7 -0
.eslintrc.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = {
|
| 2 |
+
root: true,
|
| 3 |
+
env: { browser: true, es2020: true },
|
| 4 |
+
extends: [
|
| 5 |
+
'eslint:recommended',
|
| 6 |
+
'plugin:react/recommended',
|
| 7 |
+
'plugin:react/jsx-runtime',
|
| 8 |
+
'plugin:react-hooks/recommended',
|
| 9 |
+
],
|
| 10 |
+
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
| 11 |
+
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
|
| 12 |
+
settings: { react: { version: '18.2' } },
|
| 13 |
+
plugins: ['react-refresh'],
|
| 14 |
+
rules: {
|
| 15 |
+
'react/jsx-no-target-blank': 'off',
|
| 16 |
+
'react-refresh/only-export-components': [
|
| 17 |
+
'warn',
|
| 18 |
+
{ allowConstantExport: true },
|
| 19 |
+
],
|
| 20 |
+
},
|
| 21 |
+
}
|
.firebase/hosting.YnVpbGQ.cache
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
index.html,1708484286164,dd62ab59fd7d158d4cdf478f10a609a1d01c2f1a6952a4eb71ecad82786829de
|
.firebase/hosting.ZGlzdA.cache
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
index.html,1708485655272,495a445674a2413caed6caa5a93a462bf2c7a5e624d6200967e8c0fd6239a2bf
|
| 2 |
+
assets/index-bYbS0vAz.css,1708485655263,0cd57e518fbfc44706849cfeebaa06b9ff3d994d52a851c3cc14fce7f3691802
|
| 3 |
+
vite.svg,1708485655107,d3bbbc44b3ea71906a72bf2ec1a4716903e2e3d9f85a5007205a65d1f12e2923
|
| 4 |
+
assets/index-D7uBYrc6.js,1708485655264,6d41e5f5d8e5a3efb6014c0b7439a846df87635ee3f80fe67317cfa27282d2bc
|
| 5 |
+
assets/worker-1hc7Hdd2.js,1708485655272,92d86bcbcc4b73884f6ae50f6682615489062a640e1c2265bcb0e3cd17d004fb
|
.firebaserc
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"projects": {
|
| 3 |
+
"default": "soren-react-translator"
|
| 4 |
+
}
|
| 5 |
+
}
|
.github/workflows/firebase-hosting-merge.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file was auto-generated by the Firebase CLI
|
| 2 |
+
# https://github.com/firebase/firebase-tools
|
| 3 |
+
|
| 4 |
+
name: Deploy to Firebase Hosting on merge
|
| 5 |
+
'on':
|
| 6 |
+
push:
|
| 7 |
+
branches:
|
| 8 |
+
- main
|
| 9 |
+
jobs:
|
| 10 |
+
build_and_deploy:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
- run: npm ci && npm run build
|
| 15 |
+
- uses: FirebaseExtended/action-hosting-deploy@v0
|
| 16 |
+
with:
|
| 17 |
+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
| 18 |
+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SOREN_REACT_TRANSLATOR }}'
|
| 19 |
+
channelId: live
|
| 20 |
+
projectId: soren-react-translator
|
.github/workflows/firebase-hosting-pull-request.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file was auto-generated by the Firebase CLI
|
| 2 |
+
# https://github.com/firebase/firebase-tools
|
| 3 |
+
|
| 4 |
+
name: Deploy to Firebase Hosting on PR
|
| 5 |
+
'on': pull_request
|
| 6 |
+
jobs:
|
| 7 |
+
build_and_preview:
|
| 8 |
+
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
|
| 9 |
+
runs-on: ubuntu-latest
|
| 10 |
+
steps:
|
| 11 |
+
- uses: actions/checkout@v3
|
| 12 |
+
- run: npm ci && npm run build
|
| 13 |
+
- uses: FirebaseExtended/action-hosting-deploy@v0
|
| 14 |
+
with:
|
| 15 |
+
repoToken: '${{ secrets.GITHUB_TOKEN }}'
|
| 16 |
+
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_SOREN_REACT_TRANSLATOR }}'
|
| 17 |
+
projectId: soren-react-translator
|
.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Logs
|
| 2 |
+
logs
|
| 3 |
+
*.log
|
| 4 |
+
npm-debug.log*
|
| 5 |
+
yarn-debug.log*
|
| 6 |
+
yarn-error.log*
|
| 7 |
+
pnpm-debug.log*
|
| 8 |
+
lerna-debug.log*
|
| 9 |
+
|
| 10 |
+
node_modules
|
| 11 |
+
dist
|
| 12 |
+
dist-ssr
|
| 13 |
+
*.local
|
| 14 |
+
|
| 15 |
+
# Editor directories and files
|
| 16 |
+
.vscode/*
|
| 17 |
+
!.vscode/extensions.json
|
| 18 |
+
.idea
|
| 19 |
+
.DS_Store
|
| 20 |
+
*.suo
|
| 21 |
+
*.ntvs*
|
| 22 |
+
*.njsproj
|
| 23 |
+
*.sln
|
| 24 |
+
*.sw?
|
build/index.html
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>Welcome to Firebase Hosting</title>
|
| 7 |
+
|
| 8 |
+
<!-- update the version number as needed -->
|
| 9 |
+
<script defer src="/__/firebase/10.8.0/firebase-app-compat.js"></script>
|
| 10 |
+
<!-- include only the Firebase features as you need -->
|
| 11 |
+
<script defer src="/__/firebase/10.8.0/firebase-auth-compat.js"></script>
|
| 12 |
+
<script defer src="/__/firebase/10.8.0/firebase-database-compat.js"></script>
|
| 13 |
+
<script defer src="/__/firebase/10.8.0/firebase-firestore-compat.js"></script>
|
| 14 |
+
<script defer src="/__/firebase/10.8.0/firebase-functions-compat.js"></script>
|
| 15 |
+
<script defer src="/__/firebase/10.8.0/firebase-messaging-compat.js"></script>
|
| 16 |
+
<script defer src="/__/firebase/10.8.0/firebase-storage-compat.js"></script>
|
| 17 |
+
<script defer src="/__/firebase/10.8.0/firebase-analytics-compat.js"></script>
|
| 18 |
+
<script defer src="/__/firebase/10.8.0/firebase-remote-config-compat.js"></script>
|
| 19 |
+
<script defer src="/__/firebase/10.8.0/firebase-performance-compat.js"></script>
|
| 20 |
+
<!--
|
| 21 |
+
initialize the SDK after all desired features are loaded, set useEmulator to false
|
| 22 |
+
to avoid connecting the SDK to running emulators.
|
| 23 |
+
-->
|
| 24 |
+
<script defer src="/__/firebase/init.js?useEmulator=true"></script>
|
| 25 |
+
|
| 26 |
+
<style media="screen">
|
| 27 |
+
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
|
| 28 |
+
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px; border-radius: 3px; }
|
| 29 |
+
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
|
| 30 |
+
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
|
| 31 |
+
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
|
| 32 |
+
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
|
| 33 |
+
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
|
| 34 |
+
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
|
| 35 |
+
@media (max-width: 600px) {
|
| 36 |
+
body, #message { margin-top: 0; background: white; box-shadow: none; }
|
| 37 |
+
body { border-top: 16px solid #ffa100; }
|
| 38 |
+
}
|
| 39 |
+
</style>
|
| 40 |
+
</head>
|
| 41 |
+
<body>
|
| 42 |
+
<div id="message">
|
| 43 |
+
<h2>Welcome</h2>
|
| 44 |
+
<h1>Firebase Hosting Setup Complete</h1>
|
| 45 |
+
<p>You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!</p>
|
| 46 |
+
<a target="_blank" href="https://firebase.google.com/docs/hosting/">Open Hosting Documentation</a>
|
| 47 |
+
</div>
|
| 48 |
+
<p id="load">Firebase SDK Loading…</p>
|
| 49 |
+
|
| 50 |
+
<script>
|
| 51 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 52 |
+
const loadEl = document.querySelector('#load');
|
| 53 |
+
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
| 54 |
+
// // The Firebase SDK is initialized and available here!
|
| 55 |
+
//
|
| 56 |
+
// firebase.auth().onAuthStateChanged(user => { });
|
| 57 |
+
// firebase.database().ref('/path/to/ref').on('value', snapshot => { });
|
| 58 |
+
// firebase.firestore().doc('/foo/bar').get().then(() => { });
|
| 59 |
+
// firebase.functions().httpsCallable('yourFunction')().then(() => { });
|
| 60 |
+
// firebase.messaging().requestPermission().then(() => { });
|
| 61 |
+
// firebase.storage().ref('/path/to/ref').getDownloadURL().then(() => { });
|
| 62 |
+
// firebase.analytics(); // call to activate
|
| 63 |
+
// firebase.analytics().logEvent('tutorial_completed');
|
| 64 |
+
// firebase.performance(); // call to activate
|
| 65 |
+
//
|
| 66 |
+
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
| 67 |
+
|
| 68 |
+
try {
|
| 69 |
+
let app = firebase.app();
|
| 70 |
+
let features = [
|
| 71 |
+
'auth',
|
| 72 |
+
'database',
|
| 73 |
+
'firestore',
|
| 74 |
+
'functions',
|
| 75 |
+
'messaging',
|
| 76 |
+
'storage',
|
| 77 |
+
'analytics',
|
| 78 |
+
'remoteConfig',
|
| 79 |
+
'performance',
|
| 80 |
+
].filter(feature => typeof app[feature] === 'function');
|
| 81 |
+
loadEl.textContent = `Firebase SDK loaded with ${features.join(', ')}`;
|
| 82 |
+
} catch (e) {
|
| 83 |
+
console.error(e);
|
| 84 |
+
loadEl.textContent = 'Error loading the Firebase SDK, check the console.';
|
| 85 |
+
}
|
| 86 |
+
});
|
| 87 |
+
</script>
|
| 88 |
+
</body>
|
| 89 |
+
</html>
|
firebase.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"hosting": {
|
| 3 |
+
"public": "dist",
|
| 4 |
+
"ignore": [
|
| 5 |
+
"firebase.json",
|
| 6 |
+
"**/.*",
|
| 7 |
+
"**/node_modules/**"
|
| 8 |
+
],
|
| 9 |
+
"rewrites": [
|
| 10 |
+
{
|
| 11 |
+
"source": "**",
|
| 12 |
+
"destination": "/index.html"
|
| 13 |
+
}
|
| 14 |
+
]
|
| 15 |
+
}
|
| 16 |
+
}
|
index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Vite + React</title>
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div id="root"></div>
|
| 11 |
+
<script type="module" src="/src/main.jsx"></script>
|
| 12 |
+
</body>
|
| 13 |
+
</html>
|
package-lock.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "react-translator",
|
| 3 |
+
"private": true,
|
| 4 |
+
"version": "0.0.0",
|
| 5 |
+
"type": "module",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"dev": "vite",
|
| 8 |
+
"build": "vite build",
|
| 9 |
+
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
| 10 |
+
"preview": "vite preview"
|
| 11 |
+
},
|
| 12 |
+
"dependencies": {
|
| 13 |
+
"@xenova/transformers": "^2.15.0",
|
| 14 |
+
"react": "^18.2.0",
|
| 15 |
+
"react-dom": "^18.2.0"
|
| 16 |
+
},
|
| 17 |
+
"devDependencies": {
|
| 18 |
+
"@types/react": "^18.2.55",
|
| 19 |
+
"@types/react-dom": "^18.2.19",
|
| 20 |
+
"@vitejs/plugin-react": "^4.2.1",
|
| 21 |
+
"eslint": "^8.56.0",
|
| 22 |
+
"eslint-plugin-react": "^7.33.2",
|
| 23 |
+
"eslint-plugin-react-hooks": "^4.6.0",
|
| 24 |
+
"eslint-plugin-react-refresh": "^0.4.5",
|
| 25 |
+
"vite": "^5.1.0"
|
| 26 |
+
}
|
| 27 |
+
}
|
public/vite.svg
ADDED
|
|
src/App.css
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#root {
|
| 2 |
+
max-width: 1280px;
|
| 3 |
+
margin: 0 auto;
|
| 4 |
+
padding: 2rem;
|
| 5 |
+
text-align: center;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
.language-container {
|
| 9 |
+
display: flex;
|
| 10 |
+
gap: 20px;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
.textbox-container {
|
| 14 |
+
display: flex;
|
| 15 |
+
justify-content: center;
|
| 16 |
+
gap: 20px;
|
| 17 |
+
width: 800px;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.textbox-container>textarea, .language-selector {
|
| 21 |
+
width: 50%;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.language-selector>select {
|
| 25 |
+
width: 150px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.progress-container {
|
| 29 |
+
position: relative;
|
| 30 |
+
font-size: 14px;
|
| 31 |
+
color: white;
|
| 32 |
+
background-color: #e9ecef;
|
| 33 |
+
border: solid 1px;
|
| 34 |
+
border-radius: 8px;
|
| 35 |
+
text-align: left;
|
| 36 |
+
overflow: hidden;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.progress-bar {
|
| 40 |
+
padding: 0 4px;
|
| 41 |
+
z-index: 0;
|
| 42 |
+
top: 0;
|
| 43 |
+
width: 1%;
|
| 44 |
+
height: 100%;
|
| 45 |
+
overflow: hidden;
|
| 46 |
+
background-color: #007bff;
|
| 47 |
+
white-space: nowrap;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
.progress-text {
|
| 51 |
+
z-index: 2;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.selector-container {
|
| 55 |
+
display: flex;
|
| 56 |
+
gap: 20px;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.progress-bars-container {
|
| 60 |
+
padding: 8px;
|
| 61 |
+
height: 140px;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
.container {
|
| 65 |
+
margin: 25px;
|
| 66 |
+
display: flex;
|
| 67 |
+
flex-direction: column;
|
| 68 |
+
gap: 10px;
|
| 69 |
+
}
|
src/App.jsx
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useEffect, useRef, useState } from 'react'
|
| 2 |
+
import LanguageSelector from './components/LanguageSelector';
|
| 3 |
+
import Progress from './components/Progress';
|
| 4 |
+
|
| 5 |
+
import './App.css'
|
| 6 |
+
|
| 7 |
+
function App() {
|
| 8 |
+
|
| 9 |
+
// Model loading
|
| 10 |
+
const [ready, setReady] = useState(null);
|
| 11 |
+
const [disabled, setDisabled] = useState(false);
|
| 12 |
+
const [progressItems, setProgressItems] = useState([]);
|
| 13 |
+
|
| 14 |
+
// Inputs and outputs
|
| 15 |
+
const [input, setInput] = useState('I love walking my dog.');
|
| 16 |
+
const [sourceLanguage, setSourceLanguage] = useState('eng_Latn');
|
| 17 |
+
const [targetLanguage, setTargetLanguage] = useState('fra_Latn');
|
| 18 |
+
const [output, setOutput] = useState('');
|
| 19 |
+
|
| 20 |
+
// Create a reference to the worker object.
|
| 21 |
+
const worker = useRef(null);
|
| 22 |
+
|
| 23 |
+
// We use the `useEffect` hook to setup the worker as soon as the `App` component is mounted.
|
| 24 |
+
useEffect(() => {
|
| 25 |
+
if (!worker.current) {
|
| 26 |
+
// Create the worker if it does not yet exist.
|
| 27 |
+
worker.current = new Worker(new URL('./worker.js', import.meta.url), {
|
| 28 |
+
type: 'module'
|
| 29 |
+
});
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
// Create a callback function for messages from the worker thread.
|
| 33 |
+
const onMessageReceived = (e) => {
|
| 34 |
+
switch (e.data.status) {
|
| 35 |
+
case 'initiate':
|
| 36 |
+
// Model file start load: add a new progress item to the list.
|
| 37 |
+
setReady(false);
|
| 38 |
+
setProgressItems(prev => [...prev, e.data]);
|
| 39 |
+
break;
|
| 40 |
+
|
| 41 |
+
case 'progress':
|
| 42 |
+
// Model file progress: update one of the progress items.
|
| 43 |
+
setProgressItems(
|
| 44 |
+
prev => prev.map(item => {
|
| 45 |
+
if (item.file === e.data.file) {
|
| 46 |
+
return { ...item, progress: e.data.progress }
|
| 47 |
+
}
|
| 48 |
+
return item;
|
| 49 |
+
})
|
| 50 |
+
);
|
| 51 |
+
break;
|
| 52 |
+
|
| 53 |
+
case 'done':
|
| 54 |
+
// Model file loaded: remove the progress item from the list.
|
| 55 |
+
setProgressItems(
|
| 56 |
+
prev => prev.filter(item => item.file !== e.data.file)
|
| 57 |
+
);
|
| 58 |
+
break;
|
| 59 |
+
|
| 60 |
+
case 'ready':
|
| 61 |
+
// Pipeline ready: the worker is ready to accept messages.
|
| 62 |
+
setReady(true);
|
| 63 |
+
break;
|
| 64 |
+
|
| 65 |
+
case 'update':
|
| 66 |
+
// Generation update: update the output text.
|
| 67 |
+
setOutput(e.data.output);
|
| 68 |
+
break;
|
| 69 |
+
|
| 70 |
+
case 'complete':
|
| 71 |
+
// Generation complete: re-enable the "Translate" button
|
| 72 |
+
setDisabled(false);
|
| 73 |
+
break;
|
| 74 |
+
}
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
// Attach the callback function as an event listener.
|
| 78 |
+
worker.current.addEventListener('message', onMessageReceived);
|
| 79 |
+
|
| 80 |
+
// Define a cleanup function for when the component is unmounted.
|
| 81 |
+
return () => worker.current.removeEventListener('message', onMessageReceived);
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
const translate = () => {
|
| 85 |
+
setDisabled(true);
|
| 86 |
+
worker.current.postMessage({
|
| 87 |
+
text: input,
|
| 88 |
+
src_lang: sourceLanguage,
|
| 89 |
+
tgt_lang: targetLanguage,
|
| 90 |
+
});
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
return (
|
| 94 |
+
<>
|
| 95 |
+
<h1>Transformers.js</h1>
|
| 96 |
+
<h2>ML-powered multilingual translation in React!</h2>
|
| 97 |
+
|
| 98 |
+
<div className='container'>
|
| 99 |
+
<div className='language-container'>
|
| 100 |
+
<LanguageSelector type={"Source"} defaultLanguage={"eng_Latn"} onChange={x => setSourceLanguage(x.target.value)} />
|
| 101 |
+
<LanguageSelector type={"Target"} defaultLanguage={"fra_Latn"} onChange={x => setTargetLanguage(x.target.value)} />
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<div className='textbox-container'>
|
| 105 |
+
<textarea value={input} rows={3} onChange={e => setInput(e.target.value)}></textarea>
|
| 106 |
+
<textarea value={output} rows={3} readOnly></textarea>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<button disabled={disabled} onClick={translate}>Translate</button>
|
| 111 |
+
|
| 112 |
+
<div className='progress-bars-container'>
|
| 113 |
+
{ready === false && (
|
| 114 |
+
<label>Loading models... (only run once)</label>
|
| 115 |
+
)}
|
| 116 |
+
{progressItems.map(data => (
|
| 117 |
+
<div key={data.file}>
|
| 118 |
+
<Progress text={data.file} percentage={data.progress} />
|
| 119 |
+
</div>
|
| 120 |
+
))}
|
| 121 |
+
</div>
|
| 122 |
+
</>
|
| 123 |
+
)
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
export default App
|
src/assets/react.svg
ADDED
|
|
src/components/LanguageSelector.jsx
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// The full list of languages in FLORES-200 is available here:
|
| 3 |
+
// https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200
|
| 4 |
+
|
| 5 |
+
const LANGUAGES = {
|
| 6 |
+
"Acehnese (Arabic script)": "ace_Arab",
|
| 7 |
+
"Acehnese (Latin script)": "ace_Latn",
|
| 8 |
+
"Afrikaans": "afr_Latn",
|
| 9 |
+
"Akan": "aka_Latn",
|
| 10 |
+
"Amharic": "amh_Ethi",
|
| 11 |
+
"Armenian": "hye_Armn",
|
| 12 |
+
"Assamese": "asm_Beng",
|
| 13 |
+
"Asturian": "ast_Latn",
|
| 14 |
+
"Awadhi": "awa_Deva",
|
| 15 |
+
"Ayacucho Quechua": "quy_Latn",
|
| 16 |
+
"Balinese": "ban_Latn",
|
| 17 |
+
"Bambara": "bam_Latn",
|
| 18 |
+
"Banjar (Arabic script)": "bjn_Arab",
|
| 19 |
+
"Banjar (Latin script)": "bjn_Latn",
|
| 20 |
+
"Bashkir": "bak_Cyrl",
|
| 21 |
+
"Basque": "eus_Latn",
|
| 22 |
+
"Belarusian": "bel_Cyrl",
|
| 23 |
+
"Bemba": "bem_Latn",
|
| 24 |
+
"Bengali": "ben_Beng",
|
| 25 |
+
"Bhojpuri": "bho_Deva",
|
| 26 |
+
"Bosnian": "bos_Latn",
|
| 27 |
+
"Buginese": "bug_Latn",
|
| 28 |
+
"Bulgarian": "bul_Cyrl",
|
| 29 |
+
"Burmese": "mya_Mymr",
|
| 30 |
+
"Catalan": "cat_Latn",
|
| 31 |
+
"Cebuano": "ceb_Latn",
|
| 32 |
+
"Central Atlas Tamazight": "tzm_Tfng",
|
| 33 |
+
"Central Aymara": "ayr_Latn",
|
| 34 |
+
"Central Kanuri (Arabic script)": "knc_Arab",
|
| 35 |
+
"Central Kanuri (Latin script)": "knc_Latn",
|
| 36 |
+
"Central Kurdish": "ckb_Arab",
|
| 37 |
+
"Chhattisgarhi": "hne_Deva",
|
| 38 |
+
"Chinese (Simplified)": "zho_Hans",
|
| 39 |
+
"Chinese (Traditional)": "zho_Hant",
|
| 40 |
+
"Chokwe": "cjk_Latn",
|
| 41 |
+
"Crimean Tatar": "crh_Latn",
|
| 42 |
+
"Croatian": "hrv_Latn",
|
| 43 |
+
"Czech": "ces_Latn",
|
| 44 |
+
"Danish": "dan_Latn",
|
| 45 |
+
"Dari": "prs_Arab",
|
| 46 |
+
"Dutch": "nld_Latn",
|
| 47 |
+
"Dyula": "dyu_Latn",
|
| 48 |
+
"Dzongkha": "dzo_Tibt",
|
| 49 |
+
"Eastern Panjabi": "pan_Guru",
|
| 50 |
+
"Eastern Yiddish": "ydd_Hebr",
|
| 51 |
+
"Egyptian Arabic": "arz_Arab",
|
| 52 |
+
"English": "eng_Latn",
|
| 53 |
+
"Esperanto": "epo_Latn",
|
| 54 |
+
"Estonian": "est_Latn",
|
| 55 |
+
"Ewe": "ewe_Latn",
|
| 56 |
+
"Faroese": "fao_Latn",
|
| 57 |
+
"Fijian": "fij_Latn",
|
| 58 |
+
"Finnish": "fin_Latn",
|
| 59 |
+
"Fon": "fon_Latn",
|
| 60 |
+
"French": "fra_Latn",
|
| 61 |
+
"Friulian": "fur_Latn",
|
| 62 |
+
"Galician": "glg_Latn",
|
| 63 |
+
"Ganda": "lug_Latn",
|
| 64 |
+
"Georgian": "kat_Geor",
|
| 65 |
+
"German": "deu_Latn",
|
| 66 |
+
"Greek": "ell_Grek",
|
| 67 |
+
"Guarani": "grn_Latn",
|
| 68 |
+
"Gujarati": "guj_Gujr",
|
| 69 |
+
"Haitian Creole": "hat_Latn",
|
| 70 |
+
"Halh Mongolian": "khk_Cyrl",
|
| 71 |
+
"Hausa": "hau_Latn",
|
| 72 |
+
"Hebrew": "heb_Hebr",
|
| 73 |
+
"Hindi": "hin_Deva",
|
| 74 |
+
"Hungarian": "hun_Latn",
|
| 75 |
+
"Icelandic": "isl_Latn",
|
| 76 |
+
"Igbo": "ibo_Latn",
|
| 77 |
+
"Ilocano": "ilo_Latn",
|
| 78 |
+
"Indonesian": "ind_Latn",
|
| 79 |
+
"Irish": "gle_Latn",
|
| 80 |
+
"Italian": "ita_Latn",
|
| 81 |
+
"Japanese": "jpn_Jpan",
|
| 82 |
+
"Javanese": "jav_Latn",
|
| 83 |
+
"Jingpho": "kac_Latn",
|
| 84 |
+
"Kabiyè": "kbp_Latn",
|
| 85 |
+
"Kabuverdianu": "kea_Latn",
|
| 86 |
+
"Kabyle": "kab_Latn",
|
| 87 |
+
"Kamba": "kam_Latn",
|
| 88 |
+
"Kannada": "kan_Knda",
|
| 89 |
+
"Kashmiri (Arabic script)": "kas_Arab",
|
| 90 |
+
"Kashmiri (Devanagari script)": "kas_Deva",
|
| 91 |
+
"Kazakh": "kaz_Cyrl",
|
| 92 |
+
"Khmer": "khm_Khmr",
|
| 93 |
+
"Kikongo": "kon_Latn",
|
| 94 |
+
"Kikuyu": "kik_Latn",
|
| 95 |
+
"Kimbundu": "kmb_Latn",
|
| 96 |
+
"Kinyarwanda": "kin_Latn",
|
| 97 |
+
"Korean": "kor_Hang",
|
| 98 |
+
"Kyrgyz": "kir_Cyrl",
|
| 99 |
+
"Lao": "lao_Laoo",
|
| 100 |
+
"Latgalian": "ltg_Latn",
|
| 101 |
+
"Ligurian": "lij_Latn",
|
| 102 |
+
"Limburgish": "lim_Latn",
|
| 103 |
+
"Lingala": "lin_Latn",
|
| 104 |
+
"Lithuanian": "lit_Latn",
|
| 105 |
+
"Lombard": "lmo_Latn",
|
| 106 |
+
"Luba-Kasai": "lua_Latn",
|
| 107 |
+
"Luo": "luo_Latn",
|
| 108 |
+
"Luxembourgish": "ltz_Latn",
|
| 109 |
+
"Macedonian": "mkd_Cyrl",
|
| 110 |
+
"Magahi": "mag_Deva",
|
| 111 |
+
"Maithili": "mai_Deva",
|
| 112 |
+
"Malayalam": "mal_Mlym",
|
| 113 |
+
"Maltese": "mlt_Latn",
|
| 114 |
+
"Maori": "mri_Latn",
|
| 115 |
+
"Marathi": "mar_Deva",
|
| 116 |
+
"Meitei (Bengali script)": "mni_Beng",
|
| 117 |
+
"Mesopotamian Arabic": "acm_Arab",
|
| 118 |
+
"Minangkabau (Arabic script)": "min_Arab",
|
| 119 |
+
"Minangkabau (Latin script)": "min_Latn",
|
| 120 |
+
"Mizo": "lus_Latn",
|
| 121 |
+
"Modern Standard Arabic (Romanized)": "arb_Latn",
|
| 122 |
+
"Modern Standard Arabic": "arb_Arab",
|
| 123 |
+
"Moroccan Arabic": "ary_Arab",
|
| 124 |
+
"Mossi": "mos_Latn",
|
| 125 |
+
"Najdi Arabic": "ars_Arab",
|
| 126 |
+
"Nepali": "npi_Deva",
|
| 127 |
+
"Nigerian Fulfulde": "fuv_Latn",
|
| 128 |
+
"North Azerbaijani": "azj_Latn",
|
| 129 |
+
"North Levantine Arabic": "apc_Arab",
|
| 130 |
+
"Northern Kurdish": "kmr_Latn",
|
| 131 |
+
"Northern Sotho": "nso_Latn",
|
| 132 |
+
"Northern Uzbek": "uzn_Latn",
|
| 133 |
+
"Norwegian Bokmål": "nob_Latn",
|
| 134 |
+
"Norwegian Nynorsk": "nno_Latn",
|
| 135 |
+
"Nuer": "nus_Latn",
|
| 136 |
+
"Nyanja": "nya_Latn",
|
| 137 |
+
"Occitan": "oci_Latn",
|
| 138 |
+
"Odia": "ory_Orya",
|
| 139 |
+
"Pangasinan": "pag_Latn",
|
| 140 |
+
"Papiamento": "pap_Latn",
|
| 141 |
+
"Plateau Malagasy": "plt_Latn",
|
| 142 |
+
"Polish": "pol_Latn",
|
| 143 |
+
"Portuguese": "por_Latn",
|
| 144 |
+
"Romanian": "ron_Latn",
|
| 145 |
+
"Rundi": "run_Latn",
|
| 146 |
+
"Russian": "rus_Cyrl",
|
| 147 |
+
"Samoan": "smo_Latn",
|
| 148 |
+
"Sango": "sag_Latn",
|
| 149 |
+
"Sanskrit": "san_Deva",
|
| 150 |
+
"Santali": "sat_Olck",
|
| 151 |
+
"Sardinian": "srd_Latn",
|
| 152 |
+
"Scottish Gaelic": "gla_Latn",
|
| 153 |
+
"Serbian": "srp_Cyrl",
|
| 154 |
+
"Shan": "shn_Mymr",
|
| 155 |
+
"Shona": "sna_Latn",
|
| 156 |
+
"Sicilian": "scn_Latn",
|
| 157 |
+
"Silesian": "szl_Latn",
|
| 158 |
+
"Sindhi": "snd_Arab",
|
| 159 |
+
"Sinhala": "sin_Sinh",
|
| 160 |
+
"Slovak": "slk_Latn",
|
| 161 |
+
"Slovenian": "slv_Latn",
|
| 162 |
+
"Somali": "som_Latn",
|
| 163 |
+
"South Azerbaijani": "azb_Arab",
|
| 164 |
+
"South Levantine Arabic": "ajp_Arab",
|
| 165 |
+
"Southern Pashto": "pbt_Arab",
|
| 166 |
+
"Southern Sotho": "sot_Latn",
|
| 167 |
+
"Southwestern Dinka": "dik_Latn",
|
| 168 |
+
"Spanish": "spa_Latn",
|
| 169 |
+
"Standard Latvian": "lvs_Latn",
|
| 170 |
+
"Standard Malay": "zsm_Latn",
|
| 171 |
+
"Standard Tibetan": "bod_Tibt",
|
| 172 |
+
"Sundanese": "sun_Latn",
|
| 173 |
+
"Swahili": "swh_Latn",
|
| 174 |
+
"Swati": "ssw_Latn",
|
| 175 |
+
"Swedish": "swe_Latn",
|
| 176 |
+
"Tagalog": "tgl_Latn",
|
| 177 |
+
"Tajik": "tgk_Cyrl",
|
| 178 |
+
"Tamasheq (Latin script)": "taq_Latn",
|
| 179 |
+
"Tamasheq (Tifinagh script)": "taq_Tfng",
|
| 180 |
+
"Tamil": "tam_Taml",
|
| 181 |
+
"Tatar": "tat_Cyrl",
|
| 182 |
+
"Ta’izzi-Adeni Arabic": "acq_Arab",
|
| 183 |
+
"Telugu": "tel_Telu",
|
| 184 |
+
"Thai": "tha_Thai",
|
| 185 |
+
"Tigrinya": "tir_Ethi",
|
| 186 |
+
"Tok Pisin": "tpi_Latn",
|
| 187 |
+
"Tosk Albanian": "als_Latn",
|
| 188 |
+
"Tsonga": "tso_Latn",
|
| 189 |
+
"Tswana": "tsn_Latn",
|
| 190 |
+
"Tumbuka": "tum_Latn",
|
| 191 |
+
"Tunisian Arabic": "aeb_Arab",
|
| 192 |
+
"Turkish": "tur_Latn",
|
| 193 |
+
"Turkmen": "tuk_Latn",
|
| 194 |
+
"Twi": "twi_Latn",
|
| 195 |
+
"Ukrainian": "ukr_Cyrl",
|
| 196 |
+
"Umbundu": "umb_Latn",
|
| 197 |
+
"Urdu": "urd_Arab",
|
| 198 |
+
"Uyghur": "uig_Arab",
|
| 199 |
+
"Venetian": "vec_Latn",
|
| 200 |
+
"Vietnamese": "vie_Latn",
|
| 201 |
+
"Waray": "war_Latn",
|
| 202 |
+
"Welsh": "cym_Latn",
|
| 203 |
+
"West Central Oromo": "gaz_Latn",
|
| 204 |
+
"Western Persian": "pes_Arab",
|
| 205 |
+
"Wolof": "wol_Latn",
|
| 206 |
+
"Xhosa": "xho_Latn",
|
| 207 |
+
"Yoruba": "yor_Latn",
|
| 208 |
+
"Yue Chinese": "yue_Hant",
|
| 209 |
+
"Zulu": "zul_Latn",
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
export default function LanguageSelector({ type, onChange, defaultLanguage }) {
|
| 213 |
+
return (
|
| 214 |
+
<div className='language-selector'>
|
| 215 |
+
<label>{type}: </label>
|
| 216 |
+
<select onChange={onChange} defaultValue={defaultLanguage}>
|
| 217 |
+
{Object.entries(LANGUAGES).map(([key, value]) => {
|
| 218 |
+
return <option key={key} value={value}>{key}</option>
|
| 219 |
+
})}
|
| 220 |
+
</select>
|
| 221 |
+
</div>
|
| 222 |
+
)
|
| 223 |
+
}
|
src/components/Progress.jsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
export default function Progress({ text, percentage }) {
|
| 3 |
+
percentage = percentage ?? 0;
|
| 4 |
+
return (
|
| 5 |
+
<div className="progress-container">
|
| 6 |
+
<div className='progress-bar' style={{ 'width': `${percentage}%` }}>{text} ({`${percentage.toFixed(2)}%`})</div>
|
| 7 |
+
</div>
|
| 8 |
+
);
|
| 9 |
+
}
|
src/index.css
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:root {
|
| 2 |
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
| 3 |
+
line-height: 1.5;
|
| 4 |
+
font-weight: 400;
|
| 5 |
+
color: #213547;
|
| 6 |
+
background-color: #ffffff;
|
| 7 |
+
|
| 8 |
+
font-synthesis: none;
|
| 9 |
+
text-rendering: optimizeLegibility;
|
| 10 |
+
-webkit-font-smoothing: antialiased;
|
| 11 |
+
-moz-osx-font-smoothing: grayscale;
|
| 12 |
+
-webkit-text-size-adjust: 100%;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
margin: 0;
|
| 17 |
+
display: flex;
|
| 18 |
+
place-items: center;
|
| 19 |
+
min-width: 320px;
|
| 20 |
+
min-height: 100vh;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
h1 {
|
| 24 |
+
font-size: 3.2em;
|
| 25 |
+
line-height: 1;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
h1,
|
| 29 |
+
h2 {
|
| 30 |
+
margin: 8px;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
select {
|
| 34 |
+
padding: 0.3em;
|
| 35 |
+
cursor: pointer;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
textarea {
|
| 39 |
+
padding: 0.6em;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
button {
|
| 43 |
+
padding: 0.6em 1.2em;
|
| 44 |
+
cursor: pointer;
|
| 45 |
+
font-weight: 500;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
button[disabled] {
|
| 49 |
+
cursor: not-allowed;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
select,
|
| 53 |
+
textarea,
|
| 54 |
+
button {
|
| 55 |
+
border-radius: 8px;
|
| 56 |
+
border: 1px solid transparent;
|
| 57 |
+
font-size: 1em;
|
| 58 |
+
font-family: inherit;
|
| 59 |
+
background-color: #f9f9f9;
|
| 60 |
+
transition: border-color 0.25s;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
select:hover,
|
| 64 |
+
textarea:hover,
|
| 65 |
+
button:not([disabled]):hover {
|
| 66 |
+
border-color: #646cff;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
select:focus,
|
| 70 |
+
select:focus-visible,
|
| 71 |
+
textarea:focus,
|
| 72 |
+
textarea:focus-visible,
|
| 73 |
+
button:focus,
|
| 74 |
+
button:focus-visible {
|
| 75 |
+
outline: 4px auto -webkit-focus-ring-color;
|
| 76 |
+
}
|
src/main.jsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React from 'react'
|
| 2 |
+
import ReactDOM from 'react-dom/client'
|
| 3 |
+
import App from './App.jsx'
|
| 4 |
+
import './index.css'
|
| 5 |
+
|
| 6 |
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
| 7 |
+
<React.StrictMode>
|
| 8 |
+
<App />
|
| 9 |
+
</React.StrictMode>,
|
| 10 |
+
)
|
src/worker.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import { pipeline, env } from "@xenova/transformers";
|
| 3 |
+
|
| 4 |
+
// Disable local models
|
| 5 |
+
env.allowLocalModels = false;
|
| 6 |
+
|
| 7 |
+
/**
|
| 8 |
+
* This class uses the Singleton pattern to ensure that only one instance of the
|
| 9 |
+
* pipeline is loaded. This is because loading the pipeline is an expensive
|
| 10 |
+
* operation and we don't want to do it every time we want to translate a sentence.
|
| 11 |
+
*/
|
| 12 |
+
class MyTranslationPipeline {
|
| 13 |
+
static task = 'translation';
|
| 14 |
+
static model = 'Xenova/nllb-200-distilled-600M';
|
| 15 |
+
static instance = null;
|
| 16 |
+
|
| 17 |
+
static async getInstance(progress_callback = null) {
|
| 18 |
+
if (this.instance === null) {
|
| 19 |
+
this.instance = pipeline(this.task, this.model, { progress_callback });
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
return this.instance;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Listen for messages from the main thread
|
| 27 |
+
self.addEventListener('message', async (event) => {
|
| 28 |
+
// Retrieve the translation pipeline. When called for the first time,
|
| 29 |
+
// this will load the pipeline and save it for future use.
|
| 30 |
+
let translator = await MyTranslationPipeline.getInstance(x => {
|
| 31 |
+
// We also add a progress callback to the pipeline so that we can
|
| 32 |
+
// track model loading.
|
| 33 |
+
self.postMessage(x);
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// Actually perform the translation
|
| 37 |
+
let output = await translator(event.data.text, {
|
| 38 |
+
tgt_lang: event.data.tgt_lang,
|
| 39 |
+
src_lang: event.data.src_lang,
|
| 40 |
+
|
| 41 |
+
// Allows for partial output
|
| 42 |
+
callback_function: x => {
|
| 43 |
+
self.postMessage({
|
| 44 |
+
status: 'update',
|
| 45 |
+
output: translator.tokenizer.decode(x[0].output_token_ids, { skip_special_tokens: true })
|
| 46 |
+
});
|
| 47 |
+
}
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
// Send the output back to the main thread
|
| 51 |
+
self.postMessage({
|
| 52 |
+
status: 'complete',
|
| 53 |
+
output: output,
|
| 54 |
+
});
|
| 55 |
+
});
|
vite.config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { defineConfig } from 'vite'
|
| 2 |
+
import react from '@vitejs/plugin-react'
|
| 3 |
+
|
| 4 |
+
// https://vitejs.dev/config/
|
| 5 |
+
export default defineConfig({
|
| 6 |
+
plugins: [react()],
|
| 7 |
+
})
|