Spaces:
Sleeping
Sleeping
File size: 816 Bytes
e852ba8 380d80f e852ba8 380d80f e852ba8 3c87765 380d80f e852ba8 380d80f e852ba8 380d80f e852ba8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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!")
|