Corin1998 commited on
Commit
0735cb3
·
verified ·
1 Parent(s): ab532a1

Update dashboard.py

Browse files
Files changed (1) hide show
  1. dashboard.py +6 -11
dashboard.py CHANGED
@@ -1,5 +1,4 @@
1
  from __future__ import annotations
2
- import pandas as pd
3
  import gradio as gr
4
  import plotly.express as px
5
  from data import read_events, aggregate
@@ -16,9 +15,8 @@ def ui_refresh_tables():
16
  def ui_recommend():
17
  agg = aggregate()
18
  if agg.empty:
19
- return {"message": "No data yet. Upload or POST /api/ingest first."}
20
- rec = BANDIT.recommend(agg)
21
- return rec
22
 
23
  def ui_plot_posteriors(medium: str):
24
  agg = aggregate()
@@ -27,18 +25,16 @@ def ui_plot_posteriors(medium: str):
27
  g = agg[agg["medium"].astype(str) == str(medium)].copy()
28
  if g.empty:
29
  return gr.update(visible=False), f"No data for medium={medium}"
30
-
31
- # 事後平均の棒グラフ(Laplace 平滑 CTR)
32
  g["ctr"] = (g["clicks"] + 1) / (g["impressions"] + 2)
33
- fig = px.bar(g, x="creative", y="ctr", color="is_control", barmode="group", title=f"CTR (Laplace) by creative @ {medium}")
 
34
  return gr.Plot(fig), ""
35
 
36
  def ui_fit_uplift():
37
  agg = aggregate()
38
  if agg.empty:
39
  return {"message": "No data"}
40
- res = fit_uplift_binary(agg)
41
- return res
42
 
43
  def build_ui():
44
  with gr.Blocks(title="AdCopy MAB Optimizer Pro") as demo:
@@ -56,8 +52,7 @@ def build_ui():
56
  medium = gr.Textbox(label="Medium for Plot", value="FB")
57
  plot = gr.Plot(visible=False)
58
  msg = gr.Markdown()
59
- plot_btn = gr.Button("Plot CTR by Creative")
60
- plot_btn.click(ui_plot_posteriors, inputs=[medium], outputs=[plot, msg])
61
  with gr.Tab("Uplift (Causal)"):
62
  cbtn = gr.Button("Fit Uplift Model")
63
  cout = gr.JSON()
 
1
  from __future__ import annotations
 
2
  import gradio as gr
3
  import plotly.express as px
4
  from data import read_events, aggregate
 
15
  def ui_recommend():
16
  agg = aggregate()
17
  if agg.empty:
18
+ return {"message": "No data yet. POST /api/ingest first."}
19
+ return BANDIT.recommend(agg)
 
20
 
21
  def ui_plot_posteriors(medium: str):
22
  agg = aggregate()
 
25
  g = agg[agg["medium"].astype(str) == str(medium)].copy()
26
  if g.empty:
27
  return gr.update(visible=False), f"No data for medium={medium}"
 
 
28
  g["ctr"] = (g["clicks"] + 1) / (g["impressions"] + 2)
29
+ fig = px.bar(g, x="creative", y="ctr", color="is_control", barmode="group",
30
+ title=f"CTR (Laplace) by creative @ {medium}")
31
  return gr.Plot(fig), ""
32
 
33
  def ui_fit_uplift():
34
  agg = aggregate()
35
  if agg.empty:
36
  return {"message": "No data"}
37
+ return fit_uplift_binary(agg)
 
38
 
39
  def build_ui():
40
  with gr.Blocks(title="AdCopy MAB Optimizer Pro") as demo:
 
52
  medium = gr.Textbox(label="Medium for Plot", value="FB")
53
  plot = gr.Plot(visible=False)
54
  msg = gr.Markdown()
55
+ gr.Button("Plot CTR by Creative").click(ui_plot_posteriors, inputs=[medium], outputs=[plot, msg])
 
56
  with gr.Tab("Uplift (Causal)"):
57
  cbtn = gr.Button("Fit Uplift Model")
58
  cout = gr.JSON()