Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
from deep_translator import GoogleTranslator
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 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 |
-
#
|
| 16 |
-
|
| 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 |
-
# π
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|