Spaces:
Runtime error
Runtime error
Real time translation
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import translators as ts
|
|
| 2 |
import gradio as gr
|
| 3 |
from langdetect import detect
|
| 4 |
|
| 5 |
-
def
|
| 6 |
languages_dict = {'Spanish': 'es', 'Bengali': 'bn', 'English': 'en', 'French': 'fr'}
|
| 7 |
|
| 8 |
input_language = detect(input_text)
|
|
@@ -11,12 +11,17 @@ def translate_transformers(output_language, input_text,):
|
|
| 11 |
from_language=input_language,
|
| 12 |
to_language=languages_dict[output_language])
|
| 13 |
|
| 14 |
-
interface = gr.Interface(fn=
|
| 15 |
inputs=[
|
| 16 |
gr.Dropdown(['Spanish', 'Bengali', 'English', 'French'],
|
| 17 |
-
label = '
|
| 18 |
gr.Textbox(lines=2, placeholder='Text to translate',
|
| 19 |
label='Text')],
|
| 20 |
-
outputs='text'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
interface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from langdetect import detect
|
| 4 |
|
| 5 |
+
def translate(output_language, input_text):
|
| 6 |
languages_dict = {'Spanish': 'es', 'Bengali': 'bn', 'English': 'en', 'French': 'fr'}
|
| 7 |
|
| 8 |
input_language = detect(input_text)
|
|
|
|
| 11 |
from_language=input_language,
|
| 12 |
to_language=languages_dict[output_language])
|
| 13 |
|
| 14 |
+
interface = gr.Interface(fn=translate,
|
| 15 |
inputs=[
|
| 16 |
gr.Dropdown(['Spanish', 'Bengali', 'English', 'French'],
|
| 17 |
+
label = 'Translation language'),
|
| 18 |
gr.Textbox(lines=2, placeholder='Text to translate',
|
| 19 |
label='Text')],
|
| 20 |
+
outputs='text',
|
| 21 |
+
title='Automatic Language Translation Demo from RPI eSolutions Pte Ltd',
|
| 22 |
+
theme=gr.themes.Default(
|
| 23 |
+
primary_hue=gr.themes.colors.blue,
|
| 24 |
+
secondary_hue=gr.themes.colors.indigo),
|
| 25 |
+
live=True)
|
| 26 |
|
| 27 |
interface.launch()
|