Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Modelle
|
5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
headline_model = pipeline("text2text-generation", model="google/flan-t5-base")
|
7 |
|
@@ -10,19 +10,28 @@ def simplify_and_structure(text):
|
|
10 |
return "❗ Bitte gib einen längeren Text ein."
|
11 |
|
12 |
try:
|
13 |
-
#
|
14 |
summary = summarizer(text, max_length=150, min_length=40, do_sample=False)[0]['summary_text']
|
15 |
|
16 |
-
#
|
17 |
headline_prompt = f"Schreibe eine passende Überschrift zu diesem Text:\n{text}"
|
18 |
headline = headline_model(headline_prompt, max_length=20, do_sample=False)[0]['generated_text']
|
19 |
|
20 |
-
#
|
21 |
output = f"## 🏷 {headline.strip()}\n\n{summary.strip()}"
|
22 |
return output
|
23 |
except Exception as e:
|
24 |
-
return f"⚠️ Fehler
|
25 |
|
26 |
-
# Gradio
|
27 |
with gr.Blocks() as demo:
|
28 |
-
gr.Markdown("## 📚
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Modelle laden
|
5 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
6 |
headline_model = pipeline("text2text-generation", model="google/flan-t5-base")
|
7 |
|
|
|
10 |
return "❗ Bitte gib einen längeren Text ein."
|
11 |
|
12 |
try:
|
13 |
+
# Zusammenfassung erzeugen
|
14 |
summary = summarizer(text, max_length=150, min_length=40, do_sample=False)[0]['summary_text']
|
15 |
|
16 |
+
# Überschrift generieren
|
17 |
headline_prompt = f"Schreibe eine passende Überschrift zu diesem Text:\n{text}"
|
18 |
headline = headline_model(headline_prompt, max_length=20, do_sample=False)[0]['generated_text']
|
19 |
|
20 |
+
# Strukturierte Ausgabe
|
21 |
output = f"## 🏷 {headline.strip()}\n\n{summary.strip()}"
|
22 |
return output
|
23 |
except Exception as e:
|
24 |
+
return f"⚠️ Fehler:\n{str(e)}"
|
25 |
|
26 |
+
# Gradio App
|
27 |
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## 📚 Textvereinfachung & Überschrift (Mittelschulniveau)")
|
29 |
+
|
30 |
+
input_text = gr.Textbox(label="📝 Ursprünglicher Text", lines=12)
|
31 |
+
output_markdown = gr.Textbox(label="🧠 Ausgabe", lines=12, interactive=False)
|
32 |
+
|
33 |
+
run_button = gr.Button("Vereinfachen & Überschrift erzeugen")
|
34 |
+
|
35 |
+
run_button.click(fn=simplify_and_structure, inputs=input_text, outputs=output_markdown)
|
36 |
+
|
37 |
+
demo.launch()
|