Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,25 @@
|
|
| 1 |
-
from
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
translator = Translator()
|
| 5 |
-
|
| 6 |
def translation(text):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
gr.Interface(fn=translation, inputs=inp_text, outputs=output, title='Translation',theme='peach').launch(enable_queue=True)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
| 1 |
+
from deep_translator import GoogleTranslator
|
| 2 |
import gradio as gr
|
| 3 |
|
|
|
|
|
|
|
| 4 |
def translation(text):
|
| 5 |
+
if not text:
|
| 6 |
+
return ""
|
| 7 |
+
try:
|
| 8 |
+
translator = GoogleTranslator(source='auto', target='en')
|
| 9 |
+
result = translator.translate(text)
|
| 10 |
+
return result
|
| 11 |
+
except Exception as e:
|
| 12 |
+
return f"Translation error: {str(e)}"
|
|
|
|
| 13 |
|
| 14 |
+
with gr.Blocks(title='Translation') as app:
|
| 15 |
+
gr.Markdown("# Text Translation")
|
| 16 |
+
with gr.Row():
|
| 17 |
+
inp_text = gr.Textbox(label='Input Text', lines=3)
|
| 18 |
+
with gr.Row():
|
| 19 |
+
output = gr.Textbox(label='Translated Text', lines=3)
|
| 20 |
+
with gr.Row():
|
| 21 |
+
translate_btn = gr.Button("Translate")
|
| 22 |
+
|
| 23 |
+
translate_btn.click(fn=translation, inputs=inp_text, outputs=output)
|
| 24 |
|
| 25 |
+
app.launch(enable_queue=True)
|