Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration, AutoTokenizer,
|
|
4 |
|
5 |
@spaces.GPU
|
6 |
def translate_text(input_text, sselected_language, tselected_language, model_name):
|
7 |
-
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es"}
|
8 |
sl = langs[sselected_language]
|
9 |
tl = langs[tselected_language]
|
10 |
|
@@ -14,9 +14,15 @@ def translate_text(input_text, sselected_language, tselected_language, model_nam
|
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name_full)
|
15 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
16 |
except EnvironmentError:
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
else:
|
21 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
22 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
@@ -41,11 +47,10 @@ def swap_languages(src_lang, tgt_lang):
|
|
41 |
|
42 |
def create_interface():
|
43 |
with gr.Blocks() as interface:
|
44 |
-
gr.Markdown("## Text
|
45 |
|
46 |
with gr.Row():
|
47 |
input_text = gr.Textbox(label="Enter text to translate:", placeholder="Type your text here...")
|
48 |
-
# Create the interface with gr.Blocks() as demo: with gr.Row(): sselected_language = gr.Dropdown(choices=options, value="German", label="Source language") tselected_language = gr.Dropdown(choices=options, value="Romanian", label="Target language") swap_button = gr.Button("Swap Languages") # Set up the button to call the swap function
|
49 |
|
50 |
with gr.Row():
|
51 |
sselected_language = gr.Dropdown(choices=options, value="German", label="Source language")
|
|
|
4 |
|
5 |
@spaces.GPU
|
6 |
def translate_text(input_text, sselected_language, tselected_language, model_name):
|
7 |
+
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es", , "Italian": "it"}
|
8 |
sl = langs[sselected_language]
|
9 |
tl = langs[tselected_language]
|
10 |
|
|
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name_full)
|
15 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
16 |
except EnvironmentError:
|
17 |
+
try :
|
18 |
+
model_name_full = f"Helsinki-NLP/opus-tatoeba-{sl}-{tl}"
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_full)
|
20 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
21 |
+
except EnvironmentError:
|
22 |
+
model_name_full = f"Helsinki-NLP/opus-tatoeba-{tl}-{sl}"
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_full)
|
24 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
25 |
+
|
26 |
else:
|
27 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
28 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
|
|
47 |
|
48 |
def create_interface():
|
49 |
with gr.Blocks() as interface:
|
50 |
+
gr.Markdown("## Machine Text Translation")
|
51 |
|
52 |
with gr.Row():
|
53 |
input_text = gr.Textbox(label="Enter text to translate:", placeholder="Type your text here...")
|
|
|
54 |
|
55 |
with gr.Row():
|
56 |
sselected_language = gr.Dropdown(choices=options, value="German", label="Source language")
|