File size: 712 Bytes
a95bd26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()