first commit
Browse files- README.md +1 -1
- app.py +48 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🚀
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
|
|
|
| 1 |
---
|
| 2 |
+
title: frenglish
|
| 3 |
emoji: 🚀
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: indigo
|
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize translation pipelines
|
| 5 |
+
translator_fr_to_en = pipeline('translation_fr_to_en', model='Helsinki-NLP/opus-mt-fr-en')
|
| 6 |
+
translator_en_to_fr = pipeline('translation_en_to_fr', model='Helsinki-NLP/opus-mt-en-fr')
|
| 7 |
+
|
| 8 |
+
def translate(text, direction):
|
| 9 |
+
# If no direction is provided or "Français à Anglais" is selected
|
| 10 |
+
if direction == "Français à Anglais":
|
| 11 |
+
return translator_fr_to_en(text, max_length=512)[0]['translation_text']
|
| 12 |
+
else: # "Anglais à Français" is selected
|
| 13 |
+
return translator_en_to_fr(text, max_length=512)[0]['translation_text']
|
| 14 |
+
|
| 15 |
+
# Custom CSS to style the Gradio interface
|
| 16 |
+
custom_css = """
|
| 17 |
+
body { font-family: Arial, sans-serif; }
|
| 18 |
+
h1 { color: #333366; }
|
| 19 |
+
label { font-weight: bold; }
|
| 20 |
+
input[type="text"], textarea { border-radius: 20px; border: 1px solid #ccc; padding: 10px; width: 100%; box-sizing: border-box; }
|
| 21 |
+
.button { background-color: #4CAF50; border: none; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 12px; }
|
| 22 |
+
footer{display:none !important}
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
examples = [
|
| 26 |
+
["Elle est intéressée par la haute couture.", "Français à Anglais"],
|
| 27 |
+
["I’m looking forward to seeing you.", "Anglais à Français"],
|
| 28 |
+
["Appelons-le un jour.", "Français à Anglais"],
|
| 29 |
+
["It’s the life.", "Anglais à Français"],
|
| 30 |
+
["C’est la vie.", "Français à Anglais"],
|
| 31 |
+
["Let's call him one day.", "Anglais à Français"]
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# Create the Gradio interface
|
| 35 |
+
interface = gr.Interface(fn=translate,
|
| 36 |
+
inputs=[gr.Textbox(label="Texte à traduire"),
|
| 37 |
+
gr.Radio(["Français à Anglais", "Anglais à Français"],
|
| 38 |
+
label="Direction de traduction",
|
| 39 |
+
value="Français à Anglais")],
|
| 40 |
+
outputs=gr.Textbox(label="Texte traduit"),
|
| 41 |
+
examples=examples,
|
| 42 |
+
title="Traducteur Français-Anglais / English-French Translator",
|
| 43 |
+
description="""<p>Une application simple pour traduire du texte du français vers l'anglais et vice versa. Entrez votre texte et sélectionnez la direction de la traduction.</p>""",
|
| 44 |
+
css=custom_css,
|
| 45 |
+
allow_flagging="never")
|
| 46 |
+
|
| 47 |
+
# Launch the app
|
| 48 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
gradio
|
| 3 |
+
transformers
|