Till Fischer
commited on
Commit
·
2f86969
1
Parent(s):
b3af7d8
Add Gradio app
Browse files- app.py +35 -42
- aspect-sentiment-analyzer +1 -0
app.py
CHANGED
@@ -1,56 +1,49 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from pathlib import Path
|
|
|
3 |
import shutil
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
# Sprachliste korrekt übergeben
|
20 |
-
lang_args = []
|
21 |
-
for lang in languages:
|
22 |
-
lang_args.append(lang)
|
23 |
-
|
24 |
-
try:
|
25 |
-
subprocess.run(
|
26 |
-
[
|
27 |
-
"python3", "analyze_aspects.py",
|
28 |
-
"--db-path", str(db_path),
|
29 |
-
"--isbn", isbn,
|
30 |
-
"--languages", *lang_args
|
31 |
-
],
|
32 |
-
check=True
|
33 |
)
|
34 |
-
except subprocess.CalledProcessError as e:
|
35 |
-
return f"Analyse fehlgeschlagen: {e}", None
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
|
|
40 |
iface = gr.Interface(
|
41 |
-
fn=
|
42 |
inputs=[
|
43 |
-
gr.File(label="SQLite-Datenbank (.sqlite)"),
|
44 |
-
gr.
|
45 |
-
gr.CheckboxGroup(["de", "en"], label="Sprachen", value=["de"])
|
46 |
],
|
47 |
outputs=[
|
48 |
gr.Text(label="Status"),
|
49 |
-
gr.Image(
|
50 |
],
|
51 |
-
title="Aspekt-
|
52 |
-
description="Lade eine
|
53 |
)
|
54 |
|
55 |
-
|
56 |
-
iface.launch()
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
from analyze_aspects import analyze_quickwin, visualize_aspects
|
5 |
from pathlib import Path
|
6 |
+
import tempfile
|
7 |
import shutil
|
8 |
+
|
9 |
+
def run_analysis(db_file, isbn, languages):
|
10 |
+
if not isbn.strip():
|
11 |
+
return "❗ Bitte ISBN angeben.", None
|
12 |
+
|
13 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
14 |
+
tmp_path = Path(tmpdir) / "db.sqlite"
|
15 |
+
shutil.copy(db_file.name, tmp_path)
|
16 |
+
|
17 |
+
# Analyse
|
18 |
+
results = analyze_quickwin(
|
19 |
+
db_path=tmp_path,
|
20 |
+
isbn=isbn,
|
21 |
+
device=-1,
|
22 |
+
languages=languages
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
)
|
|
|
|
|
24 |
|
25 |
+
if not results:
|
26 |
+
return "⚠️ Keine relevanten Aspekte gefunden oder Fehler in der Analyse.", None
|
27 |
+
|
28 |
+
# Diagramm erzeugen
|
29 |
+
visualize_aspects(results, Path(tmpdir))
|
30 |
+
chart_path = Path(tmpdir) / "sentiment_aspekte.png"
|
31 |
+
return "✅ Analyse abgeschlossen!", chart_path
|
32 |
|
33 |
+
# Gradio Interface
|
34 |
iface = gr.Interface(
|
35 |
+
fn=run_analysis,
|
36 |
inputs=[
|
37 |
+
gr.File(label="SQLite-Datenbank (.sqlite)", file_types=[".sqlite"]),
|
38 |
+
gr.Text(label="ISBN", placeholder="z. B. 9783446264199"),
|
39 |
+
gr.CheckboxGroup(choices=["de", "en"], label="Sprachen", value=["de"])
|
40 |
],
|
41 |
outputs=[
|
42 |
gr.Text(label="Status"),
|
43 |
+
gr.Image(label="Sentiment-Diagramm", type="filepath")
|
44 |
],
|
45 |
+
title="📖 Aspekt-Sentiment-Analyse",
|
46 |
+
description="Lade eine SQLite-Datenbank hoch, gib eine ISBN an und analysiere die wichtigsten inhaltlichen Aspekte und deren Sentiment."
|
47 |
)
|
48 |
|
49 |
+
iface.launch()
|
|
aspect-sentiment-analyzer
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit de51e3830863b035c34001bde80aaee1e115d2ab
|