File size: 4,236 Bytes
ee1b999
 
5ef407f
 
 
 
ee1b999
5ef407f
ee1b999
5ef407f
ee1b999
5ef407f
 
 
 
 
 
ee1b999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ef407f
ee1b999
5ef407f
ee1b999
 
 
 
 
 
 
 
 
 
 
 
 
5ef407f
ee1b999
 
5ef407f
ee1b999
 
 
 
5ef407f
 
ee1b999
 
5ef407f
ee1b999
 
 
5ef407f
ee1b999
 
 
 
5ef407f
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
# app.py
import gradio as gr
import os

from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import HfApi
import literature_understanding, main_page, c_and_e, data_analysis, e2e

from content import TITLE, css

# --- Constants and Configuration  ---
LOCAL_DEBUG = not (os.environ.get("system") == "spaces")
IS_INTERNAL = os.environ.get("IS_INTERNAL", "false").lower() == "true"
OWNER = "allenai"
PROJECT_NAME = "asta-bench" + ("-internal" if IS_INTERNAL else "")
LEADERBOARD_PATH = f"{OWNER}/{PROJECT_NAME}-leaderboard"
api = HfApi()
LOGO_PATH = "Ai2_logo_pink_padding_RGB.png"



# --- Theme Definition ---
theme = gr.themes.Base(
    primary_hue=gr.themes.Color(c100="#CFF5E8", c200="#B7EFDD", c300="#9FEAD1", c400="#87E5C5", c50="#E7FAF3", c500="#6FE0BA", c600="#57DBAF", c700="#3FD5A3", c800="#27D09C", c900="#0FCB8C", c950="#0fcb8c"),
    secondary_hue=gr.themes.Color(c100="#FCDCEB", c200="#FBCBE1", c300="#F9BAD7", c400="#F7A8CD", c50="#FDEEF5", c500="#F697C4", c600="#F586BA", c700="#F375B0", c800="#F263A6", c900="#F0529C", c950="#F0529C"),
    neutral_hue=gr.themes.Color(c100="#FDF9F4", c200="#C9C9C3", c300="#B0B5AF", c400="#97A09C", c50="#FAF2E9", c500="#7F8C89", c600="#667876", c700="#344F4F", c800="#1C3A3C", c900="#032629", c950="032629"),
    font=[gr.themes.GoogleFont('Manrope'), 'ui-sans-serif', 'sans-serif', 'sans-serif'],
    font_mono=[gr.themes.GoogleFont('Roboto Mono'), 'ui-monospace', 'monospace', 'monospace'],
).set(
    body_text_color='*neutral_950',
    body_text_color_dark='*neutral_50',
    background_fill_primary='*neutral_50',
    background_fill_primary_dark='*neutral_900',
    background_fill_secondary='*neutral_100',
    background_fill_secondary_dark='*neutral_800',
    border_color_accent='*secondary_900',
    border_color_accent_subdued='*neutral_400',
    border_color_accent_subdued_dark='*neutral_400',
    color_accent='*primary_900',
    color_accent_soft='*neutral_200',
    color_accent_soft_dark='*neutral_800',
    link_text_color='*secondary_900',
    link_text_color_dark='*primary_900',
    link_text_color_active_dark='*primary_600',
    link_text_color_hover_dark='*primary_700',
    link_text_color_visited_dark='*primary_600',
    table_even_background_fill='*neutral_100',
    table_even_background_fill_dark='*neutral_800',
    button_primary_background_fill='*secondary_900',
    button_primary_background_fill_dark='*primary_900',
    button_primary_background_fill_hover='*secondary_600',
    button_primary_background_fill_hover_dark='*primary_600',
    button_primary_text_color='*neutral_900',
    button_primary_text_color_dark='*neutral_900'
)
# --- Gradio App Definition ---
demo = gr.Blocks(theme=theme, css=css)
with demo:
    gr.Image(
        value=LOGO_PATH,
        show_label=False,
        interactive=False,
        container=False,
        show_download_button=False,
        show_fullscreen_button=False,
        elem_id="logo-image"
    )
    gr.HTML(TITLE)

    main_page.demo.render()
with demo.route("Literature Understanding"):
    literature_understanding.demo.render()
with demo.route("Code & Execution"):
    c_and_e.demo.render()
with demo.route("Data Analysis"):
    data_analysis.demo.render()
with demo.route("Discovery"):
    e2e.demo.render()

# --- Scheduler and Launch
def restart_space_job():
    print("Scheduler: Attempting to restart space.")
    try:
        api.restart_space(repo_id=LEADERBOARD_PATH)
        print("Scheduler: Space restart request sent.")
    except Exception as e:
        print(f"Scheduler: Error restarting space: {e}")
    scheduler = BackgroundScheduler(timezone="UTC")
    scheduler.add_job(restart_space_job, "interval", hours=1)
    scheduler.start()


# Launch the Gradio app
if __name__ == "__main__":
    if LOCAL_DEBUG:
        print("Launching in LOCAL_DEBUG mode.")
        def get_initial_global_tag_choices(): return ["Overall", "TagA"]
        demo.launch(debug=True)
    else:
        print("Launching in Space mode.")
        # For Spaces, share=False is typical unless specific tunneling is needed.
        # debug=True can be set to False for a "production" Space.
        demo.launch(server_name="0.0.0.0", server_port=7860, debug=True, share=False)