Yogeshwarirj commited on
Commit
76484f1
Β·
verified Β·
1 Parent(s): bf4b5ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -1,18 +1,22 @@
1
- import gradio as gr
2
  import subprocess
3
  import json
4
  import os
5
 
6
  def run_benchmark():
 
 
7
  process = subprocess.Popen(
8
  ["python", "-u", "benchmark.py"],
9
  stdout=subprocess.PIPE,
10
- stderr=subprocess.DEVNULL,
11
  text=True,
12
  bufsize=1,
13
  cwd=os.path.dirname(os.path.abspath(__file__))
14
  )
15
 
 
 
16
  output = ""
17
  for line in process.stdout:
18
  output += line
@@ -20,9 +24,12 @@ def run_benchmark():
20
 
21
  process.wait()
22
 
 
 
23
  if os.path.exists("benchmark_results.json"):
24
  with open("benchmark_results.json", "r") as f:
25
  data = json.load(f)
 
26
  summary = data.get("summary", {})
27
  output += f"\n\nπŸ“Š SUMMARY:\n"
28
  output += f" Single MedGemma Accuracy : {summary.get('single_accuracy', 'N/A'):.1f}%\n"
@@ -31,20 +38,30 @@ def run_benchmark():
31
  output += f" Devil's Advocate Saves : {summary.get('devils_advocate_saves', 'N/A')}\n"
32
  yield output
33
 
 
34
  def load_results():
 
 
35
  if not os.path.exists("benchmark_results.json"):
36
  return "No results yet. Run the benchmark first."
 
37
  with open("benchmark_results.json", "r") as f:
38
  return json.dumps(json.load(f), indent=2)
39
 
 
 
 
40
  with gr.Blocks(title="MedPanel Benchmark") as demo:
41
  gr.Markdown("# πŸ₯ MedPanel Benchmark Runner")
42
  gr.Markdown("Compares **Single MedGemma** vs **MedPanel** across test cases.")
43
 
44
  with gr.Row():
 
45
  run_btn = gr.Button("▢️ Run Benchmark", variant="primary")
 
46
  results_btn = gr.Button("πŸ“„ Load Saved Results")
47
 
 
48
  output_box = gr.Textbox(
49
  label="Benchmark Output",
50
  lines=40,
@@ -54,4 +71,5 @@ with gr.Blocks(title="MedPanel Benchmark") as demo:
54
  run_btn.click(fn=run_benchmark, outputs=output_box)
55
  results_btn.click(fn=load_results, outputs=output_box)
56
 
57
- demo.launch()
 
 
1
+ import gradio as gr
2
  import subprocess
3
  import json
4
  import os
5
 
6
  def run_benchmark():
7
+ # spin up benchmark.py as a subprocess so it doesn't block the UI
8
+ # -u flag = unbuffered output, which is what lets us stream line by line
9
  process = subprocess.Popen(
10
  ["python", "-u", "benchmark.py"],
11
  stdout=subprocess.PIPE,
12
+ stderr=subprocess.DEVNULL, # hide model loading noise β€” it's distracting
13
  text=True,
14
  bufsize=1,
15
  cwd=os.path.dirname(os.path.abspath(__file__))
16
  )
17
 
18
+ # stream each line to the UI as it comes in
19
+ # this way the user sees progress instead of staring at a blank box for 10 minutes
20
  output = ""
21
  for line in process.stdout:
22
  output += line
 
24
 
25
  process.wait()
26
 
27
+ # once benchmark.py finishes, try to load the saved JSON and show a clean summary
28
+ # benchmark.py writes this file β€” if it's missing, something went wrong upstream
29
  if os.path.exists("benchmark_results.json"):
30
  with open("benchmark_results.json", "r") as f:
31
  data = json.load(f)
32
+
33
  summary = data.get("summary", {})
34
  output += f"\n\nπŸ“Š SUMMARY:\n"
35
  output += f" Single MedGemma Accuracy : {summary.get('single_accuracy', 'N/A'):.1f}%\n"
 
38
  output += f" Devil's Advocate Saves : {summary.get('devils_advocate_saves', 'N/A')}\n"
39
  yield output
40
 
41
+
42
  def load_results():
43
+ # just a convenience button β€” lets you reload the last run without
44
+ # running the full benchmark again (which takes ~10 minutes)
45
  if not os.path.exists("benchmark_results.json"):
46
  return "No results yet. Run the benchmark first."
47
+
48
  with open("benchmark_results.json", "r") as f:
49
  return json.dumps(json.load(f), indent=2)
50
 
51
+
52
+ # ── UI ───────────────────────────────────────────────────────────────
53
+
54
  with gr.Blocks(title="MedPanel Benchmark") as demo:
55
  gr.Markdown("# πŸ₯ MedPanel Benchmark Runner")
56
  gr.Markdown("Compares **Single MedGemma** vs **MedPanel** across test cases.")
57
 
58
  with gr.Row():
59
+ # run_benchmark streams live output as the test cases complete
60
  run_btn = gr.Button("▢️ Run Benchmark", variant="primary")
61
+ # load_results just reads the last saved JSON β€” no rerun needed
62
  results_btn = gr.Button("πŸ“„ Load Saved Results")
63
 
64
+ # tall textbox so you can see the full output without scrolling too much
65
  output_box = gr.Textbox(
66
  label="Benchmark Output",
67
  lines=40,
 
71
  run_btn.click(fn=run_benchmark, outputs=output_box)
72
  results_btn.click(fn=load_results, outputs=output_box)
73
 
74
+
75
+ demo.launch()