lewiskimaru commited on
Commit
75a0eef
1 Parent(s): 5ecc89c

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +64 -50
static/index.html CHANGED
@@ -1,52 +1,66 @@
1
- <!DOCTYPE html>
2
  <html>
3
- <head>
4
  <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width">
6
- <title>Sema Translator</title>
7
- <link rel="stylesheet" href="static/style.css" />
8
- <py-script src="modules/flores200_codes.py"></py-script>
9
- </head>
10
- <body>
11
- <div class="Header">
12
- <h1>Sema Translator</h1>
13
- <p>Unlock the Power of Global Communication with Sema Translator! Seamlessly bridging language barriers. With support for over 200 languages, Sema Translator opens up a realm of possibilities for building truly global applications.</p>
14
-
15
- </div>
16
-
17
- <div class="LanguageDropdown" style="text-align:center">
18
- <h2>Select a Language:</h2>
19
- <select id="languageSelect">
20
- {"".join(f"<option value='{code}'>{lang} - {code}</option>" for lang, code in flores_codes.items())}
21
- </select>
22
- </div>
23
-
24
- <div class="instructions">
25
- <p>Use the following python code to access the api endpoint</p>
26
- <pre style="text-align: left;">
27
- import requests
28
-
29
- url = "{public_url}/translate/"
30
- data = {
31
- "userinput": "rũcinĩ rwega, niwokĩra wega?",
32
- "target_lang": "eng_Latn",
33
- }
34
-
35
- response = requests.post(url, json=data)
36
- result = response.json()
37
-
38
- print(result)
39
-
40
- source_language = result['source_language']
41
- print("Source Language:", source_language)
42
-
43
- translation = result['translated_text']
44
- print("Translated text:", translation)
45
- </pre>
46
- </div>
47
-
48
- <div class="footer">
49
- <h1>Created by Lewis Kamau Kiamru</h1>
50
- </div>
51
- </body>
52
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <html>
2
+ <head>
3
  <meta charset="utf-8">
4
+ <title>Sema API Integration Example</title>
5
+ </head>
6
+ <body>
7
+ <h1>Translate and Detect Source Language</h1>
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>