Terry Zhuo commited on
Commit
17dce22
·
1 Parent(s): 071ce9f
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -3,12 +3,14 @@ import logging
3
  import time
4
  import datetime
5
  import gradio as gr
6
- from threading import Thread
7
  import datasets
8
  from huggingface_hub import snapshot_download, WebhooksServer, WebhookPayload, RepoCard
9
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
10
  from apscheduler.schedulers.background import BackgroundScheduler
11
 
 
 
12
  # Start ephemeral Spaces on PRs (see config in README.md)
13
  from gradio_space_ci.webhook import IS_EPHEMERAL_SPACE, SPACE_ID, configure_space_ci
14
 
@@ -557,26 +559,30 @@ with main_block as demo:
557
 
558
 
559
  def start_evaluation(command, jsonl_file, subset, split):
560
- extra = subset + "_" if subset != "full" else ""
561
- if jsonl_file is not None:
562
- result_path = os.path.basename(jsonl_file.name).replace(".jsonl", f"_{extra}eval_results.json")
563
- else:
564
- result_path = None
565
-
566
- for log in stream_logs(command, jsonl_file):
567
- if jsonl_file is not None and jsonl_file.name.endswith(".jsonl"):
568
- yield log, gr.update(value=result_path, label=result_path, visible=True), gr.update(visible=False)
 
 
 
 
 
 
 
 
 
569
  else:
570
- yield log, gr.update(), gr.update()
571
- result_file = find_result_file()
572
- if result_file:
573
- return gr.update(label="Evaluation completed. Result file found."), gr.update(value=result_file)
574
- # gr.Button(visible=False)#,
575
- # gr.DownloadButton(label="Download Result", value=result_file, visible=True))
576
- else:
577
- return gr.update(label="Evaluation completed. No result file found."), gr.update(value=result_path)
578
- # gr.Button("Run Evaluation", visible=True),
579
- # gr.DownloadButton(visible=False))
580
  submit_btn.click(start_evaluation,
581
  inputs=[command_output, jsonl_file, subset, split],
582
  outputs=[log_output, download_btn, submit_btn])
 
3
  import time
4
  import datetime
5
  import gradio as gr
6
+ from threading import Thread, Lock
7
  import datasets
8
  from huggingface_hub import snapshot_download, WebhooksServer, WebhookPayload, RepoCard
9
  from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
10
  from apscheduler.schedulers.background import BackgroundScheduler
11
 
12
+ lock = Lock()
13
+
14
  # Start ephemeral Spaces on PRs (see config in README.md)
15
  from gradio_space_ci.webhook import IS_EPHEMERAL_SPACE, SPACE_ID, configure_space_ci
16
 
 
559
 
560
 
561
  def start_evaluation(command, jsonl_file, subset, split):
562
+ lock.acquire()
563
+ try:
564
+ extra = subset + "_" if subset != "full" else ""
565
+ if jsonl_file is not None:
566
+ result_path = os.path.basename(jsonl_file.name).replace(".jsonl", f"_{extra}eval_results.json")
567
+ else:
568
+ result_path = None
569
+
570
+ for log in stream_logs(command, jsonl_file):
571
+ if jsonl_file is not None and jsonl_file.name.endswith(".jsonl"):
572
+ yield log, gr.update(value=result_path, label=result_path, visible=True), gr.update(visible=False)
573
+ else:
574
+ yield log, gr.update(), gr.update()
575
+ result_file = find_result_file()
576
+ if result_file:
577
+ return gr.update(label="Evaluation completed. Result file found."), gr.update(value=result_file)
578
+ # gr.Button(visible=False)#,
579
+ # gr.DownloadButton(label="Download Result", value=result_file, visible=True))
580
  else:
581
+ return gr.update(label="Evaluation completed. No result file found."), gr.update(value=result_path)
582
+ # gr.Button("Run Evaluation", visible=True),
583
+ # gr.DownloadButton(visible=False))
584
+ finally:
585
+ lock.release()
 
 
 
 
 
586
  submit_btn.click(start_evaluation,
587
  inputs=[command_output, jsonl_file, subset, split],
588
  outputs=[log_output, download_btn, submit_btn])