Till Fischer
Add Gradio app
2f86969
raw
history blame
1.52 kB
# app.py
import gradio as gr
from analyze_aspects import analyze_quickwin, visualize_aspects
from pathlib import Path
import tempfile
import shutil
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()