Spaces:
Runtime error
Runtime error
Update dashboard.py
Browse files- dashboard.py +31 -9
dashboard.py
CHANGED
@@ -1,18 +1,40 @@
|
|
1 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
2 |
import io
|
3 |
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
fig, ax = plt.subplots()
|
11 |
-
ax.bar(
|
12 |
-
ax.
|
|
|
13 |
|
|
|
14 |
buf = io.BytesIO()
|
15 |
-
plt.savefig(buf, format=
|
16 |
buf.seek(0)
|
17 |
-
|
18 |
-
return
|
|
|
1 |
import matplotlib.pyplot as plt
|
2 |
+
import firebase_admin
|
3 |
+
from firebase_admin import credentials, firestore
|
4 |
+
import gradio as gr
|
5 |
import io
|
6 |
from PIL import Image
|
7 |
|
8 |
+
# Initialize Firebase if not already initialized
|
9 |
+
if not firebase_admin._apps:
|
10 |
+
cred = credentials.Certificate("firebase_key.json")
|
11 |
+
firebase_admin.initialize_app(cred)
|
12 |
|
13 |
+
db = firestore.client()
|
14 |
+
|
15 |
+
def update_dashboard_plot():
|
16 |
+
logs_ref = db.collection("evo_feedback")
|
17 |
+
docs = logs_ref.stream()
|
18 |
+
|
19 |
+
count_1 = 0
|
20 |
+
count_2 = 0
|
21 |
+
for doc in docs:
|
22 |
+
data = doc.to_dict()
|
23 |
+
winner = data.get("winner", "")
|
24 |
+
if winner == "1":
|
25 |
+
count_1 += 1
|
26 |
+
elif winner == "2":
|
27 |
+
count_2 += 1
|
28 |
+
|
29 |
+
# Generate a bar chart
|
30 |
fig, ax = plt.subplots()
|
31 |
+
ax.bar(["Solution 1", "Solution 2"], [count_1, count_2], color=["blue", "green"])
|
32 |
+
ax.set_ylabel("Votes")
|
33 |
+
ax.set_title("EvoTransformer Feedback Summary")
|
34 |
|
35 |
+
# Convert matplotlib figure to PIL Image
|
36 |
buf = io.BytesIO()
|
37 |
+
plt.savefig(buf, format="png")
|
38 |
buf.seek(0)
|
39 |
+
img = Image.open(buf)
|
40 |
+
return img
|