Spaces:
Sleeping
Sleeping
Upload 9 files
Browse filesFiles changed (10)
- .gitattributes+1
- DockerfileAdded+26
- README.md+3-2
- app.pyAdded+758
- background_bottom.pngAdded
- background_mid.pngAdded
- background_top.pngAdded
- gitattributes.txtAdded+36
- requirements.txtAdded+17
- style.cssAdded+326
32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textbackground_top.png filter=lfs diff=lfs merge=lfs -text1234567891011121314151617181920212223242526FROM python:3.10-slim
ENV DEBIAN_FRONTEND=noninteractiveENV PYTHONDONTWRITEBYTECODE=1ENV PYTHONUNBUFFERED=1
ENV GRADIO_SERVER_NAME=0.0.0.0ENV GRADIO_SERVER_PORT=7860
WORKDIR /appCOPY . /app
# Python deps (from requirements.txt)RUN pip install --no-cache-dir -r requirements.txt
# Notebook execution depsRUN pip install --no-cache-dir notebook ipykernel papermill
# Pre-install packages the notebooks use via !pip installRUN pip install --no-cache-dir textblob faker vaderSentiment transformers
RUN python -m ipykernel install --user --name python3 --display-name "Python 3"
EXPOSE 7860
CMD ["python", "app.py"]123234567891011---title: Codingworkshop2emoji: ⚡title: SE21 App Templateemoji: 📊colorFrom: bluecolorTo: purplesdk: dockerpinned: falseshort_description: AI-enhanced analytics dashboard template for SE21 students---
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758import osimport reimport jsonimport timeimport tracebackfrom pathlib import Pathfrom typing import Dict, Any, List, Tuple
import pandas as pdimport gradio as grimport papermill as pmimport plotly.graph_objects as go
# Optional LLM (HuggingFace Inference API)try: from huggingface_hub import InferenceClientexcept Exception: InferenceClient = None
# =========================================================# CONFIG# =========================================================
BASE_DIR = Path(__file__).resolve().parent
NB1 = os.environ.get("NB1", "datacreation.ipynb").strip()NB2 = os.environ.get("NB2", "pythonanalysis.ipynb").strip()
RUNS_DIR = BASE_DIR / "runs"ART_DIR = BASE_DIR / "artifacts"PY_FIG_DIR = ART_DIR / "py" / "figures"PY_TAB_DIR = ART_DIR / "py" / "tables"
PAPERMILL_TIMEOUT = int(os.environ.get("PAPERMILL_TIMEOUT", "1800"))MAX_PREVIEW_ROWS = int(os.environ.get("MAX_FILE_PREVIEW_ROWS", "50"))MAX_LOG_CHARS = int(os.environ.get("MAX_LOG_CHARS", "8000"))
HF_API_KEY = os.environ.get("HF_API_KEY", "").strip()MODEL_NAME = os.environ.get("MODEL_NAME", "deepseek-ai/DeepSeek-R1").strip()HF_PROVIDER = os.environ.get("HF_PROVIDER", "novita").strip()N8N_WEBHOOK_URL = os.environ.get("N8N_WEBHOOK_URL", "").strip()
LLM_ENABLED = bool(HF_API_KEY) and InferenceClient is not Nonellm_client = ( InferenceClient(provider=HF_PROVIDER, api_key=HF_API_KEY) if LLM_ENABLED else None)
# =========================================================# HELPERS# =========================================================
def ensure_dirs(): for p in [RUNS_DIR, ART_DIR, PY_FIG_DIR, PY_TAB_DIR]: p.mkdir(parents=True, exist_ok=True)
def stamp(): return time.strftime("%Y%m%d-%H%M%S")
def tail(text: str, n: int = MAX_LOG_CHARS) -> str: return (text or "")[-n:]
def _ls(dir_path: Path, exts: Tuple[str, ...]) -> List[str]: if not dir_path.is_dir(): return [] return sorted(p.name for p in dir_path.iterdir() if p.is_file() and p.suffix.lower() in exts)
def _read_csv(path: Path) -> pd.DataFrame: return pd.read_csv(path, nrows=MAX_PREVIEW_ROWS)
def _read_json(path: Path): with path.open(encoding="utf-8") as f: return json.load(f)
def artifacts_index() -> Dict[str, Any]: return { "python": { "figures": _ls(PY_FIG_DIR, (".png", ".jpg", ".jpeg")), "tables": _ls(PY_TAB_DIR, (".csv", ".json")), }, }
# =========================================================# PIPELINE RUNNERS# =========================================================
def run_notebook(nb_name: str) -> str: ensure_dirs() nb_in = BASE_DIR / nb_name if not nb_in.exists(): return f"ERROR: {nb_name} not found." nb_out = RUNS_DIR / f"run_{stamp()}_{nb_name}" pm.execute_notebook( input_path=str(nb_in), output_path=str(nb_out), cwd=str(BASE_DIR), log_output=True, progress_bar=False, request_save_on_cell_execute=True, execution_timeout=PAPERMILL_TIMEOUT, ) return f"Executed {nb_name}"
def run_datacreation() -> str: try: log = run_notebook(NB1) csvs = [f.name for f in BASE_DIR.glob("*.csv")] return f"OK {log}\n\nCSVs now in /app:\n" + "\n".join(f" - {c}" for c in sorted(csvs)) except Exception as e: return f"FAILED {e}\n\n{traceback.format_exc()[-2000:]}"
def run_pythonanalysis() -> str: try: log = run_notebook(NB2) idx = artifacts_index() figs = idx["python"]["figures"] tabs = idx["python"]["tables"] return ( f"OK {log}\n\n" f"Figures: {', '.join(figs) or '(none)'}\n" f"Tables: {', '.join(tabs) or '(none)'}" ) except Exception as e: return f"FAILED {e}\n\n{traceback.format_exc()[-2000:]}"
def run_full_pipeline() -> str: logs = [] logs.append("=" * 50) logs.append("STEP 1/2: Data Creation (web scraping + synthetic data)") logs.append("=" * 50) logs.append(run_datacreation()) logs.append("") logs.append("=" * 50) logs.append("STEP 2/2: Python Analysis (sentiment, ARIMA, dashboard)") logs.append("=" * 50) logs.append(run_pythonanalysis()) return "\n".join(logs)
# =========================================================# GALLERY LOADERS# =========================================================
def _load_all_figures() -> List[Tuple[str, str]]: """Return list of (filepath, caption) for Gallery.""" items = [] for p in sorted(PY_FIG_DIR.glob("*.png")): items.append((str(p), p.stem.replace('_', ' ').title())) return items
def _load_table_safe(path: Path) -> pd.DataFrame: try: if path.suffix == ".json": obj = _read_json(path) if isinstance(obj, dict): return pd.DataFrame([obj]) return pd.DataFrame(obj) return _read_csv(path) except Exception as e: return pd.DataFrame([{"error": str(e)}])
def refresh_gallery(): """Called when user clicks Refresh on Gallery tab.""" figures = _load_all_figures() idx = artifacts_index()
table_choices = list(idx["python"]["tables"])
default_df = pd.DataFrame() if table_choices: default_df = _load_table_safe(PY_TAB_DIR / table_choices[0])
return ( figures if figures else [], gr.update(choices=table_choices, value=table_choices[0] if table_choices else None), default_df, )
def on_table_select(choice: str): if not choice: return pd.DataFrame([{"hint": "Select a table above."}]) path = PY_TAB_DIR / choice if not path.exists(): return pd.DataFrame([{"error": f"File not found: {choice}"}]) return _load_table_safe(path)
# =========================================================# KPI LOADER# =========================================================
def load_kpis() -> Dict[str, Any]: for candidate in [PY_TAB_DIR / "kpis.json", PY_FIG_DIR / "kpis.json"]: if candidate.exists(): try: return _read_json(candidate) except Exception: pass return {}
# =========================================================# AI DASHBOARD -- LLM picks what to display# =========================================================
DASHBOARD_SYSTEM = """You are an AI dashboard assistant for a book-sales analytics app.The user asks questions or requests about their data. You have access to pre-computedartifacts from a Python analysis pipeline.
AVAILABLE ARTIFACTS (only reference ones that exist):{artifacts_json}
KPI SUMMARY: {kpis_json}
YOUR JOB:1. Answer the user's question conversationally using the KPIs and your knowledge of the artifacts.2. At the END of your response, output a JSON block (fenced with ```json ... ```) that tells the dashboard which artifact to display. The JSON must have this shape: {{"show": "figure"|"table"|"none", "scope": "python", "filename": "..."}}
- Use "show": "figure" to display a chart image. - Use "show": "table" to display a CSV/JSON table. - Use "show": "none" if no artifact is relevant.
RULES:- If the user asks about sales trends or forecasting by title, show sales_trends or arima figures.- If the user asks about sentiment, show sentiment figure or sentiment_counts table.- If the user asks about forecast accuracy or ARIMA, show arima figures.- If the user asks about top sellers, show top_titles_by_units_sold.csv.- If the user asks a general data question, pick the most relevant artifact.- Keep your answer concise (2-4 sentences), then the JSON block."""
JSON_BLOCK_RE = re.compile(r"```json\s*(\{.*?\})\s*```", re.DOTALL)FALLBACK_JSON_RE = re.compile(r"\{[^{}]*\"show\"[^{}]*\}", re.DOTALL)
def _parse_display_directive(text: str) -> Dict[str, str]: m = JSON_BLOCK_RE.search(text) if m: try: return json.loads(m.group(1)) except json.JSONDecodeError: pass m = FALLBACK_JSON_RE.search(text) if m: try: return json.loads(m.group(0)) except json.JSONDecodeError: pass return {"show": "none"}
def _clean_response(text: str) -> str: """Strip the JSON directive block from the displayed response.""" return JSON_BLOCK_RE.sub("", text).strip()
def _n8n_call(msg: str) -> Tuple[str, Dict]: """Call the student's n8n webhook and return (reply, directive).""" import requests as req try: resp = req.post(N8N_WEBHOOK_URL, json={"question": msg}, timeout=20) data = resp.json() answer = data.get("answer", "No response from n8n workflow.") chart = data.get("chart", "none") if chart and chart != "none": return answer, {"show": "figure", "chart": chart} return answer, {"show": "none"} except Exception as e: return f"n8n error: {e}. Falling back to keyword matching.", None
def ai_chat(user_msg: str, history: list): """Chat function for the AI Dashboard tab.""" if not user_msg or not user_msg.strip(): return history, "", None, None
idx = artifacts_index() kpis = load_kpis()
# Priority: n8n webhook > HF LLM > keyword fallback if N8N_WEBHOOK_URL: reply, directive = _n8n_call(user_msg) if directive is None: reply_fb, directive = _keyword_fallback(user_msg, idx, kpis) reply += "\n\n" + reply_fb elif not LLM_ENABLED: reply, directive = _keyword_fallback(user_msg, idx, kpis) else: system = DASHBOARD_SYSTEM.format( artifacts_json=json.dumps(idx, indent=2), kpis_json=json.dumps(kpis, indent=2) if kpis else "(no KPIs yet, run the pipeline first)", ) msgs = [{"role": "system", "content": system}] for entry in (history or [])[-6:]: msgs.append(entry) msgs.append({"role": "user", "content": user_msg})
try: r = llm_client.chat_completion( model=MODEL_NAME, messages=msgs, temperature=0.3, max_tokens=600, stream=False, ) raw = ( r["choices"][0]["message"]["content"] if isinstance(r, dict) else r.choices[0].message.content ) directive = _parse_display_directive(raw) reply = _clean_response(raw) except Exception as e: reply = f"LLM error: {e}. Falling back to keyword matching." reply_fb, directive = _keyword_fallback(user_msg, idx, kpis) reply += "\n\n" + reply_fb
# Resolve artifacts — build interactive Plotly charts when possible chart_out = None tab_out = None show = directive.get("show", "none") fname = directive.get("filename", "") chart_name = directive.get("chart", "")
# Interactive chart builders keyed by name chart_builders = { "sales": build_sales_chart, "sentiment": build_sentiment_chart, "top_sellers": build_top_sellers_chart, }
if chart_name and chart_name in chart_builders: chart_out = chart_builders[chart_name]() elif show == "figure" and fname: # Fallback: try to match filename to a chart builder if "sales_trend" in fname: chart_out = build_sales_chart() elif "sentiment" in fname: chart_out = build_sentiment_chart() elif "arima" in fname or "forecast" in fname: chart_out = build_sales_chart() # closest interactive equivalent else: chart_out = _empty_chart(f"No interactive chart for {fname}")
if show == "table" and fname: fp = PY_TAB_DIR / fname if fp.exists(): tab_out = _load_table_safe(fp) else: reply += f"\n\n*(Could not find table: {fname})*"
new_history = (history or []) + [ {"role": "user", "content": user_msg}, {"role": "assistant", "content": reply}, ]
return new_history, "", chart_out, tab_out
def _keyword_fallback(msg: str, idx: Dict, kpis: Dict) -> Tuple[str, Dict]: """Simple keyword matcher when LLM is unavailable.""" msg_lower = msg.lower()
if not idx["python"]["figures"] and not idx["python"]["tables"]: return ( "No artifacts found yet. Please run the pipeline first (Tab 1), " "then come back here to explore the results.", {"show": "none"}, )
kpi_text = "" if kpis: total = kpis.get("total_units_sold", 0) kpi_text = ( f"Quick summary: **{kpis.get('n_titles', '?')}** book titles across " f"**{kpis.get('n_months', '?')}** months, with **{total:,.0f}** total units sold." )
if any(w in msg_lower for w in ["trend", "sales trend", "monthly sale"]): return ( f"Here are the sales trends. {kpi_text}", {"show": "figure", "chart": "sales"}, )
if any(w in msg_lower for w in ["sentiment", "review", "positive", "negative"]): return ( f"Here is the sentiment distribution across sampled book titles. {kpi_text}", {"show": "figure", "chart": "sentiment"}, )
if any(w in msg_lower for w in ["arima", "forecast", "predict"]): return ( f"Here are the sales trends and forecasts. {kpi_text}", {"show": "figure", "chart": "sales"}, )
if any(w in msg_lower for w in ["top", "best sell", "popular", "rank"]): return ( f"Here are the top-selling titles by units sold. {kpi_text}", {"show": "table", "scope": "python", "filename": "top_titles_by_units_sold.csv"}, )
if any(w in msg_lower for w in ["price", "pricing", "decision"]): return ( f"Here are the pricing decisions. {kpi_text}", {"show": "table", "scope": "python", "filename": "pricing_decisions.csv"}, )
if any(w in msg_lower for w in ["dashboard", "overview", "summary", "kpi"]): return ( f"Dashboard overview: {kpi_text}\n\nAsk me about sales trends, sentiment, forecasts, " "pricing, or top sellers to see specific visualizations.", {"show": "table", "scope": "python", "filename": "df_dashboard.csv"}, )
# Default return ( f"I can show you various analyses. {kpi_text}\n\n" "Try asking about: **sales trends**, **sentiment**, **ARIMA forecasts**, " "**pricing decisions**, **top sellers**, or **dashboard overview**.", {"show": "none"}, )
# =========================================================# KPI CARDS (BubbleBusters style)# =========================================================
def render_kpi_cards() -> str: kpis = load_kpis() if not kpis: return ( '<div style="background:rgba(255,255,255,.65);backdrop-filter:blur(16px);' 'border-radius:20px;padding:28px;text-align:center;' 'border:1.5px solid rgba(255,255,255,.7);' 'box-shadow:0 8px 32px rgba(124,92,191,.08);">' '<div style="font-size:36px;margin-bottom:10px;">📊</div>' '<div style="color:#a48de8;font-size:14px;' 'font-weight:800;margin-bottom:6px;">No data yet</div>' '<div style="color:#9d8fc4;font-size:12px;">' 'Run the pipeline to populate these cards.</div>' '</div>' )
def card(icon, label, value, colour): return f""" <div style="background:rgba(255,255,255,.72);backdrop-filter:blur(16px); border-radius:20px;padding:18px 14px 16px;text-align:center; border:1.5px solid rgba(255,255,255,.8); box-shadow:0 4px 16px rgba(124,92,191,.08); border-top:3px solid {colour};"> <div style="font-size:26px;margin-bottom:7px;line-height:1;">{icon}</div> <div style="color:#9d8fc4;font-size:9.5px;text-transform:uppercase; letter-spacing:1.8px;margin-bottom:7px;font-weight:800;">{label}</div> <div style="color:#2d1f4e;font-size:16px;font-weight:800;">{value}</div> </div>"""
kpi_config = [ ("n_titles", "📚", "Book Titles", "#a48de8"), ("n_months", "📅", "Time Periods", "#7aa6f8"), ("total_units_sold", "📦", "Units Sold", "#6ee7c7"), ("total_revenue", "💰", "Revenue", "#3dcba8"), ]
html = ( '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));' 'gap:12px;margin-bottom:24px;">' ) for key, icon, label, colour in kpi_config: val = kpis.get(key) if val is None: continue if isinstance(val, (int, float)) and val > 100: val = f"{val:,.0f}" html += card(icon, label, str(val), colour) # Extra KPIs not in config known = {k for k, *_ in kpi_config} for key, val in kpis.items(): if key not in known: label = key.replace("_", " ").title() if isinstance(val, (int, float)) and val > 100: val = f"{val:,.0f}" html += card("📈", label, str(val), "#8fa8f8") html += "</div>" return html
# =========================================================# INTERACTIVE PLOTLY CHARTS (BubbleBusters style)# =========================================================
CHART_PALETTE = ["#7c5cbf", "#2ec4a0", "#e8537a", "#e8a230", "#5e8fef", "#c45ea8", "#3dbacc", "#a0522d", "#6aaa3a", "#d46060"]
def _styled_layout(**kwargs) -> dict: defaults = dict( template="plotly_white", paper_bgcolor="rgba(255,255,255,0.95)", plot_bgcolor="rgba(255,255,255,0.98)", font=dict(family="system-ui, sans-serif", color="#2d1f4e", size=12), margin=dict(l=60, r=20, t=70, b=70), legend=dict( orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1, bgcolor="rgba(255,255,255,0.92)", bordercolor="rgba(124,92,191,0.35)", borderwidth=1, ), title=dict(font=dict(size=15, color="#4b2d8a")), ) defaults.update(kwargs) return defaults
def _empty_chart(title: str) -> go.Figure: fig = go.Figure() fig.update_layout( title=title, height=420, template="plotly_white", paper_bgcolor="rgba(255,255,255,0.95)", annotations=[dict(text="Run the pipeline to generate data", x=0.5, y=0.5, xref="paper", yref="paper", showarrow=False, font=dict(size=14, color="rgba(124,92,191,0.5)"))], ) return fig
def build_sales_chart() -> go.Figure: path = PY_TAB_DIR / "df_dashboard.csv" if not path.exists(): return _empty_chart("Sales Trends — run the pipeline first") df = pd.read_csv(path) date_col = next((c for c in df.columns if "month" in c.lower() or "date" in c.lower()), None) val_cols = [c for c in df.columns if c != date_col and df[c].dtype in ("float64", "int64")] if not date_col or not val_cols: return _empty_chart("Could not auto-detect columns in df_dashboard.csv") df[date_col] = pd.to_datetime(df[date_col], errors="coerce") fig = go.Figure() for i, col in enumerate(val_cols): fig.add_trace(go.Scatter( x=df[date_col], y=df[col], name=col.replace("_", " ").title(), mode="lines+markers", line=dict(color=CHART_PALETTE[i % len(CHART_PALETTE)], width=2), marker=dict(size=4), hovertemplate=f"<b>{col.replace('_',' ').title()}</b><br>%{{x|%b %Y}}: %{{y:,.0f}}<extra></extra>", )) fig.update_layout(**_styled_layout(height=450, hovermode="x unified", title=dict(text="Monthly Overview"))) fig.update_xaxes(gridcolor="rgba(124,92,191,0.15)", showgrid=True) fig.update_yaxes(gridcolor="rgba(124,92,191,0.15)", showgrid=True) return fig
def build_sentiment_chart() -> go.Figure: path = PY_TAB_DIR / "sentiment_counts_sampled.csv" if not path.exists(): return _empty_chart("Sentiment Distribution — run the pipeline first") df = pd.read_csv(path) title_col = df.columns[0] sent_cols = [c for c in ["negative", "neutral", "positive"] if c in df.columns] if not sent_cols: return _empty_chart("No sentiment columns found in CSV") colors = {"negative": "#e8537a", "neutral": "#5e8fef", "positive": "#2ec4a0"} fig = go.Figure() for col in sent_cols: fig.add_trace(go.Bar( name=col.title(), y=df[title_col], x=df[col], orientation="h", marker_color=colors.get(col, "#888"), hovertemplate=f"<b>{col.title()}</b>: %{{x}}<extra></extra>", )) fig.update_layout(**_styled_layout( height=max(400, len(df) * 28), barmode="stack", title=dict(text="Sentiment Distribution by Book"), )) fig.update_xaxes(title="Number of Reviews") fig.update_yaxes(autorange="reversed") return fig
def build_top_sellers_chart() -> go.Figure: path = PY_TAB_DIR / "top_titles_by_units_sold.csv" if not path.exists(): return _empty_chart("Top Sellers — run the pipeline first") df = pd.read_csv(path).head(15) title_col = next((c for c in df.columns if "title" in c.lower()), df.columns[0]) val_col = next((c for c in df.columns if "unit" in c.lower() or "sold" in c.lower()), df.columns[-1]) fig = go.Figure(go.Bar( y=df[title_col], x=df[val_col], orientation="h", marker=dict(color=df[val_col], colorscale=[[0, "#c5b4f0"], [1, "#7c5cbf"]]), hovertemplate="<b>%{y}</b><br>Units: %{x:,.0f}<extra></extra>", )) fig.update_layout(**_styled_layout( height=max(400, len(df) * 30), title=dict(text="Top Selling Titles"), showlegend=False, )) fig.update_yaxes(autorange="reversed") fig.update_xaxes(title="Total Units Sold") return fig
def refresh_dashboard(): return render_kpi_cards(), build_sales_chart(), build_sentiment_chart(), build_top_sellers_chart()
# =========================================================# UI# =========================================================
ensure_dirs()
def load_css() -> str: css_path = BASE_DIR / "style.css" return css_path.read_text(encoding="utf-8") if css_path.exists() else ""
with gr.Blocks(title="AIBDM 2026 Workshop App") as demo:
gr.Markdown( "# SE21 App Template\n" "*This is an app template for SE21 students*", elem_id="escp_title", )
# =========================================================== # TAB 1 -- Pipeline Runner # =========================================================== with gr.Tab("Pipeline Runner"): gr.Markdown()
with gr.Row(): with gr.Column(scale=1): btn_nb1 = gr.Button("Step 1: Data Creation", variant="secondary") with gr.Column(scale=1): btn_nb2 = gr.Button("Step 2: Python Analysis", variant="secondary")
with gr.Row(): btn_all = gr.Button("Run Full Pipeline (Both Steps)", variant="primary")
run_log = gr.Textbox( label="Execution Log", lines=18, max_lines=30, interactive=False, )
btn_nb1.click(run_datacreation, outputs=[run_log]) btn_nb2.click(run_pythonanalysis, outputs=[run_log]) btn_all.click(run_full_pipeline, outputs=[run_log])
# =========================================================== # TAB 2 -- Dashboard (KPIs + Interactive Charts + Gallery) # =========================================================== with gr.Tab("Dashboard"): kpi_html = gr.HTML(value=render_kpi_cards)
refresh_btn = gr.Button("Refresh Dashboard", variant="primary")
gr.Markdown("#### Interactive Charts") chart_sales = gr.Plot(label="Monthly Overview") chart_sentiment = gr.Plot(label="Sentiment Distribution") chart_top = gr.Plot(label="Top Sellers")
gr.Markdown("#### Static Figures (from notebooks)") gallery = gr.Gallery( label="Generated Figures", columns=2, height=480, object_fit="contain", )
gr.Markdown("#### Data Tables") table_dropdown = gr.Dropdown( label="Select a table to view", choices=[], interactive=True, ) table_display = gr.Dataframe( label="Table Preview", interactive=False, )
def _on_refresh(): kpi, c1, c2, c3 = refresh_dashboard() figs, dd, df = refresh_gallery() return kpi, c1, c2, c3, figs, dd, df
refresh_btn.click( _on_refresh, outputs=[kpi_html, chart_sales, chart_sentiment, chart_top, gallery, table_dropdown, table_display], ) table_dropdown.change( on_table_select, inputs=[table_dropdown], outputs=[table_display], )
# =========================================================== # TAB 3 -- AI Dashboard # =========================================================== with gr.Tab('"AI" Dashboard'): _ai_status = ( "Connected to your **n8n workflow**." if N8N_WEBHOOK_URL else "**LLM active.**" if LLM_ENABLED else "Using **keyword matching**. Upgrade options: " "set `N8N_WEBHOOK_URL` to connect your n8n workflow, " "or set `HF_API_KEY` for direct LLM access." ) gr.Markdown( "### Ask questions, get interactive visualisations\n\n" f"Type a question and the system will pick the right interactive chart or table. {_ai_status}" )
with gr.Row(equal_height=True): with gr.Column(scale=1): chatbot = gr.Chatbot( label="Conversation", height=380, ) user_input = gr.Textbox( label="Ask about your data", placeholder="e.g. Show me sales trends / What are the top sellers? / Sentiment analysis", lines=1, ) gr.Examples( examples=[ "Show me the sales trends", "What does the sentiment look like?", "Which titles sell the most?", "Show the ARIMA forecasts", "What are the pricing decisions?", "Give me a dashboard overview", ], inputs=user_input, )
with gr.Column(scale=1): ai_figure = gr.Plot( label="Interactive Chart", ) ai_table = gr.Dataframe( label="Data Table", interactive=False, )
user_input.submit( ai_chat, inputs=[user_input, chatbot], outputs=[chatbot, user_input, ai_figure, ai_table], )
demo.launch(css=load_css(), allowed_paths=[str(BASE_DIR)])123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textbackground_top.png filter=lfs diff=lfs merge=lfs -text1234567891011121314151617gradio==6.0.0pandas>=2.0.0numpy>=1.24.0matplotlib>=3.7.0seaborn>=0.13.0statsmodels>=0.14.0scikit-learn>=1.3.0papermill>=2.5.0nbformat>=5.9.0pillow>=10.0.0requests>=2.31.0beautifulsoup4>=4.12.0vaderSentiment>=3.3.2huggingface_hub>=0.20.0textblob>=0.18.0faker>=20.0.0plotly>=5.18.0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326/* --- Target the Gradio app wrapper for backgrounds --- */gradio-app,.gradio-app,.main,#app,[data-testid="app"] { background-color: rgb(40,9,109) !important; background-image: url('https://huggingface.co/spaces/atascioglu/SE21AppTemplate/resolve/main/background_top.png'), url('https://huggingface.co/spaces/atascioglu/SE21AppTemplate/resolve/main/background_mid.png'), url('https://huggingface.co/spaces/atascioglu/SE21AppTemplate/resolve/main/background_bottom.png') !important; background-position: top center, 0 913px, bottom center !important; background-repeat: no-repeat, repeat-y, no-repeat !important; background-size: 100% auto, 100% auto, 100% auto !important; min-height: 100vh !important;}
/* --- Fallback on html/body --- */html, body { background-color: rgb(40,9,109) !important; margin: 0 !important; padding: 0 !important; min-height: 100vh !important;}
/* Bottom image is now part of the main background layers (positioned at bottom center) */
/* --- Main container --- */.gradio-container { max-width: 1400px !important; width: 94vw !important; margin: 0 auto !important; padding-top: 220px !important; padding-bottom: 150px !important; background: transparent !important;}
/* --- Title in ESCP gold --- */#escp_title h1 { color: rgb(242,198,55) !important; font-size: 3rem !important; font-weight: 800 !important; text-align: center !important; margin: 0 0 12px 0 !important;}
/* --- Subtitle --- */#escp_title p, #escp_title em { color: rgba(255,255,255,0.85) !important; text-align: center !important;}
/* --- Tab bar background --- */.tabs > .tab-nav,.tab-nav,div[role="tablist"],.svelte-tabs > .tab-nav { background: rgba(40,9,109,0.6) !important; border-radius: 10px 10px 0 0 !important; padding: 4px !important;}
/* --- ALL tab buttons: force white text --- */.tabs > .tab-nav button,.tab-nav button,div[role="tablist"] button,button[role="tab"],.svelte-tabs button,.tab-nav > button,.tabs button { color: #ffffff !important; font-weight: 600 !important; border: none !important; background: transparent !important; padding: 10px 20px !important; border-radius: 8px 8px 0 0 !important; opacity: 1 !important;}
/* --- Selected tab: ESCP gold --- */.tabs > .tab-nav button.selected,.tab-nav button.selected,button[role="tab"][aria-selected="true"],button[role="tab"].selected,div[role="tablist"] button[aria-selected="true"],.svelte-tabs button.selected { color: rgb(242,198,55) !important; background: rgba(255,255,255,0.12) !important;}
/* --- Unselected tabs: ensure visibility --- */.tabs > .tab-nav button:not(.selected),.tab-nav button:not(.selected),button[role="tab"][aria-selected="false"],button[role="tab"]:not(.selected),div[role="tablist"] button:not([aria-selected="true"]) { color: #ffffff !important; opacity: 1 !important;}
/* --- White card panels --- */.gradio-container .gr-block,.gradio-container .gr-box,.gradio-container .gr-panel,.gradio-container .gr-group { background: #ffffff !important; border-radius: 10px !important;}
/* --- Tab content area --- */.tabitem { background: rgba(255,255,255,0.95) !important; border-radius: 0 0 10px 10px !important; padding: 16px !important;}
/* --- Inputs --- */.gradio-container input,.gradio-container textarea,.gradio-container select { background: #ffffff !important; border: 1px solid #d1d5db !important; border-radius: 8px !important;}
/* --- Buttons: ESCP purple primary --- */.gradio-container button:not([role="tab"]) { font-weight: 600 !important; padding: 10px 16px !important; border-radius: 10px !important;}
button.primary { background-color: rgb(40,9,109) !important; color: #ffffff !important; border: none !important;}
button.primary:hover { background-color: rgb(60,20,140) !important;}
button.secondary { background-color: #ffffff !important; color: rgb(40,9,109) !important; border: 2px solid rgb(40,9,109) !important;}
button.secondary:hover { background-color: rgb(240,238,250) !important;}
/* --- Dataframes --- */[data-testid="dataframe"] { background-color: #ffffff !important; border-radius: 10px !important;}
table { font-size: 0.85rem !important;}
/* --- Chatbot (AI Dashboard tab) --- */.gr-chatbot { min-height: 380px !important; background-color: #ffffff !important; border-radius: 12px !important;}
.gr-chatbot .message.user { background-color: rgb(232,225,250) !important; border-radius: 12px !important;}
.gr-chatbot .message.bot { background-color: #f3f4f6 !important; border-radius: 12px !important;}
/* --- Gallery --- */.gallery { background: #ffffff !important; border-radius: 10px !important;}
/* --- Log textbox --- */textarea { font-family: monospace !important; font-size: 0.8rem !important;}
/* --- Markdown headings inside tabs --- */.tabitem h3 { color: rgb(40,9,109) !important; font-weight: 700 !important;}
.tabitem h4 { color: #374151 !important;}
/* --- Examples row (AI Dashboard) --- */.examples-row button { background: rgb(240,238,250) !important; color: rgb(40,9,109) !important; border: 1px solid rgb(40,9,109) !important; border-radius: 8px !important; font-size: 0.85rem !important;}
.examples-row button:hover { background: rgb(232,225,250) !important;}
/* --- Header / footer: transparent over banner --- */header, header *,footer, footer * { background: transparent !important; box-shadow: none !important;}
footer a, footer button,header a, header button { background: transparent !important; border: none !important; box-shadow: none !important;}
#footer, #footer *,[class*="footer"], [class*="footer"] *,[class*="chip"], [class*="pill"], [class*="chip"] *, [class*="pill"] * { background: transparent !important; border: none !important; box-shadow: none !important;}
[data-testid*="api"], [data-testid*="settings"],[id*="api"], [id*="settings"],[class*="api"], [class*="settings"],[class*="bottom"], [class*="toolbar"], [class*="controls"] { background: transparent !important; box-shadow: none !important;}
[data-testid*="api"] *, [data-testid*="settings"] *,[id*="api"] *, [id*="settings"] *,[class*="api"] *, [class*="settings"] * { background: transparent !important; box-shadow: none !important;}
section footer { background: transparent !important;}
section footer button,section footer a { background: transparent !important; background-color: transparent !important; border: none !important; box-shadow: none !important; color: white !important;}
section footer button:hover,section footer button:focus,section footer a:hover,section footer a:focus { background: transparent !important; background-color: transparent !important; box-shadow: none !important;}
section footer button,section footer button * { background: transparent !important; background-color: transparent !important; background-image: none !important; box-shadow: none !important; filter: none !important;}
section footer button::before,section footer button::after { background: transparent !important; background-color: transparent !important; background-image: none !important; box-shadow: none !important; filter: none !important;}
section footer a,section footer a * { background: transparent !important; background-color: transparent !important; box-shadow: none !important;}
.gradio-container footer button,.gradio-container footer button *,.gradio-container .footer button,.gradio-container .footer button * { background: transparent !important; background-color: transparent !important; background-image: none !important; box-shadow: none !important;}
.gradio-container footer button::before,.gradio-container footer button::after,.gradio-container .footer button::before,.gradio-container .footer button::after { background: transparent !important; background-color: transparent !important; background-image: none !important; box-shadow: none !important;}.gitattributes+1
DockerfileAdded+26
README.md+3-2
app.pyAdded+758
background_bottom.pngAdded

background_mid.pngAdded

background_top.pngAdded

Large File Pointer Details
- SHA256: 27e963d20dbb7ae88368fb527d475c85ef0de3df63d8f0d7d5e2af7403a5b365
- Pointer size: 131 Bytes
- Size of remote file: 726 kB
gitattributes.txtAdded+36
requirements.txtAdded+17
style.cssAdded+326