TNK21 commited on
Commit
178357f
·
1 Parent(s): afaefc1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Define the translation pipeline
5
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-mul")
6
+
7
+ # Define the Gradio interface
8
+ def translate_text(text, target_language):
9
+ translated_text = translator(text, target_language)[0]['translation_text']
10
+ return translated_text
11
+
12
+ iface = gr.Interface(
13
+ fn=translate_text,
14
+ inputs=[
15
+ gr.inputs.Textbox(label="Input Text"),
16
+ gr.inputs.Dropdown(
17
+ label="Target Language",
18
+ choices=["es", "fr", "de", "it"], # Add more languages as needed
19
+ ),
20
+ ],
21
+ outputs=gr.outputs.Textbox(label="Translated Text"),
22
+ live=True,
23
+ title="Multilingual Translation Tool",
24
+ description="Translate text into multiple languages.",
25
+ )
26
+
27
+ # Start the Gradio interface
28
+ iface.launch()