wiqasali's picture
Update app.py
380d80f verified
raw
history blame
816 Bytes
import streamlit as st
from transformers import pipeline
# Initialize the translation pipeline from Hugging Face
@st.cache_resource
def load_translation_model():
return pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur")
translator = load_translation_model()
# Streamlit app layout
st.title("English to Urdu Translator")
# Input text in English
english_text = st.text_area("Enter English text", placeholder="Type something in English...", height=150)
# Translate button
if st.button("Translate to Urdu"):
if english_text.strip() != "":
translation = translator(english_text)
urdu_text = translation[0]['translation_text']
st.write("### Translated Text in Urdu:")
st.write(urdu_text)
else:
st.warning("Please enter some text to translate!")