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)