Translation_API / app.py
Sheemz's picture
Create app.py
a95bd26 verified
raw
history blame
712 Bytes
import gradio as gr
from transformers import pipeline
# Load your model from the Hugging Face repository
model_name = "SLPG/English_to_Urdu_Unsupervised_MT"
translator = pipeline("translation", model=model_name)
# Define the translation function
def translate_text(input_text):
result = translator(input_text, max_length=400)
return result[0]['translation_text']
# Create the Gradio interface
interface = gr.Interface(
fn=translate_text,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text to translate"),
outputs="text",
title="Translation Model Inference",
description="Translate text using the Hugging Face translation model."
)
# Launch the interface
interface.launch()