File size: 2,837 Bytes
551c68e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""The Runs page for the Trackio UI."""

import gradio as gr

try:
    import trackio.utils as utils
    from trackio.sqlite_storage import SQLiteStorage
    from trackio.ui import fns
except ImportError:
    import utils
    from sqlite_storage import SQLiteStorage
    from ui import fns

RUN_DETAILS_TEMPLATE = """
## Run Details
* **Run Name:** `{run_name}`
* **Created:** {created} by {username}
"""

with gr.Blocks() as run_detail_page:
    with gr.Sidebar() as sidebar:
        logo = gr.Markdown(
            f"""
                <img src='/gradio_api/file={utils.TRACKIO_LOGO_DIR}/trackio_logo_type_light_transparent.png' width='80%' class='logo-light'>
                <img src='/gradio_api/file={utils.TRACKIO_LOGO_DIR}/trackio_logo_type_dark_transparent.png' width='80%' class='logo-dark'>            
            """
        )
        project_dd = gr.Dropdown(
            label="Project", allow_custom_value=True, interactive=False
        )
        run_dd = gr.Dropdown(label="Run")

    navbar = gr.Navbar(value=[("Metrics", ""), ("Runs", "/runs")], main_page_name=False)

    run_details = gr.Markdown(RUN_DETAILS_TEMPLATE)

    run_config = gr.JSON(label="Run Config")

    def configure(request: gr.Request):
        project = request.query_params.get("selected_project")
        run = request.query_params.get("selected_run")
        runs = SQLiteStorage.get_runs(project)
        return project, gr.Dropdown(choices=runs, value=run)

    def update_run_details(project, run):
        config = SQLiteStorage.get_run_config(project, run)
        if not config:
            return gr.Markdown("No run details available"), {}

        created = config.get("_Created", "Unknown")
        if created != "Unknown":
            created = utils.format_timestamp(created)

        username = config.get("_Username", "Unknown")
        if username and username != "None" and username != "Unknown":
            username = f"[{username}](https://huggingface.co/{username})"

        details_md = RUN_DETAILS_TEMPLATE.format(
            run_name=run, created=created, username=username
        )

        config_display = {k: v for k, v in config.items() if not k.startswith("_")}

        return gr.Markdown(details_md), config_display

    gr.on(
        [run_detail_page.load],
        fn=configure,
        outputs=[project_dd, run_dd],
        show_progress="hidden",
        queue=False,
        api_name=False,
    ).then(
        fns.update_navbar_value,
        inputs=[project_dd],
        outputs=[navbar],
        show_progress="hidden",
        api_name=False,
        queue=False,
    )

    gr.on(
        [run_dd.change],
        update_run_details,
        inputs=[project_dd, run_dd],
        outputs=[run_details, run_config],
        show_progress="hidden",
        api_name=False,
        queue=False,
    )