awacke1's picture
Create app.py
33b2858
import streamlit as st
from transformers import pipeline
# Load the translation pipeline
translator = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
# Set the Streamlit app title
st.title("Machine Translation with Hugging Face")
# Define the input text area
input_text = st.text_area("Enter text in English to translate to Spanish:", height=200)
# Define the translate button
translate_button = st.button("Translate")
# If the translate button is clicked
if translate_button:
# Translate the input text
output_text = translator(input_text, max_length=1000)[0]['translation_text']
# Display the output text
st.text_area("Translated text in Spanish:", value=output_text, height=200)