Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,24 @@ options = ["German", "Romanian", "English", "French", "Spanish", "Italian"]
|
|
| 11 |
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es", "Italian": "it"}
|
| 12 |
models = ["Helsinki-NLP", "Argos", "t5-base", "t5-small", "t5-large", "Unbabel/Tower-Plus-2B",
|
| 13 |
"Unbabel/TowerInstruct-Mistral-7B-v0.2", "winninghealth/WiNGPT-Babel-2", "Google"]
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
class Translators:
|
| 16 |
def __init__(self, model_name: str, sl: str, tl: str, input_text: str):
|
| 17 |
self.model_name = model_name
|
|
@@ -383,7 +400,7 @@ def wingpt(model_name, sl, tl, input_text):
|
|
| 383 |
result = rawresult.split('\n')[-1].strip() if '\n' in rawresult else rawresult.strip()
|
| 384 |
return result
|
| 385 |
|
| 386 |
-
def translate_text(
|
| 387 |
"""
|
| 388 |
Translates the input text from the source language to the target language using a specified model.
|
| 389 |
|
|
@@ -542,7 +559,8 @@ if model_name.startswith('t5'):
|
|
| 542 |
|
| 543 |
st.write("Selected language combination:", sselected_language, " - ", tselected_language, "Selected model:", model_name)
|
| 544 |
submit_button = st.button("Translate")
|
| 545 |
-
translated_textarea = st.text("")
|
|
|
|
| 546 |
|
| 547 |
# Handle the submit button click
|
| 548 |
if submit_button:
|
|
@@ -598,5 +616,7 @@ if submit_button:
|
|
| 598 |
|
| 599 |
# Display the translated text
|
| 600 |
print(translated_text)
|
| 601 |
-
|
| 602 |
-
translated_textarea = st.text(translated_text)
|
|
|
|
|
|
|
|
|
| 11 |
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es", "Italian": "it"}
|
| 12 |
models = ["Helsinki-NLP", "Argos", "t5-base", "t5-small", "t5-large", "Unbabel/Tower-Plus-2B",
|
| 13 |
"Unbabel/TowerInstruct-Mistral-7B-v0.2", "winninghealth/WiNGPT-Babel-2", "Google"]
|
| 14 |
+
allmodels = ["Helsinki-NLP",
|
| 15 |
+
"Helsinki-NLP/opus-mt-tc-bible-big-mul-mul", "Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_nld",
|
| 16 |
+
"Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_fra_por_spa", "Helsinki-NLP/opus-mt-tc-bible-big-deu_eng_fra_por_spa-mul",
|
| 17 |
+
"Helsinki-NLP/opus-mt-tc-bible-big-roa-deu_eng_fra_por_spa", "Helsinki-NLP/opus-mt-tc-bible-big-deu_eng_fra_por_spa-roa",
|
| 18 |
+
"facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
|
| 19 |
+
"facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
|
| 20 |
+
"facebook/m2m100_418M", "facebook/m2m100_1.2B", "Lego-MT/Lego-MT",
|
| 21 |
+
"bigscience/mt0-small", "bigscience/mt0-base", "bigscience/mt0-large", "bigscience/mt0-xl",
|
| 22 |
+
"bigscience/bloomz-560m", "bigscience/bloomz-1b1", "bigscience/bloomz-1b7", "bigscience/bloomz-3b",
|
| 23 |
+
"t5-small", "t5-base", "t5-large",
|
| 24 |
+
"google/flan-t5-small", "google/flan-t5-base", "google/flan-t5-large", "google/flan-t5-xl",
|
| 25 |
+
"google/madlad400-3b-mt", "jbochi/madlad400-3b-mt",
|
| 26 |
+
"Argos", "Google",
|
| 27 |
+
"HuggingFaceTB/SmolLM3-3B", "winninghealth/WiNGPT-Babel-2",
|
| 28 |
+
"utter-project/EuroLLM-1.7B", "utter-project/EuroLLM-1.7B-Instruct",
|
| 29 |
+
"Unbabel/Tower-Plus-2B", "Unbabel/TowerInstruct-7B-v0.2", "Unbabel/TowerInstruct-Mistral-7B-v0.2",
|
| 30 |
+
"openGPT-X/Teuken-7B-instruct-commercial-v0.4", "openGPT-X/Teuken-7B-instruct-v0.6"
|
| 31 |
+
]
|
| 32 |
class Translators:
|
| 33 |
def __init__(self, model_name: str, sl: str, tl: str, input_text: str):
|
| 34 |
self.model_name = model_name
|
|
|
|
| 400 |
result = rawresult.split('\n')[-1].strip() if '\n' in rawresult else rawresult.strip()
|
| 401 |
return result
|
| 402 |
|
| 403 |
+
def translate_text(model_name: str, s_language: str, t_language: str, input_text: str) -> tuple[str, str]:
|
| 404 |
"""
|
| 405 |
Translates the input text from the source language to the target language using a specified model.
|
| 406 |
|
|
|
|
| 559 |
|
| 560 |
st.write("Selected language combination:", sselected_language, " - ", tselected_language, "Selected model:", model_name)
|
| 561 |
submit_button = st.button("Translate")
|
| 562 |
+
translated_textarea = st.text(label="Translation", placeholder="Translation area", value='')
|
| 563 |
+
message_textarea = st.text(label="Messages", placeholder="Messages area", value='')
|
| 564 |
|
| 565 |
# Handle the submit button click
|
| 566 |
if submit_button:
|
|
|
|
| 616 |
|
| 617 |
# Display the translated text
|
| 618 |
print(translated_text)
|
| 619 |
+
message = f"Translated from {sselected_language} to {tselected_language} using {model_name}."
|
| 620 |
+
translated_textarea = st.text(translated_text)
|
| 621 |
+
message_textarea = st.text(value=message)
|
| 622 |
+
message = st.write(f"Translated text from {sselected_language} to {tselected_language} using {model_name}.")
|