pratikshahp's picture
Create app.py
5683e58 verified
raw
history blame contribute delete
552 Bytes
import gradio as gr
from transformers import pipeline
translator = pipeline("translation_en_to_hi", model="Helsinki-NLP/opus-mt-en-hi")
@gr.Interface(
fn=lambda text: translator(text, max_length=400)[0]["translation_text"],
inputs=gr.Textbox(),
outputs=gr.Textbox()
)
def translate_text(text):
if not text.strip():
return "⚠️ Please provide input text."
return translator(text, max_length=400)[0]["translation_text"]
iface = gr.Interface(fn=translate_text, inputs="text", outputs="text")
iface.queue()
iface.launch()