File size: 1,337 Bytes
3ff8eeb
 
 
 
89a8e5f
3ff8eeb
 
 
4066c7d
 
 
 
 
 
 
 
89a8e5f
 
 
 
 
4066c7d
89a8e5f
 
 
 
 
 
 
 
 
2f777cd
4066c7d
 
89a8e5f
3ff8eeb
89a8e5f
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
import gradio as gr
from transformers import pipeline

def translator(sentence):
    model_checkpoint = "AirrStorm/Finetuned-OpusMT-EN2FR"
    translator = pipeline("translation", model=model_checkpoint)
    return translator(sentence)[0]['translation_text']


examples = [
    ["The program runs without errors"],
    ["I need to debug the code to find the issue."],
    ["The code has a error in line 15."],
    ["I will meet you at the park in the afternoon."],
    ["The weather is beautiful today."]
]
# Create a cleaner UI with input and output labels and additional styling
demo = gr.Interface(
    fn=translator,
    inputs=gr.Textbox(
        lines=3, 
        placeholder="Enter text in English to translate it into French (e.g., 'The program runs smoothly.')", 
        label="Input (English)"
    ),
    outputs=gr.Textbox(
        lines=3, 
        placeholder="Translation will appear here...", 
        label="Output (French)"
    ),
    title="English to French Translator",
    description="This tool translates text from English to French. Especially fine-tuned for programming-related terms.",
    live=False,  # Live updates are not necessary for translation
    theme="dark-peach",  # Optional: use the Hugging Face theme
    examples=examples  # Optional: Add examples to make it easier for users 
)

demo.launch()