HemanM commited on
Commit
112a2a9
Β·
verified Β·
1 Parent(s): 6c2267b

Create dashboard.py

Browse files
Files changed (1) hide show
  1. dashboard.py +74 -0
dashboard.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # dashboard.py
2
+
3
+ import firebase_admin
4
+ from firebase_admin import credentials, firestore
5
+ import pandas as pd
6
+ import matplotlib.pyplot as plt
7
+ import io
8
+ import gradio as gr
9
+
10
+ # Initialize Firebase Admin SDK (ensure the JSON file is in your space)
11
+ if not firebase_admin._apps:
12
+ cred = credentials.Certificate("evotransformer-firebase-adminsdk-fbsvc-37a4b838aa.json")
13
+ firebase_admin.initialize_app(cred)
14
+
15
+ db = firestore.client()
16
+
17
+ def fetch_logs():
18
+ docs = db.collection("evo_feedback_logs").stream()
19
+ data = []
20
+ for doc in docs:
21
+ d = doc.to_dict()
22
+ if all(k in d for k in ["goal", "evo", "gpt", "correct"]):
23
+ data.append(d)
24
+ return pd.DataFrame(data)
25
+
26
+ def generate_dashboard():
27
+ df = fetch_logs()
28
+ if df.empty:
29
+ return "No data yet.", None
30
+
31
+ df["evo_correct"] = df["evo"] == df["correct"]
32
+ df["gpt_correct"] = df["gpt"] == df["correct"]
33
+
34
+ evo_acc = df["evo_correct"].mean()
35
+ gpt_acc = df["gpt_correct"].mean()
36
+ agreement = (df["evo"] == df["gpt"]).mean()
37
+
38
+ fig, ax = plt.subplots(figsize=(6, 4))
39
+ counts = [
40
+ df["evo_correct"].sum(),
41
+ df["evo_correct"].count() - df["evo_correct"].sum(),
42
+ df["gpt_correct"].sum(),
43
+ df["gpt_correct"].count() - df["gpt_correct"].sum()
44
+ ]
45
+ bars = ax.bar(["Evo Correct", "Evo Wrong", "GPT Correct", "GPT Wrong"], counts)
46
+ ax.set_title("Model Accuracy Summary")
47
+ ax.set_ylabel("Count")
48
+
49
+ buf = io.BytesIO()
50
+ plt.tight_layout()
51
+ plt.savefig(buf, format="png")
52
+ plt.close(fig)
53
+ buf.seek(0)
54
+
55
+ summary = (
56
+ f"🧠 Evo Accuracy: {evo_acc:.2%}\n"
57
+ f"πŸ€– GPT-3.5 Accuracy: {gpt_acc:.2%}\n"
58
+ f"βš–οΈ Agreement Rate: {agreement:.2%}\n"
59
+ f"πŸ“ Total Examples Logged: {len(df)}"
60
+ )
61
+
62
+ return summary, buf
63
+
64
+ with gr.Blocks() as dashboard:
65
+ gr.Markdown("## πŸ“Š EvoTransformer Live Evolution Dashboard")
66
+ gr.Markdown("> πŸ”„ *Below metrics are based on real-time user feedback.*")
67
+
68
+ summary_text = gr.Textbox(label="Summary", interactive=False)
69
+ plot = gr.Image(type="pil", label="Accuracy Plot")
70
+
71
+ refresh = gr.Button("πŸ” Refresh Data")
72
+ refresh.click(fn=generate_dashboard, outputs=[summary_text, plot])
73
+
74
+ dashboard.launch()