|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
@st.cache_resource |
|
def load_translation_model(): |
|
return pipeline("translation_en_to_ur", model="Helsinki-NLP/opus-mt-en-ur") |
|
|
|
translator = load_translation_model() |
|
|
|
|
|
st.title("English to Urdu Translator") |
|
|
|
|
|
english_text = st.text_area("Enter English text", placeholder="Type something in English...", height=150) |
|
|
|
|
|
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!") |
|
|
|
|
|
|