VictorKai1996NUS commited on
Commit
8d23ca8
1 Parent(s): bac0d32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -14,6 +14,12 @@ from videosys.models.cogvideo.pipeline import CogVideoPABConfig
14
  import psutil
15
  import GPUtil
16
 
 
 
 
 
 
 
17
  logging.basicConfig(level=logging.INFO)
18
  logger = logging.getLogger(__name__)
19
 
@@ -312,19 +318,47 @@ with gr.Blocks(css=css) as demo:
312
  status['gpu_memory']
313
  )
314
 
 
 
 
 
315
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  generate_button.click(
317
- generate_vanilla,
318
- inputs=[prompt, num_inference_steps, guidance_scale],
319
- outputs=[video_output, download_video_button, elapsed_time],
 
 
 
 
320
  )
321
 
322
  generate_button_vs.click(
323
- generate_vs,
324
- inputs=[prompt, num_inference_steps, guidance_scale, pab_threshold, pab_gap],
325
- outputs=[video_output_vs, download_video_button_vs, elapsed_time_vs],
 
 
 
 
326
  )
327
 
 
 
 
 
328
  enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
329
 
330
 
 
14
  import psutil
15
  import GPUtil
16
 
17
+ import threading
18
+
19
+ # tracking the task status
20
+ task_running = threading.Event()
21
+
22
+
23
  logging.basicConfig(level=logging.INFO)
24
  logger = logging.getLogger(__name__)
25
 
 
318
  status['gpu_memory']
319
  )
320
 
321
+ def check_task_status():
322
+ if task_running.is_set():
323
+ return gr.update(value="Please wait for the previous running end", visible=True)
324
+ return gr.update(value="", visible=False)
325
 
326
+ def run_task(func, *args):
327
+ if task_running.is_set():
328
+ return None, gr.update(value="Please wait for the previous running end", visible=True), gr.update(visible=False)
329
+
330
+ task_running.set()
331
+ try:
332
+ result = func(*args)
333
+ return result, gr.update(visible=False), gr.update(visible=True)
334
+ finally:
335
+ task_running.clear()
336
+
337
+ # click events
338
  generate_button.click(
339
+ run_task,
340
+ inputs=[lambda: generate_vanilla, prompt, num_inference_steps, guidance_scale],
341
+ outputs=[
342
+ gr.Group([video_output, download_video_button, elapsed_time]),
343
+ task_status,
344
+ gr.Group([generate_button, generate_button_vs])
345
+ ]
346
  )
347
 
348
  generate_button_vs.click(
349
+ run_task,
350
+ inputs=[lambda: generate_vs, prompt, num_inference_steps, guidance_scale, pab_threshold, pab_gap],
351
+ outputs=[
352
+ gr.Group([video_output_vs, download_video_button_vs, elapsed_time_vs]),
353
+ task_status,
354
+ gr.Group([generate_button, generate_button_vs])
355
+ ]
356
  )
357
 
358
+ # check click status
359
+ generate_button.click(check_task_status, outputs=task_status)
360
+ generate_button_vs.click(check_task_status, outputs=task_status)
361
+
362
  enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
363
 
364