Sa-m commited on
Commit
3ea0ef7
·
verified ·
1 Parent(s): c36cef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -1,17 +1,25 @@
1
- from googletrans import Translator
2
  import gradio as gr
3
 
4
- translator = Translator()
5
-
6
  def translation(text):
7
- translation = translator.translate(text)
8
- res=translation.text
9
- return res
10
-
11
-
12
- inp_text = gr.inputs.Textbox(label='Input')
13
- output = gr.outputs.Textbox(label='Output')
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)