rahimizadeh commited on
Commit
b3db685
·
verified ·
1 Parent(s): 9a3d357

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -1,4 +1,22 @@
1
  from transformers import pipeline
 
2
 
 
3
  translator = pipeline("translation_en_to_fr", model="t5-small")
4
- print(translator("Machine learning is amazing."))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
+ import gradio as gr
3
 
4
+ # Load the translation pipeline
5
  translator = pipeline("translation_en_to_fr", model="t5-small")
6
+
7
+ def translate_text(text):
8
+ translation = translator(text)[0]["translation_text"]
9
+ return translation
10
+
11
+ # Create a Gradio interface
12
+ demo = gr.Interface(
13
+ fn=translate_text,
14
+ inputs=gr.Textbox(label="Enter English Text", placeholder="Type something..."),
15
+ outputs=gr.Textbox(label="French Translation"),
16
+ title="English to French Translator",
17
+ description="Translate English text to French using T5-small.",
18
+ examples=[["Machine learning is amazing."], ["Hello, how are you?"]]
19
+ )
20
+
21
+ # Launch the app
22
+ demo.launch()