AlexVed commited on
Commit
9c69fdb
·
verified ·
1 Parent(s): f6f0134

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +41 -0
app.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from "react";
2
+
3
+ export default function Translator() {
4
+ const [text, setText] = useState("");
5
+ const [translation, setTranslation] = useState("");
6
+
7
+ const translateText = async () => {
8
+ if (!text) return;
9
+ const response = await fetch("http://localhost:8501/translate", {
10
+ method: "POST",
11
+ headers: { "Content-Type": "application/json" },
12
+ body: JSON.stringify({ text }),
13
+ });
14
+ const data = await response.json();
15
+ setTranslation(data.translation);
16
+ };
17
+
18
+ return (
19
+ <div className="flex flex-col items-center min-h-screen bg-gray-100 p-6">
20
+ <h1 className="text-3xl font-bold mb-4">English to Ukrainian Translator</h1>
21
+ <textarea
22
+ className="w-full max-w-md p-3 border border-gray-300 rounded-md shadow-md"
23
+ placeholder="Enter English text..."
24
+ value={text}
25
+ onChange={(e) => setText(e.target.value)}
26
+ />
27
+ <button
28
+ onClick={translateText}
29
+ className="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg shadow-md hover:bg-blue-700"
30
+ >
31
+ Translate
32
+ </button>
33
+ {translation && (
34
+ <div className="mt-4 p-4 bg-white rounded-lg shadow-md max-w-md">
35
+ <h2 className="text-xl font-semibold">Translation:</h2>
36
+ <p className="mt-2 text-gray-700">{translation}</p>
37
+ </div>
38
+ )}
39
+ </div>
40
+ );
41
+ }