Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
st.title("
|
| 6 |
|
| 7 |
# Choose the translation models from Hugging Face
|
| 8 |
translation_models = {
|
|
@@ -12,6 +12,10 @@ translation_models = {
|
|
| 12 |
"French to English": "Helsinki-NLP/opus-mt-fr-en",
|
| 13 |
"English to Urdu": "Helsinki-NLP/opus-mt-en-ur",
|
| 14 |
"Urdu to English": "Helsinki-NLP/opus-mt-ur-en",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Add more language pairs as needed
|
| 16 |
}
|
| 17 |
|
|
@@ -20,28 +24,33 @@ selected_translation = st.selectbox("Select translation model", list(translation
|
|
| 20 |
# Load the translation pipeline
|
| 21 |
translator = pipeline(task="translation", model=translation_models[selected_translation])
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import time
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
st.title("Enhanced Multilingual Translator Chatbot")
|
| 6 |
|
| 7 |
# Choose the translation models from Hugging Face
|
| 8 |
translation_models = {
|
|
|
|
| 12 |
"French to English": "Helsinki-NLP/opus-mt-fr-en",
|
| 13 |
"English to Urdu": "Helsinki-NLP/opus-mt-en-ur",
|
| 14 |
"Urdu to English": "Helsinki-NLP/opus-mt-ur-en",
|
| 15 |
+
"English to Spanish": "Helsinki-NLP/opus-mt-en-es",
|
| 16 |
+
"Spanish to English": "Helsinki-NLP/opus-mt-es-en",
|
| 17 |
+
"English to Chinese": "Helsinki-NLP/opus-mt-en-zh",
|
| 18 |
+
"Chinese to English": "Helsinki-NLP/opus-mt-zh-en",
|
| 19 |
# Add more language pairs as needed
|
| 20 |
}
|
| 21 |
|
|
|
|
| 24 |
# Load the translation pipeline
|
| 25 |
translator = pipeline(task="translation", model=translation_models[selected_translation])
|
| 26 |
|
| 27 |
+
# User input for translation
|
| 28 |
+
user_input = st.text_area("Enter text for translation:", "")
|
| 29 |
+
|
| 30 |
+
# Display loading indicator
|
| 31 |
+
if st.button("Translate"):
|
| 32 |
+
with st.spinner("Translating..."):
|
| 33 |
+
# Simulate translation delay for demonstration
|
| 34 |
+
time.sleep(2)
|
| 35 |
+
if user_input:
|
| 36 |
+
# Perform translation
|
| 37 |
+
translated_text = translator(user_input, max_length=500)[0]['translation_text']
|
| 38 |
+
st.success(f"Translated Text: {translated_text}")
|
| 39 |
+
else:
|
| 40 |
+
st.warning("Please enter text for translation.")
|
| 41 |
+
|
| 42 |
+
# Clear button to reset input and result
|
| 43 |
+
if st.button("Clear"):
|
| 44 |
+
user_input = ""
|
| 45 |
+
st.success("Input cleared.")
|
| 46 |
+
st.empty() # Clear previous results if any
|
| 47 |
+
|
| 48 |
+
st.markdown("---")
|
| 49 |
+
|
| 50 |
+
st.subheader("About")
|
| 51 |
+
st.write(
|
| 52 |
+
"This is an enhanced Multilingual Translator chatbot that uses the Hugging Face Transformers library."
|
| 53 |
+
)
|
| 54 |
+
st.write(
|
| 55 |
+
"Select a translation model from the dropdown, enter text, and click 'Translate' to see the translation."
|
| 56 |
+
)
|