Spaces:
Running
Running
Commit
·
92b542d
1
Parent(s):
8e943a0
Update offline warning
Browse files- src/model_demo.py +35 -32
src/model_demo.py
CHANGED
@@ -13,14 +13,14 @@ from wandb_data import TIMEZONE
|
|
13 |
|
14 |
SERVER_API = os.environ["SERVER_API"]
|
15 |
|
16 |
-
current_model: str
|
17 |
last_current_model_sync: datetime = datetime.fromtimestamp(0, TIMEZONE)
|
18 |
|
19 |
def get_current_model() -> str | None:
|
20 |
global current_model
|
21 |
global last_current_model_sync
|
22 |
now = datetime.now(TIMEZONE)
|
23 |
-
if now - last_current_model_sync < timedelta(minutes=
|
24 |
return current_model
|
25 |
last_current_model_sync = now
|
26 |
|
@@ -66,34 +66,37 @@ def submit(prompt: str, seed: int | str | None, baseline: bool) -> tuple:
|
|
66 |
|
67 |
|
68 |
def create_demo():
|
69 |
-
|
70 |
-
|
71 |
-
with gr.Group(
|
72 |
-
with gr.Group():
|
73 |
-
with gr.Row():
|
74 |
-
with gr.Column():
|
75 |
-
gr.Textbox("Baseline", interactive=False, show_label=False)
|
76 |
-
baseline_image_component = gr.Image(show_label=False)
|
77 |
-
|
78 |
-
with gr.Column():
|
79 |
-
textbox = gr.Textbox(interactive=False, show_label=False)
|
80 |
-
textbox.attach_load_event(lambda: get_current_model(), None)
|
81 |
-
optimized_image_component = gr.Image(show_label=False)
|
82 |
with gr.Row():
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
SERVER_API = os.environ["SERVER_API"]
|
15 |
|
16 |
+
current_model: str | None = None
|
17 |
last_current_model_sync: datetime = datetime.fromtimestamp(0, TIMEZONE)
|
18 |
|
19 |
def get_current_model() -> str | None:
|
20 |
global current_model
|
21 |
global last_current_model_sync
|
22 |
now = datetime.now(TIMEZONE)
|
23 |
+
if now - last_current_model_sync < timedelta(minutes=5):
|
24 |
return current_model
|
25 |
last_current_model_sync = now
|
26 |
|
|
|
66 |
|
67 |
|
68 |
def create_demo():
|
69 |
+
offline_textbox = gr.Textbox("The server is offline! Please come back later", interactive=False, show_label=False)
|
70 |
+
with gr.Group(visible=get_current_model() is not None):
|
71 |
+
with gr.Group():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
with gr.Row():
|
73 |
+
with gr.Column():
|
74 |
+
gr.Textbox("Baseline", interactive=False, show_label=False)
|
75 |
+
baseline_image_component = gr.Image(show_label=False)
|
76 |
+
|
77 |
+
with gr.Column():
|
78 |
+
textbox = gr.Textbox(interactive=False, show_label=False)
|
79 |
+
textbox.attach_load_event(lambda: get_current_model(), None)
|
80 |
+
optimized_image_component = gr.Image(show_label=False)
|
81 |
+
with gr.Row():
|
82 |
+
prompt = gr.Textbox(
|
83 |
+
placeholder="Enter prompt...",
|
84 |
+
interactive=True,
|
85 |
+
submit_btn=True,
|
86 |
+
show_label=False,
|
87 |
+
autofocus=True,
|
88 |
+
scale=10,
|
89 |
+
)
|
90 |
+
|
91 |
+
seed_input = gr.Textbox(
|
92 |
+
placeholder="Enter seed...",
|
93 |
+
interactive=True,
|
94 |
+
show_label=False,
|
95 |
+
)
|
96 |
+
|
97 |
+
offline_textbox.attach_load_event(lambda: gr.Textbox(visible=get_current_model() is None), None)
|
98 |
+
prompt.attach_load_event(lambda: gr.Textbox(visible=get_current_model() is not None), None)
|
99 |
+
seed_input.attach_load_event(lambda: gr.Textbox(visible=get_current_model() is not None), None)
|
100 |
+
|
101 |
+
prompt.submit(lambda prompt, seed: submit(prompt, seed, True), inputs=[prompt, seed_input], outputs=[prompt, baseline_image_component])
|
102 |
+
prompt.submit(lambda prompt, seed: submit(prompt, seed, False), inputs=[prompt, seed_input], outputs=[prompt, optimized_image_component])
|