Spaces:
Runtime error
Runtime error
File size: 2,081 Bytes
dfe0ad3 2ffd2c7 dfe0ad3 3a2ee1d 112a2a9 2ffd2c7 6ea260a 2ffd2c7 3a2ee1d 2ffd2c7 dfe0ad3 2ffd2c7 dfe0ad3 2ffd2c7 dfe0ad3 2ffd2c7 dfe0ad3 2ffd2c7 3a2ee1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import matplotlib.pyplot as plt
import firebase_admin
from firebase_admin import credentials, firestore
import gradio as gr
import io
from PIL import Image
import os
import json
# Initialize Firebase if not already initialized
if not firebase_admin._apps:
cred = credentials.Certificate("firebase_key.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
# β
This stays as-is: Firebase Feedback Summary
def update_dashboard_plot():
logs_ref = db.collection("evo_feedback")
docs = logs_ref.stream()
count_1 = 0
count_2 = 0
for doc in docs:
data = doc.to_dict()
winner = data.get("winner", "")
if winner == "1":
count_1 += 1
elif winner == "2":
count_2 += 1
# Generate a bar chart
fig, ax = plt.subplots()
ax.bar(["Solution 1", "Solution 2"], [count_1, count_2], color=["blue", "green"])
ax.set_ylabel("Votes")
ax.set_title("EvoTransformer Feedback Summary")
# Convert matplotlib figure to PIL Image
buf = io.BytesIO()
plt.savefig(buf, format="png")
buf.seek(0)
img = Image.open(buf)
return img
# β
NEW: Accuracy Plot from Local Log
def evolution_accuracy_plot():
try:
log_path = "trained_model/evolution_log.json"
if not os.path.exists(log_path):
fig, ax = plt.subplots()
ax.text(0.5, 0.5, "No evolution log found", ha="center", va="center")
return fig
with open(log_path, "r") as f:
log_data = json.load(f)
generations = list(range(1, len(log_data) + 1))
accuracies = [entry.get("accuracy", 0) for entry in log_data]
fig, ax = plt.subplots()
ax.plot(generations, accuracies, marker="o", linestyle="-")
ax.set_xlabel("Generation")
ax.set_ylabel("Accuracy")
ax.set_title("EvoTransformer Evolution Accuracy")
ax.grid(True)
return fig
except Exception as e:
fig, ax = plt.subplots()
ax.text(0.5, 0.5, f"Error loading plot: {e}", ha="center")
return fig
|