Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,22 @@
|
|
| 1 |
from transformers import pipeline
|
|
|
|
| 2 |
|
|
|
|
| 3 |
translator = pipeline("translation_en_to_fr", model="t5-small")
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|