Spaces:
Running
Running
import matplotlib.pyplot as plt | |
import firebase_admin | |
from firebase_admin import credentials, firestore | |
import gradio as gr | |
import io | |
from PIL import Image | |
# 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() | |
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 | |