Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,23 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Initialize the translation pipeline with a pre-trained model
|
5 |
+
translator = pipeline("translation_en_to_fr", model="t5-small")
|
6 |
|
7 |
+
def translate(text):
|
8 |
+
# Translate the input text from English to French
|
9 |
+
result = translator(text, max_length=512)
|
10 |
+
return result[0]['translation_text']
|
11 |
+
|
12 |
+
# Define the Gradio interface
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=translate,
|
15 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter English text here..."),
|
16 |
+
outputs="text",
|
17 |
+
title="English to French Translation",
|
18 |
+
description="This app uses the T5 model to translate English text to French. Type some text and press submit."
|
19 |
+
)
|
20 |
+
|
21 |
+
# Launch the app
|
22 |
+
if __name__ == "__main__":
|
23 |
+
iface.launch()
|