Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
8 |
return result
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
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()
|