Files changed (1) hide show
  1. app.py +18 -28
app.py CHANGED
@@ -1,37 +1,27 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load translation model (English β†’ Malayalam)
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
- # Function
17
- def translate(text, direction):
18
- if direction == "English to Malayalam":
19
- result = translator_en_ml(text)
20
- else:
21
- result = translator_ml_en(text)
22
-
23
- return result[0]['translation_text']
 
24
 
25
- # UI
26
- app = gr.Interface(
27
- fn=translate,
28
  inputs=[
29
- gr.Textbox(lines=4, placeholder="Enter text here..."),
30
- gr.Radio(["English to Malayalam", "Malayalam to English"])
31
  ],
32
  outputs="text",
33
- title="🌍 Malayalam Translator",
34
- description="Translate between English and Malayalam using Hugging Face models"
35
  )
36
 
37
- app.launch()
 
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()