File size: 6,952 Bytes
e83d737
 
 
d786867
 
e83d737
 
 
d786867
 
e83d737
 
 
 
 
d786867
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import matplotlib.pyplot as plt
import matplotlib
import pandas as pd
import gradio as gr

from data import CIResults
from utils import logger
from summary_page import create_summary_page


# 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


# Load data once at startup
Ci_results = CIResults()
Ci_results.load_data()
# Start the auto-reload scheduler
Ci_results.schedule_data_reload()


# Function to get current description text
def get_description_text():
    """Get description text with integrated last update time."""
    msg = [
        "Transformer CI Dashboard",
        "-",
        "AMD runs on MI325",
        "NVIDIA runs on A10",
    ]
    msg = ["**" + x + "**" for x in msg] + [""]
    if Ci_results.latest_update_msg:
        msg.append(f"*This dashboard only tracks important models*<br>*({Ci_results.latest_update_msg})*")
    else:
        msg.append("*This dashboard only tracks important models*<br>*(loading...)*")
    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"]
            )

            # CI job links at bottom of sidebar
            ci_links_display = gr.Markdown("🔗 **CI Jobs:** *Loading...*", elem_classes=["sidebar-links"])

        # Main content area
        with gr.Column(scale=4, elem_classes=["main-content"]):
            # Summary display (default view)
            summary_display = gr.ScatterPlot(
                pd.DataFrame({
                    "x": [i for i in range(10)] + [100, -100],
                    "y": [i ** 2 for i in range(10)] + [100, -100],
                }),
                x = "x",
                y = "y",
                height="100vh",
                container=False,
                show_fullscreen_button=True,
                elem_classes=["plot-container"],
            )



    # Summary button click handler
    def show_summary_and_update_links():
        """Show summary page and update CI links."""
        return create_summary_page(Ci_results.df, Ci_results.available_models), get_description_text(), get_ci_links()

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

    # Function to get CI job links
    def get_ci_links():
        """Get CI job links from the most recent data."""
        try:
            # Check if df exists and is not empty
            if Ci_results.df is None or Ci_results.df.empty:
                return "🔗 **CI Jobs:** *Loading...*"

            # Get links from any available model (they should be the same for all models in a run)
            amd_multi_link = None
            amd_single_link = None
            nvidia_multi_link = None
            nvidia_single_link = None

            for model_name in Ci_results.df.index:
                row = Ci_results.df.loc[model_name]

                # Extract AMD links
                if pd.notna(row.get('job_link_amd')) and (not amd_multi_link or not amd_single_link):
                    amd_link_raw = row.get('job_link_amd')
                    if isinstance(amd_link_raw, dict):
                        if 'multi' in amd_link_raw and not amd_multi_link:
                            amd_multi_link = amd_link_raw['multi']
                        if 'single' in amd_link_raw and not amd_single_link:
                            amd_single_link = amd_link_raw['single']

                # Extract NVIDIA links
                if pd.notna(row.get('job_link_nvidia')) and (not nvidia_multi_link or not nvidia_single_link):
                    nvidia_link_raw = row.get('job_link_nvidia')
                    if isinstance(nvidia_link_raw, dict):
                        if 'multi' in nvidia_link_raw and not nvidia_multi_link:
                            nvidia_multi_link = nvidia_link_raw['multi']
                        if 'single' in nvidia_link_raw and not nvidia_single_link:
                            nvidia_single_link = nvidia_link_raw['single']

                # Break if we have all links
                if amd_multi_link and amd_single_link and nvidia_multi_link and nvidia_single_link:
                    break


            # Add FAQ link at the bottom
            links_md = "❓ [**FAQ**](https://huggingface.co/spaces/transformers-community/transformers-ci-dashboard/blob/main/README.md)\n\n"
            links_md += "🔗 **CI Jobs:**\n\n"

            # AMD links
            if amd_multi_link or amd_single_link:
                links_md += "**AMD:**\n"
                if amd_multi_link:
                    links_md += f"• [Multi GPU]({amd_multi_link})\n"
                if amd_single_link:
                    links_md += f"• [Single GPU]({amd_single_link})\n"
                links_md += "\n"

            # NVIDIA links
            if nvidia_multi_link or nvidia_single_link:
                links_md += "**NVIDIA:**\n"
                if nvidia_multi_link:
                    links_md += f"• [Multi GPU]({nvidia_multi_link})\n"
                if nvidia_single_link:
                    links_md += f"• [Single GPU]({nvidia_single_link})\n"

            if not (amd_multi_link or amd_single_link or nvidia_multi_link or nvidia_single_link):
                links_md += "*No links available*"

            return links_md
        except Exception as e:
            logger.error(f"getting CI links: {e}")
            return "🔗 **CI Jobs:** *Error loading links*\n\n❓ **[FAQ](README.md)**"


    # Auto-update CI links when the interface loads
    demo.load(
        fn=get_ci_links,
        outputs=[ci_links_display]
    )


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