Update app.py
Browse files
app.py
CHANGED
|
@@ -8,13 +8,15 @@ model = T5ForConditionalGeneration.from_pretrained(model_name)
|
|
| 8 |
# tokenizer = T5Tokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
|
| 9 |
|
| 10 |
# Create the app layout
|
| 11 |
-
st.title("Text Translation
|
| 12 |
-
input_text = st.text_input("Enter text to translate
|
| 13 |
# Create a list of options for the select box
|
| 14 |
options = ["English", "Romanian", "German", "French", "Spanish"]
|
|
|
|
| 15 |
# Create the select box
|
| 16 |
slanguage_selector = st.selectbox("Select a source language:", options)
|
| 17 |
tlanguage_selector = st.selectbox("Select a target language:", options)
|
|
|
|
| 18 |
# Display the selected language
|
| 19 |
sselected_language = st.session_state["sselected_language"]
|
| 20 |
tselected_language = st.session_state["tselected_language"]
|
|
@@ -27,7 +29,7 @@ if submit_button:
|
|
| 27 |
# Encode the input text
|
| 28 |
# encoded = tokenizer(text_input, return_tensors="pt")
|
| 29 |
|
| 30 |
-
input_ids = tokenizer.encode(f'Translate {sselected_language} to {tselected_language
|
| 31 |
|
| 32 |
# Perform translation
|
| 33 |
output_ids = model.generate(input_ids)
|
|
|
|
| 8 |
# tokenizer = T5Tokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
|
| 9 |
|
| 10 |
# Create the app layout
|
| 11 |
+
st.title("Text Translation")
|
| 12 |
+
input_text = st.text_input("Enter text to translate:")
|
| 13 |
# Create a list of options for the select box
|
| 14 |
options = ["English", "Romanian", "German", "French", "Spanish"]
|
| 15 |
+
models = ["t5-base", "t5-small"]
|
| 16 |
# Create the select box
|
| 17 |
slanguage_selector = st.selectbox("Select a source language:", options)
|
| 18 |
tlanguage_selector = st.selectbox("Select a target language:", options)
|
| 19 |
+
model_selector = st.selectbox("Select a source language:", options)
|
| 20 |
# Display the selected language
|
| 21 |
sselected_language = st.session_state["sselected_language"]
|
| 22 |
tselected_language = st.session_state["tselected_language"]
|
|
|
|
| 29 |
# Encode the input text
|
| 30 |
# encoded = tokenizer(text_input, return_tensors="pt")
|
| 31 |
|
| 32 |
+
input_ids = tokenizer.encode(f'Translate {sselected_language} to {tselected_language}: {input_text}', return_tensors='pt')
|
| 33 |
|
| 34 |
# Perform translation
|
| 35 |
output_ids = model.generate(input_ids)
|