File size: 3,328 Bytes
e83d737
 
 
d786867
66b7161
d786867
e83d737
d786867
 
e83d737
 
 
 
 
d786867
e83d737
66b7161
 
 
 
 
 
 
e83d737
 
 
 
66b7161
e83d737
66b7161
e83d737
66b7161
 
e83d737
 
66b7161
e83d737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29b7ec1
e83d737
 
66b7161
e83d737
 
 
 
 
 
 
 
 
 
 
66b7161
 
 
 
e83d737
 
66b7161
 
e83d737
 
66b7161
e83d737
66b7161
 
e83d737
 
 
 
d786867
e83d737
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
import gradio as gr
import random

from utils import logger


# Configure matplotlib to prevent memory warnings and set dark background
matplotlib.rcParams['figure.facecolor'] = '#000000'
matplotlib.rcParams['axes.facecolor'] = '#000000'
matplotlib.rcParams['savefig.facecolor'] = '#000000'
plt.ioff()  # Turn off interactive mode to prevent figure accumulation


# Function to generate random data for the plot
def generate_random_data():
    """Generate random data points for the scatter plot."""
    n_points = random.randint(20, 50)  # Random number of points
    x_data = [random.uniform(-100, 100) for _ in range(n_points)]
    y_data = [random.uniform(-100, 100) for _ in range(n_points)]
    return pd.DataFrame({"x": x_data, "y": y_data})


# Function to get current description text
def get_description_text():
    """Get description text."""
    msg = [
        "Random Data Dashboard",
        "-",
        "Click summary to refresh data",
        "Demo visualization",
    ]
    msg = ["**" + x + "**" for x in msg] + [""]
    msg.append("*Random scatter plot data*<br>*Updated on each click*")
    return "<br>".join(msg)

# Load CSS from external file
def load_css():
    try:
        with open("styles.css", "r") as f:
            css_content = f.read()
        
        return css_content
    except FileNotFoundError:
        logger.warning("styles.css not found, using minimal default styles")
        return "body { background: #000; color: #fff; }"


# Create the Gradio interface with sidebar and dark theme
with gr.Blocks(title="Model Test Results Dashboard", css=load_css(), fill_height=True, fill_width=True) as demo:


    with gr.Row():
        # Sidebar for model selection
        with gr.Column(scale=1, elem_classes=["sidebar"]):
            gr.Markdown("# 🤖 TCID", elem_classes=["sidebar-title"])

            # Description with integrated last update time
            description_text = get_description_text()
            description_display = gr.Markdown(description_text, elem_classes=["sidebar-description"])

            # Summary button
            summary_button = gr.Button(
                "summary\n📊",
                variant="primary",
                size="lg",
                elem_classes=["summary-button"]
            )


        # Main content area
        with gr.Column(elem_classes=["main-content"]):
            # Summary display (default view)
            summary_display = gr.ScatterPlot(
                generate_random_data(),
                x = "x",
                y = "y",
                height="100vh",
                container=False,
                show_fullscreen_button=True,
                elem_classes=["plot-container"],
            )



    # Summary button click handler
    def refresh_plot_data():
        """Generate new random data for the plot."""
        new_data = generate_random_data()
        return new_data, get_description_text()

    summary_button.click(
        fn=refresh_plot_data,
        outputs=[summary_display, description_display]
    )

    # Auto-update description when the interface loads
    demo.load(
        fn=get_description_text,
        outputs=[description_display]
    )


# Gradio entrypoint
if __name__ == "__main__":
    demo.launch()