Spaces:
Sleeping
Sleeping
| 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() | |