Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
target_languages = [
|
| 11 |
("ta", "Tamil"),
|
|
@@ -23,12 +27,12 @@ target_languages = [
|
|
| 23 |
target_language_names = [f"{code} ({name})" for code, name in target_languages]
|
| 24 |
|
| 25 |
interface = gr.Interface(
|
| 26 |
-
fn=
|
| 27 |
inputs=[
|
| 28 |
-
gr.
|
| 29 |
-
gr.
|
| 30 |
],
|
| 31 |
-
outputs=gr.
|
| 32 |
)
|
| 33 |
|
| 34 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from langdetect import detect
|
| 3 |
|
| 4 |
+
def translate_langdetect(text, target_language):
|
| 5 |
+
source_language = detect(text)
|
| 6 |
+
translation = text
|
| 7 |
+
if source_language != target_language:
|
| 8 |
+
try:
|
| 9 |
+
translation = Translator().translate(text, src=source_language, dest=target_language).text
|
| 10 |
+
except:
|
| 11 |
+
pass
|
| 12 |
+
return translation
|
| 13 |
|
| 14 |
target_languages = [
|
| 15 |
("ta", "Tamil"),
|
|
|
|
| 27 |
target_language_names = [f"{code} ({name})" for code, name in target_languages]
|
| 28 |
|
| 29 |
interface = gr.Interface(
|
| 30 |
+
fn=translate_langdetect,
|
| 31 |
inputs=[
|
| 32 |
+
gr.inputs.Textbox(label="Text to translate"),
|
| 33 |
+
gr.inputs.Dropdown(target_language_names, label="Target Language")
|
| 34 |
],
|
| 35 |
+
outputs=gr.outputs.Textbox(label="Translation")
|
| 36 |
)
|
| 37 |
|
| 38 |
interface.launch()
|