pratikshahp's picture
Update app.py
f27d523 verified
raw
history blame
835 Bytes
import gradio as gr
from transformers import pipeline
# Load the translation model
translator = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
# Define the translation function
def translate_text(text):
if not text:
return "⚠️ Please provide some input text."
result = translator(text)[0]["translation_text"]
return result
# Create the Gradio interface
iface = gr.Interface(
fn=translate_text,
inputs=gr.Textbox(label="Enter English Text"),
outputs=gr.Textbox(label="Hindi Translation"),
title="English to Hindi Translator",
description="Enter English text to translate it into Hindi using a HuggingFace transformer model."
)
# 🚀 Launch with API enabled so external clients like Discord can POST data
# Enable queuing
app.queue()
# Launch the app
app.launch()