venkatks515 commited on
Commit
b14f0eb
1 Parent(s): 2b73c9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -1,14 +1,22 @@
1
- import streamlit as st
2
- import transformers
3
  from transformers import pipeline
4
 
5
- st.title("Text Generation with Hugging Face")
 
6
 
7
- model_name = "bigscience/mt0-xxl-mt"
8
- generator = pipeline("text-generation", model=model_name, device=0)
9
 
10
- prompt = st.text_input("Enter text prompt:", "Once upon a time")
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- if st.button("Generate Text"):
13
- output = generator(prompt, max_length=100, do_sample=True)
14
- st.write(output[0]['generated_text'])
 
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)
22