Spaces:
Sleeping
Sleeping
| 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) |