Spaces:
Runtime error
Runtime error
Update app.py
#1
by Barat123 - opened
app.py
CHANGED
|
@@ -1,37 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
translator_en_ml = pipeline(
|
| 6 |
-
"translation",
|
| 7 |
-
model="Helsinki-NLP/opus-mt-en-ml"
|
| 8 |
-
)
|
| 9 |
-
|
| 10 |
-
# Malayalam β English
|
| 11 |
-
translator_ml_en = pipeline(
|
| 12 |
-
"translation",
|
| 13 |
-
model="Helsinki-NLP/opus-mt-ml-en"
|
| 14 |
-
)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
fn=translate,
|
| 28 |
inputs=[
|
| 29 |
-
gr.Textbox(
|
| 30 |
-
gr.Radio(["English
|
| 31 |
],
|
| 32 |
outputs="text",
|
| 33 |
-
title="
|
| 34 |
-
description="
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from googletrans import Translator
|
| 3 |
|
| 4 |
+
translator = Translator()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def translate_text(text, direction):
|
| 7 |
+
try:
|
| 8 |
+
if direction == "English β Malayalam":
|
| 9 |
+
result = translator.translate(text, dest='ml')
|
| 10 |
+
else:
|
| 11 |
+
result = translator.translate(text, dest='en')
|
| 12 |
+
return result.text
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"Error: {e}"
|
| 15 |
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=translate_text,
|
|
|
|
| 18 |
inputs=[
|
| 19 |
+
gr.Textbox(label="Enter Text"),
|
| 20 |
+
gr.Radio(["English β Malayalam", "Malayalam β English"], label="Select Direction")
|
| 21 |
],
|
| 22 |
outputs="text",
|
| 23 |
+
title="Malayalam Translator (GoogleTrans)",
|
| 24 |
+
description="Simple translator using googletrans in Hugging Face Spaces"
|
| 25 |
)
|
| 26 |
|
| 27 |
+
iface.launch()
|