File size: 1,070 Bytes
dfe0ad3
2ffd2c7
 
 
dfe0ad3
 
112a2a9
2ffd2c7
 
 
 
6ea260a
2ffd2c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfe0ad3
2ffd2c7
 
 
dfe0ad3
2ffd2c7
dfe0ad3
2ffd2c7
dfe0ad3
2ffd2c7
 
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
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