|
|
|
|
|
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 |
|
|
|
|
|
|
|
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) |
|
logging.info("NLTK 'punkt'-Daten erfolgreich heruntergeladen.") |
|
|
|
|
|
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) |
|
|
|
|
|
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 |
|
|
|
|
|
visualize_aspects(results, Path(tmpdir)) |
|
chart_path = Path(tmpdir) / "sentiment_aspekte.png" |
|
return "β
Analyse abgeschlossen!", chart_path |
|
|
|
|
|
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() |