AamerAkhter commited on
Commit
3c0c41f
Β·
verified Β·
1 Parent(s): 6de4f47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -1,28 +1,27 @@
1
- import gradio as gr
2
  from deep_translator import GoogleTranslator
3
 
4
- # 🎩 The Feather-Light Magic Trick!
5
- def magic_translator(text, direction):
6
- if direction == "English to Urdu":
7
- # 🦜 The magic parrot flies and translates to Urdu
8
- translated = GoogleTranslator(source='en', target='ur').translate(text)
9
- return translated
10
- else:
11
- # 🦜 The magic parrot flies and translates to English
12
- translated = GoogleTranslator(source='ur', target='en').translate(text)
13
- return translated
14
 
15
- # 🎁 Building the shiny Toy Box!
16
- toy_box = gr.Interface(
17
- fn=magic_translator,
18
- inputs=[
19
- gr.Textbox(lines=3, placeholder="Type your words here... ✍️", label="Your Words"),
20
- gr.Radio(["English to Urdu", "Urdu to English"], label="Which way?", value="English to Urdu")
21
- ],
22
- outputs=gr.Textbox(label="Magic Answer! ✨"),
23
- title="🌟 The Magic Language Box 🌟",
24
- description="Type words, pick a direction, and watch the magic parrot do the work!"
25
- )
26
 
27
- # πŸš€ Turn it on!
28
- toy_box.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  from deep_translator import GoogleTranslator
3
 
4
+ # 🌟 Give our toy box a giant title!
5
+ st.title("🌟 The Magic Streamlit Language Box 🌟")
6
+ st.write("Type words, pick a direction, and watch the magic parrot do the work!")
7
+
8
+ # ✍️ The big box to type words
9
+ my_words = st.text_area("Type your words here... ✍️")
 
 
 
 
10
 
11
+ # πŸ”˜ The buttons to pick the direction
12
+ direction = st.radio("Which way?", ["English to Urdu", "Urdu to English"])
 
 
 
 
 
 
 
 
 
13
 
14
+ # πŸš€ The magic button to make the parrot fly!
15
+ if st.button("Translate! ✨"):
16
+ # Check if the text box is empty first
17
+ if my_words == "":
18
+ st.warning("Oops! You forgot to type some words! πŸ™ˆ")
19
+ else:
20
+ if direction == "English to Urdu":
21
+ # 🦜 Parrot flies to Urdu
22
+ answer = GoogleTranslator(source='en', target='ur').translate(my_words)
23
+ st.success(answer)
24
+ else:
25
+ # 🦜 Parrot flies to English
26
+ answer = GoogleTranslator(source='ur', target='en').translate(my_words)
27
+ st.success(answer)