HemanM commited on
Commit
2ffd2c7
Β·
verified Β·
1 Parent(s): 40911df

Update dashboard.py

Browse files
Files changed (1) hide show
  1. 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
- def update_dashboard_plot(log_data):
6
- # Sample data visualization
7
- labels = ["Solution 1", "Solution 2"]
8
- values = [log_data.count("1"), log_data.count("2")]
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  fig, ax = plt.subplots()
11
- ax.bar(labels, values)
12
- ax.set_title("Feedback Summary")
 
13
 
 
14
  buf = io.BytesIO()
15
- plt.savefig(buf, format='png')
16
  buf.seek(0)
17
- plt.close(fig)
18
- return Image.open(buf)
 
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