File size: 1,313 Bytes
084f5b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
import gradio as gr
from transformers import pipeline

# Load your fine-tuned model
model_checkpoint = "Shekarss/marian-finetuned-kde4-en-to-fr"
translator = pipeline("translation", model=model_checkpoint)

# Translation function
def translate_text(text):
    if not text.strip():
        return "Please enter some text to translate."
    result = translator(text)
    return result[0]['translation_text']

# Build Gradio UI
with gr.Blocks(title="English → French Translator") as demo:
    gr.Markdown(
        """
        # 🌐 English to French Translator
        Translate your English sentences into French instantly!  
        Enter text below and see the translation.
        """
    )
    
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(
                label="Enter English Text",
                placeholder="Type your sentence here...",
                lines=5
            )
            translate_btn = gr.Button("Translate 🡆 French")
        with gr.Column():
            output_text = gr.Textbox(
                label="French Translation",
                placeholder="Your translation will appear here...",
                lines=5
            )

    translate_btn.click(fn=translate_text, inputs=input_text, outputs=output_text)

# Launch Space
demo.launch()