Spaces:
Running
Running
lewiskimaru
commited on
Commit
•
6cbf028
1
Parent(s):
bd3c7b9
Update static/index.html
Browse files- static/index.html +33 -64
static/index.html
CHANGED
@@ -1,66 +1,35 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
<
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
<form action="#" method="post">
|
10 |
-
<label for="userinput">Enter text to translate:</label>
|
11 |
-
|
12 |
-
<input type="text" id="userinput" name="userinput">
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
<label for="target_lang">Enter target language:</label>
|
17 |
-
|
18 |
-
<input type="text" id="target_lang" name="target_lang">
|
19 |
-
|
20 |
-
|
21 |
-
<input type="submit" value="Translate">
|
22 |
-
</form>
|
23 |
-
|
24 |
-
<div id="output"></div>
|
25 |
-
|
26 |
-
<script>
|
27 |
-
const form = document.querySelector('form');
|
28 |
-
const targetLangInput = document.querySelector('#target_lang');
|
29 |
-
const outputDiv = document.querySelector('#output');
|
30 |
-
|
31 |
-
form.addEventListener('submit', async (e) => {
|
32 |
-
e.preventDefault();
|
33 |
-
|
34 |
-
const userInput = document.querySelector('#userinput').value;
|
35 |
-
const targetLang = targetLangInput.value || 'swh_Latn';
|
36 |
-
|
37 |
-
try {
|
38 |
-
const response = await fetch('https://kamau1-sema-api.hf.space/translate_detect/', {
|
39 |
-
method: 'POST',
|
40 |
-
headers: {
|
41 |
-
'Content-Type': 'application/json'
|
42 |
-
},
|
43 |
-
body: JSON.stringify({
|
44 |
-
userinput: userInput,
|
45 |
-
target_lang: targetLang
|
46 |
-
})
|
47 |
-
});
|
48 |
-
|
49 |
-
const data = await response.json();
|
50 |
-
const sourceLanguage = data.source_language;
|
51 |
-
const translatedText = data.translations[0].text;
|
52 |
-
|
53 |
-
outputDiv.innerHTML = `
|
54 |
-
<p><strong>Output:</strong></p>
|
55 |
-
<p>Source Language: ${source_language}</p>
|
56 |
-
<p>Translated Text: ${translated_text}</p>
|
57 |
-
`;
|
58 |
-
|
59 |
-
} catch (error) {
|
60 |
-
console.error(error);
|
61 |
-
outputDiv.textContent = 'An error occurred while translating the text. Please check the input and try again.';
|
62 |
-
}
|
63 |
-
});
|
64 |
-
</script>
|
65 |
-
</body>
|
66 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="utf-8">
|
6 |
+
<title>Sema Translator</title>
|
7 |
+
<link rel="stylesheet" href="style.css" />
|
8 |
+
</head>
|
9 |
+
|
10 |
+
<body>
|
11 |
+
<h1>Translate across 200 Languages</h1>
|
12 |
+
|
13 |
+
<form action="#" method="post" id="translationForm">
|
14 |
+
<div class="container">
|
15 |
+
<div class="text-box input-box">
|
16 |
+
<label for="source_lang">Select source language:</label>
|
17 |
+
<select id="source_lang" name="source_lang"></select>
|
18 |
+
<textarea id="userinput" name="userinput" placeholder="Enter text"></textarea>
|
19 |
+
</div>
|
20 |
+
|
21 |
+
<div class="text-box output-box">
|
22 |
+
<label for="target_lang">Select target language:</label>
|
23 |
+
<select id="target_lang" name="target_lang"></select>
|
24 |
+
<textarea id="output" name="output" placeholder="Translation" disabled></textarea>
|
25 |
+
</div>
|
26 |
+
</div>
|
27 |
+
<div class="center-container">
|
28 |
+
<input type="submit" value="Translate">
|
29 |
+
</form>
|
30 |
+
</div>
|
31 |
+
|
32 |
+
<script src="script.js"></script>
|
33 |
+
</body>
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
</html>
|