muqeet1234 commited on
Commit
e9ac66d
·
verified ·
1 Parent(s): 3f385a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title and description
5
+ st.title("Language Translator")
6
+ st.markdown("Translate text from English to Spanish using the Hugging Face model `Helsinki-NLP/opus-mt-en-es`.")
7
+
8
+ # Load the translation pipeline
9
+ @st.cache_resource
10
+ def load_translator():
11
+ return pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
12
+
13
+ translator = load_translator()
14
+
15
+ # Input area for English text
16
+ user_input = st.text_area("Enter text in English:", placeholder="Type something in English...", height=200)
17
+
18
+ # Translate button
19
+ if st.button("Translate"):
20
+ if user_input.strip():
21
+ with st.spinner("Translating text..."):
22
+ # Perform translation
23
+ translated = translator(user_input, max_length=100)
24
+ translated_text = translated[0]["translation_text"]
25
+
26
+ # Display the translated text
27
+ st.markdown("### Translated Text:")
28
+ st.write(translated_text)
29
+ else:
30
+ st.warning("Please enter some text to translate.")
31
+
32
+ # Footer
33
+ st.markdown("---")
34
+ st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/) and Streamlit.")