AlexVed commited on
Commit
a011039
·
verified ·
1 Parent(s): c1901d7

Delete app.js

Browse files

removed app.js

Files changed (1) hide show
  1. app.js +0 -52
app.js DELETED
@@ -1,52 +0,0 @@
1
- import { useState } from "react";
2
-
3
- export default function Translator() {
4
- const [text, setText] = useState("");
5
- const [translation, setTranslation] = useState("");
6
- const [loading, setLoading] = useState(false);
7
-
8
- const translateText = async () => {
9
- if (!text) return;
10
- setLoading(true);
11
-
12
- const response = await fetch(
13
- "https://api-inference.huggingface.co/models/Helsinki-NLP/opus-mt-en-uk",
14
- {
15
- method: "POST",
16
- headers: {
17
- "Authorization": `Bearer YOUR_HUGGINGFACE_API_KEY`, // Replace with your API key
18
- "Content-Type": "application/json",
19
- },
20
- body: JSON.stringify({ inputs: text }),
21
- }
22
- );
23
-
24
- const data = await response.json();
25
- setTranslation(data[0]?.translation_text || "Translation failed.");
26
- setLoading(false);
27
- };
28
-
29
- return (
30
- <div className="flex flex-col items-center min-h-screen bg-gray-100 p-6">
31
- <h1 className="text-3xl font-bold mb-4">English to Ukrainian Translator</h1>
32
- <textarea
33
- className="w-full max-w-md p-3 border border-gray-300 rounded-md shadow-md"
34
- placeholder="Enter English text..."
35
- value={text}
36
- onChange={(e) => setText(e.target.value)}
37
- />
38
- <button
39
- onClick={translateText}
40
- className="mt-4 px-6 py-2 bg-blue-600 text-white rounded-lg shadow-md hover:bg-blue-700"
41
- >
42
- {loading ? "Translating..." : "Translate"}
43
- </button>
44
- {translation && (
45
- <div className="mt-4 p-4 bg-white rounded-lg shadow-md max-w-md">
46
- <h2 className="text-xl font-semibold">Translation:</h2>
47
- <p className="mt-2 text-gray-700">{translation}</p>
48
- </div>
49
- )}
50
- </div>
51
- );
52
- }