pratikshahp commited on
Commit
73afe6a
·
verified ·
1 Parent(s): 7479cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -1,13 +1,24 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  translator = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
5
 
 
6
  def translate_text(text):
7
- result = translator(text)[0]['translation_text']
 
 
8
  return result
9
 
10
- iface = gr.Interface(fn=translate_text, inputs="text", outputs="text")
 
 
 
 
 
 
 
11
 
12
- # Enable API mode
13
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the translation model
5
  translator = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
6
 
7
+ # Define the translation function
8
  def translate_text(text):
9
+ if not text:
10
+ return "⚠️ Please provide some input text."
11
+ result = translator(text)[0]["translation_text"]
12
  return result
13
 
14
+ # Create the Gradio interface
15
+ iface = gr.Interface(
16
+ fn=translate_text,
17
+ inputs=gr.Textbox(label="Enter English Text"),
18
+ outputs=gr.Textbox(label="Hindi Translation"),
19
+ title="English to Hindi Translator",
20
+ description="Enter English text to translate it into Hindi using a HuggingFace transformer model."
21
+ )
22
 
23
+ # 🚀 Launch with API enabled so external clients like Discord can POST data
24
  iface.launch()