Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,25 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# Charger
|
| 5 |
-
summarizer = pipeline("summarization", model="
|
| 6 |
|
| 7 |
def summarize_text(text):
|
| 8 |
-
if
|
| 9 |
-
return "Veuillez entrer
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate").set(
|
| 25 |
-
block_background_fill=BACKGROUND_COLOR,
|
| 26 |
-
body_background_fill=BACKGROUND_COLOR,
|
| 27 |
-
button_primary_background_fill=PRIMARY_COLOR,
|
| 28 |
-
button_primary_background_fill_hover="#1d4ed8",
|
| 29 |
-
button_primary_text_color="white",
|
| 30 |
-
block_label_text_color=TEXT_COLOR,
|
| 31 |
-
block_title_text_color=TEXT_COLOR,
|
| 32 |
-
),
|
| 33 |
-
css="""
|
| 34 |
-
footer { display: none !important; }
|
| 35 |
-
.gradio-container { max-width: 800px; margin: auto; padding: 20px; }
|
| 36 |
-
h1 { text-align: center; font-weight: 700; margin-bottom: 8px; }
|
| 37 |
-
.subtitle { text-align: center; color: #4b5563; margin-bottom: 24px; }
|
| 38 |
-
"""
|
| 39 |
-
) as demo:
|
| 40 |
-
gr.Markdown(
|
| 41 |
-
|
| 42 |
-
<div style="text-align: center; margin-bottom: 20px;">
|
| 43 |
-
<h1>📝 Résumeur IA</h1>
|
| 44 |
-
<p class="subtitle">Par <strong>Chariow TechWorks</strong> — Automatisation intelligente pour les équipes non techniques</p>
|
| 45 |
-
</div>
|
| 46 |
-
)
|
| 47 |
-
gr.Markdown("➡️ Collez un texte (email, note, article…) et obtenez un **résumé clair, court et en bon français**.")
|
| 48 |
-
|
| 49 |
-
with gr.Row():
|
| 50 |
-
with gr.Column():
|
| 51 |
-
input_text = gr.Textbox(
|
| 52 |
-
label="📄 Votre texte",
|
| 53 |
-
placeholder="Exemple : « Dans le cadre de notre transition vers des outils plus automatisés, nous souhaitons simplifier la gestion… »",
|
| 54 |
-
lines=10,
|
| 55 |
-
max_lines=15
|
| 56 |
-
)
|
| 57 |
-
with gr.Row():
|
| 58 |
-
clear_btn = gr.ClearButton(value="🗑️ Effacer", components=[input_text])
|
| 59 |
-
submit_btn = gr.Button("🚀 Résumer", variant="primary")
|
| 60 |
-
|
| 61 |
-
with gr.Column():
|
| 62 |
-
output_text = gr.Textbox(
|
| 63 |
-
label="✨ Résumé généré",
|
| 64 |
-
lines=5,
|
| 65 |
-
interactive=False,
|
| 66 |
-
elem_classes=["output-box"]
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
# Lier le bouton et la fonction
|
| 70 |
-
submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output_text)
|
| 71 |
-
input_text.submit(fn=summarize_text, inputs=input_text, outputs=output_text) # Entrée + Entrée = résumer
|
| 72 |
|
| 73 |
demo.launch()
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Charger le modèle de résumé (BART CNN)
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
|
| 7 |
def summarize_text(text):
|
| 8 |
+
if len(text.strip()) == 0:
|
| 9 |
+
return "Veuillez entrer du texte à résumer."
|
| 10 |
+
# Le modèle a une limite de ~1024 tokens ; on tronque si nécessaire
|
| 11 |
+
max_input_length = 1024
|
| 12 |
+
inputs = summarizer.tokenizer(text, return_tensors="pt", truncation=True, max_length=max_input_length)
|
| 13 |
+
summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 14 |
+
return summary[0]['summary_text']
|
| 15 |
+
|
| 16 |
+
# Interface Gradio
|
| 17 |
+
with gr.Blocks(title="Résumeur IA – Chariow TechWorks") as demo:
|
| 18 |
+
gr.Markdown("## 📝 Résumeur Automatique")
|
| 19 |
+
gr.Markdown("Collez un texte long (article, email, note...) et obtenez un résumé clair et concis.")
|
| 20 |
+
input_text = gr.Textbox(label="Texte à résumer", lines=10)
|
| 21 |
+
output_text = gr.Textbox(label="Résumé", lines=5)
|
| 22 |
+
btn = gr.Button("Résumer")
|
| 23 |
+
btn.click(fn=summarize_text, inputs=input_text, outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
demo.launch()
|