Spaces:
Sleeping
Sleeping
File size: 1,046 Bytes
3c0c41f 2887a75 3c0c41f 2887a75 3c0c41f 2887a75 3c0c41f | 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 | import streamlit as st
from deep_translator import GoogleTranslator
# π Give our toy box a giant title!
st.title("π The Magic Streamlit Language Box π")
st.write("Type words, pick a direction, and watch the magic parrot do the work!")
# βοΈ The big box to type words
my_words = st.text_area("Type your words here... βοΈ")
# π The buttons to pick the direction
direction = st.radio("Which way?", ["English to Urdu", "Urdu to English"])
# π The magic button to make the parrot fly!
if st.button("Translate! β¨"):
# Check if the text box is empty first
if my_words == "":
st.warning("Oops! You forgot to type some words! π")
else:
if direction == "English to Urdu":
# π¦ Parrot flies to Urdu
answer = GoogleTranslator(source='en', target='ur').translate(my_words)
st.success(answer)
else:
# π¦ Parrot flies to English
answer = GoogleTranslator(source='ur', target='en').translate(my_words)
st.success(answer) |