Shekarss commited on
Commit
084f5b7
·
verified ·
1 Parent(s): 49e737f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load your fine-tuned model
5
+ model_checkpoint = "Shekarss/marian-finetuned-kde4-en-to-fr"
6
+ translator = pipeline("translation", model=model_checkpoint)
7
+
8
+ # Translation function
9
+ def translate_text(text):
10
+ if not text.strip():
11
+ return "Please enter some text to translate."
12
+ result = translator(text)
13
+ return result[0]['translation_text']
14
+
15
+ # Build Gradio UI
16
+ with gr.Blocks(title="English → French Translator") as demo:
17
+ gr.Markdown(
18
+ """
19
+ # 🌐 English to French Translator
20
+ Translate your English sentences into French instantly!
21
+ Enter text below and see the translation.
22
+ """
23
+ )
24
+
25
+ with gr.Row():
26
+ with gr.Column():
27
+ input_text = gr.Textbox(
28
+ label="Enter English Text",
29
+ placeholder="Type your sentence here...",
30
+ lines=5
31
+ )
32
+ translate_btn = gr.Button("Translate 🡆 French")
33
+ with gr.Column():
34
+ output_text = gr.Textbox(
35
+ label="French Translation",
36
+ placeholder="Your translation will appear here...",
37
+ lines=5
38
+ )
39
+
40
+ translate_btn.click(fn=translate_text, inputs=input_text, outputs=output_text)
41
+
42
+ # Launch Space
43
+ demo.launch()