Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Define the
|
| 5 |
-
|
| 6 |
|
| 7 |
# Define the Gradio interface
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
score = results[0]['score']
|
| 12 |
-
return f"Label: {label}, Score: {score}"
|
| 13 |
|
| 14 |
iface = gr.Interface(
|
| 15 |
-
fn=
|
| 16 |
-
inputs=
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
live=True,
|
| 19 |
-
title="Multilingual
|
| 20 |
-
description="
|
| 21 |
)
|
| 22 |
|
| 23 |
# Start the Gradio interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Define the translation pipeline
|
| 5 |
+
translator = pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt")
|
| 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 using facebook/mbart-large-50-many-to-many-mmt model.",
|
| 25 |
)
|
| 26 |
|
| 27 |
# Start the Gradio interface
|