Spaces:
Running
Running
# dashboard.py | |
import firebase_admin | |
from firebase_admin import credentials, firestore | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import io | |
import gradio as gr | |
# Initialize Firebase Admin SDK (ensure the JSON file is in your space) | |
if not firebase_admin._apps: | |
cred = credentials.Certificate("evotransformer-firebase-adminsdk-fbsvc-37a4b838aa.json") | |
firebase_admin.initialize_app(cred) | |
db = firestore.client() | |
def fetch_logs(): | |
docs = db.collection("evo_feedback_logs").stream() | |
data = [] | |
for doc in docs: | |
d = doc.to_dict() | |
if all(k in d for k in ["goal", "evo", "gpt", "correct"]): | |
data.append(d) | |
return pd.DataFrame(data) | |
def generate_dashboard(): | |
df = fetch_logs() | |
if df.empty: | |
return "No data yet.", None | |
df["evo_correct"] = df["evo"] == df["correct"] | |
df["gpt_correct"] = df["gpt"] == df["correct"] | |
evo_acc = df["evo_correct"].mean() | |
gpt_acc = df["gpt_correct"].mean() | |
agreement = (df["evo"] == df["gpt"]).mean() | |
fig, ax = plt.subplots(figsize=(6, 4)) | |
counts = [ | |
df["evo_correct"].sum(), | |
df["evo_correct"].count() - df["evo_correct"].sum(), | |
df["gpt_correct"].sum(), | |
df["gpt_correct"].count() - df["gpt_correct"].sum() | |
] | |
bars = ax.bar(["Evo Correct", "Evo Wrong", "GPT Correct", "GPT Wrong"], counts) | |
ax.set_title("Model Accuracy Summary") | |
ax.set_ylabel("Count") | |
buf = io.BytesIO() | |
plt.tight_layout() | |
plt.savefig(buf, format="png") | |
plt.close(fig) | |
buf.seek(0) | |
summary = ( | |
f"π§ Evo Accuracy: {evo_acc:.2%}\n" | |
f"π€ GPT-3.5 Accuracy: {gpt_acc:.2%}\n" | |
f"βοΈ Agreement Rate: {agreement:.2%}\n" | |
f"π Total Examples Logged: {len(df)}" | |
) | |
return summary, buf | |
with gr.Blocks() as dashboard: | |
gr.Markdown("## π EvoTransformer Live Evolution Dashboard") | |
gr.Markdown("> π *Below metrics are based on real-time user feedback.*") | |
summary_text = gr.Textbox(label="Summary", interactive=False) | |
plot = gr.Image(type="pil", label="Accuracy Plot") | |
refresh = gr.Button("π Refresh Data") | |
refresh.click(fn=generate_dashboard, outputs=[summary_text, plot]) | |
dashboard.launch() | |