Spaces:
Sleeping
Sleeping
Saanvi12011
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
|
6 |
|
7 |
-
|
8 |
-
st.
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
if st.button("Translate"):
|
12 |
if not text.strip():
|
13 |
-
st.error("Please provide
|
14 |
else:
|
15 |
with st.spinner("Translating..."):
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Ensure sentencepiece is installed
|
5 |
+
try:
|
6 |
+
import sentencepiece
|
7 |
+
except ImportError:
|
8 |
+
st.error("The 'sentencepiece' library is required. Install it using 'pip install sentencepiece'.")
|
9 |
+
|
10 |
+
# Initialize the translation pipeline
|
11 |
translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
|
12 |
|
13 |
+
# Streamlit app
|
14 |
+
st.title("English-to-Spanish Translation App")
|
15 |
+
st.write("Translate your text from English to Spanish with ease using Hugging Face models.")
|
16 |
+
|
17 |
+
# Input text box for user
|
18 |
+
text = st.text_area("Enter text in English:", placeholder="Type your text here...", height=150)
|
19 |
|
20 |
+
# Button to trigger translation
|
21 |
if st.button("Translate"):
|
22 |
if not text.strip():
|
23 |
+
st.error("Please provide text to translate.")
|
24 |
else:
|
25 |
with st.spinner("Translating..."):
|
26 |
+
try:
|
27 |
+
# Perform translation
|
28 |
+
translation = translator(text)
|
29 |
+
translated_text = translation[0]["translation_text"]
|
30 |
+
st.subheader("Translated Text (Spanish):")
|
31 |
+
st.write(translated_text)
|
32 |
+
except Exception as e:
|
33 |
+
st.error(f"An error occurred during translation: {e}")
|
34 |
+
|