TiberiuCristianLeon's picture
Update app.py
167f186 verified
raw
history blame
856 Bytes
import streamlit as st
from transformers import T5ForTranslation, T5Tokenizer
# Load the pre-trained model and tokenizer
model = T5ForTranslation.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
tokenizer = T5Tokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-ro")
# Create the app layout
st.title("Text Translation App")
text_input = st.text_input("Enter text to translate:")
submit_button = st.button("Translate")
translated_text = st.text("")
# Handle the submit button click
if submit_button:
# Encode the input text
encoded = tokenizer(text_input, return_tensors="pt")
# Perform translation
translated = model.generate(**encoded)
# Decode the translated text
translated_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
# Display the translated text
st.write("Translated Text:", translated_text[0])