awacke1 commited on
Commit
33b2858
1 Parent(s): b682f3f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the translation pipeline
5
+ translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
6
+
7
+ # Set the Streamlit app title
8
+ st.title("Machine Translation with Hugging Face")
9
+
10
+ # Define the input text area
11
+ input_text = st.text_area("Enter text in English to translate to Spanish:", height=200)
12
+
13
+ # Define the translate button
14
+ translate_button = st.button("Translate")
15
+
16
+ # If the translate button is clicked
17
+ if translate_button:
18
+ # Translate the input text
19
+ output_text = translator(input_text, max_length=1000)[0]['translation_text']
20
+ # Display the output text
21
+ st.text_area("Translated text in Spanish:", value=output_text, height=200)