Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ input_text = st.text_input("Enter text to translate:")
|
|
8 |
# Create a list of options for the select box
|
9 |
options = ["German", "Romanian", "English", "French", "Spanish"]
|
10 |
langs = {"English":"en", "Romanian":"ro", "German":"de", "French":"fr", "Spanish":"es", "Italian":"it"}
|
11 |
-
models = ["Helsinki-NLP", "t5-base", "t5-small", "t5-large", "Unbabel/TowerInstruct-7B-v0.2", "Unbabel/TowerInstruct-Mistral-7B-v0.2"]
|
12 |
|
13 |
# Create two columns
|
14 |
scol, tcol = st.columns(2)
|
@@ -53,6 +53,11 @@ if submit_button:
|
|
53 |
output_ids = model.generate(input_ids)
|
54 |
# Decode the translated text
|
55 |
translated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
56 |
elif model_name.startswith('t5'):
|
57 |
prompt = f'translate {sselected_language} to {tselected_language}: {input_text}'
|
58 |
print(prompt)
|
|
|
8 |
# Create a list of options for the select box
|
9 |
options = ["German", "Romanian", "English", "French", "Spanish"]
|
10 |
langs = {"English":"en", "Romanian":"ro", "German":"de", "French":"fr", "Spanish":"es", "Italian":"it"}
|
11 |
+
models = ["Helsinki-NLP", "t5-base", "t5-small", "t5-large", "Unbabel/TowerInstruct-7B-v0.2", "Unbabel/TowerInstruct-Mistral-7B-v0.2", 'Google']
|
12 |
|
13 |
# Create two columns
|
14 |
scol, tcol = st.columns(2)
|
|
|
53 |
output_ids = model.generate(input_ids)
|
54 |
# Decode the translated text
|
55 |
translated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
56 |
+
elif model_name.startswith('Google'):
|
57 |
+
import requests
|
58 |
+
url = os.environ('GTRANSURL')
|
59 |
+
params = {'sl': sselected_language, 'tl': tselected_language, 'dt': 't', 'ie': 'UTF-8', 'oe': 'UTF-8', 'q': input_text}
|
60 |
+
translated_text = requests.get(url, params=params).text[0][0]
|
61 |
elif model_name.startswith('t5'):
|
62 |
prompt = f'translate {sselected_language} to {tselected_language}: {input_text}'
|
63 |
print(prompt)
|