Spaces:
Runtime error
Runtime error
Commit
·
b14f0eb
1
Parent(s):
2b73c9b
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,22 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import transformers
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|