File size: 2,068 Bytes
2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 d96f744 cca703d 5741580 cca703d 5741580 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 b3af7d8 2f86969 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# app.py
import gradio as gr
from analyze_aspects import analyze_quickwin, visualize_aspects
from pathlib import Path
import tempfile
import shutil
import os
import nltk
import logging
# --- NLTK-DATEN-SETUP ---
# Dieser Block stellt sicher, dass die notwendigen Daten beim Start des Spaces vorhanden sind.
try:
nltk.data.find('tokenizers/punkt')
logging.info("NLTK 'punkt'-Daten bereits vorhanden.")
except nltk.downloader.DownloadError:
logging.info("NLTK 'punkt'-Daten nicht gefunden. Lade herunter...")
nltk.download('punkt', quiet=True) # quiet=True verhindert zu viel Log-Ausgabe
logging.info("NLTK 'punkt'-Daten erfolgreich heruntergeladen.")
# --- ENDE NLTK-SETUP ---
def run_analysis(db_file, isbn, languages):
if not isbn.strip():
return "β Bitte ISBN angeben.", None
with tempfile.TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir) / "db.sqlite"
shutil.copy(db_file.name, tmp_path)
# Analyse
results = analyze_quickwin(
db_path=tmp_path,
isbn=isbn,
device=-1,
languages=languages
)
if not results:
return "β οΈ Keine relevanten Aspekte gefunden oder Fehler in der Analyse.", None
# Diagramm erzeugen
visualize_aspects(results, Path(tmpdir))
chart_path = Path(tmpdir) / "sentiment_aspekte.png"
return "β
Analyse abgeschlossen!", chart_path
# Gradio Interface
iface = gr.Interface(
fn=run_analysis,
inputs=[
gr.File(label="SQLite-Datenbank (.sqlite)", file_types=[".sqlite"]),
gr.Text(label="ISBN", placeholder="z.β―B. 9783446264199"),
gr.CheckboxGroup(choices=["de", "en"], label="Sprachen", value=["de"])
],
outputs=[
gr.Text(label="Status"),
gr.Image(label="Sentiment-Diagramm", type="filepath")
],
title="π Aspekt-Sentiment-Analyse",
description="Lade eine SQLite-Datenbank hoch, gib eine ISBN an und analysiere die wichtigsten inhaltlichen Aspekte und deren Sentiment."
)
iface.launch() |