File size: 1,096 Bytes
4b74d53
 
 
73afe6a
4b74d53
 
73afe6a
556a464
 
 
 
 
 
4b74d53
73afe6a
 
556a464
 
 
 
 
4b74d53
 
73afe6a
 
 
 
 
 
 
 
4b74d53
73afe6a
f27d523
91c238b
f27d523
 
91c238b
f27d523
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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

def translate_text(text):
    if not text:
        return "⚠️ Please provide some input text."
    result = translator(
        text,
        max_length=100,
        clean_up_tokenization_spaces=True
    )[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
iface.queue()

# Launch the app
iface.launch()