Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|