Till Fischer commited on
Commit
b3af7d8
·
1 Parent(s): de51e38

Initial commit for HF Space

Browse files
Files changed (3) hide show
  1. analyze_aspects.py +0 -0
  2. app.py +56 -0
  3. requirements.txt +5 -0
analyze_aspects.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pathlib import Path
3
+ import shutil
4
+ import uuid
5
+ import subprocess
6
+
7
+ def analyze_sqlite(sqlite_file, isbn, languages):
8
+ # Arbeitsverzeichnis vorbereiten
9
+ run_id = str(uuid.uuid4())
10
+ workdir = Path(f"/tmp/{run_id}")
11
+ output_dir = Path("output")
12
+ workdir.mkdir(parents=True, exist_ok=True)
13
+ output_dir.mkdir(parents=True, exist_ok=True)
14
+
15
+ # DB-Datei speichern
16
+ db_path = workdir / "buch_datenbank.sqlite"
17
+ shutil.copy(sqlite_file.name, db_path)
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
+ chart_path = output_dir / "sentiment_aspekte.png"
38
+ return "Analyse abgeschlossen ✅", str(chart_path) if chart_path.exists() else None
39
+
40
+ iface = gr.Interface(
41
+ fn=analyze_sqlite,
42
+ inputs=[
43
+ gr.File(label="SQLite-Datenbank (.sqlite)"),
44
+ gr.Textbox(label="ISBN", placeholder="9783446264199"),
45
+ gr.CheckboxGroup(["de", "en"], label="Sprachen", value=["de"])
46
+ ],
47
+ outputs=[
48
+ gr.Text(label="Status"),
49
+ gr.Image(type="filepath", label="Sentiment-Diagramm")
50
+ ],
51
+ title="Aspekt-Sentimentanalyse",
52
+ description="Lade eine bereinigte SQLite-Datenbank hoch und erhalte eine visuelle Analyse der Sentiment-Scores nach Aspekten."
53
+ )
54
+
55
+ if __name__ == "__main__":
56
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ nltk
4
+ matplotlib
5
+ torch