Briwel commited on
Commit
6b1d45a
·
verified ·
1 Parent(s): 5a56be2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -66
app.py CHANGED
@@ -1,73 +1,25 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Charger un modèle français performant pour le résumé
5
- summarizer = pipeline("summarization", model="moussaKam/barthez-orangesum-title")
6
 
7
  def summarize_text(text):
8
- if not text or not text.strip():
9
- return "Veuillez entrer un texte à résumer."
10
- try:
11
- # Limiter pour éviter les erreurs de longueur
12
- summary = summarizer(text[:2000], max_length=120, min_length=40, do_sample=False)
13
- return summary[0]["summary_text"]
14
- except Exception as e:
15
- return "Erreur lors du résumé. Veuillez réessayer avec un texte plus court."
16
-
17
- # Couleurs Chariow-style (tu peux les ajuster)
18
- PRIMARY_COLOR = "#2563eb" # bleu moderne
19
- BACKGROUND_COLOR = "#f9fafb"
20
- TEXT_COLOR = "#111827"
21
-
22
- with gr.Blocks(
23
- title="Résumeur IA – Chariow TechWorks",
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()