wi-lab commited on
Commit
4e72019
·
verified ·
1 Parent(s): b636bbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -24,7 +24,11 @@ def beam_prediction_task(data_percentage, task_complexity, theme):
24
  raw_cm = compute_average_confusion_matrix(raw_folder)
25
  if raw_cm is not None:
26
  raw_cm_path = os.path.join(raw_folder, "confusion_matrix_raw.png")
27
- plot_confusion_matrix_beamPred(raw_cm, classes=np.arange(raw_cm.shape[0]), title=f"Raw Confusion Matrix\n({data_percentage}% data, {task_complexity} beams)", save_path=raw_cm_path, theme=theme)
 
 
 
 
28
  raw_img = Image.open(raw_cm_path)
29
  else:
30
  raw_img = None
@@ -33,7 +37,11 @@ def beam_prediction_task(data_percentage, task_complexity, theme):
33
  embeddings_cm = compute_average_confusion_matrix(embeddings_folder)
34
  if embeddings_cm is not None:
35
  embeddings_cm_path = os.path.join(embeddings_folder, "confusion_matrix_embeddings.png")
36
- plot_confusion_matrix_beamPred(embeddings_cm, classes=np.arange(embeddings_cm.shape[0]), title=f"Embeddings Confusion Matrix\n({data_percentage}% data, {task_complexity} beams)", save_path=embeddings_cm_path, theme=theme)
 
 
 
 
37
  embeddings_img = Image.open(embeddings_cm_path)
38
  else:
39
  embeddings_img = None
@@ -474,20 +482,24 @@ def process_hdf5_file(uploaded_file, percentage):
474
  sys.stdout = sys.__stdout__ # Reset print statements
475
 
476
  ######################## Define the Gradio interface ###############################
477
- # JavaScript to detect dark/light mode and pass it to Gradio as 'light' or 'dark'
478
- detect_theme_js = """
479
  <script>
480
- function detectTheme() {
481
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
482
- return 'dark';
483
- } else {
484
- return 'light';
485
- }
486
  }
487
- document.getElementById('theme_output').value = detectTheme();
488
- document.getElementById('theme_output').dispatchEvent(new Event('change'));
 
 
 
 
 
 
 
 
489
  </script>
490
- """
491
 
492
  with gr.Blocks(css="""
493
  .slider-container {
@@ -552,7 +564,7 @@ with gr.Blocks(css="""
552
  gr.HTML(detect_theme_js)
553
 
554
  # Hidden textbox to store the detected theme
555
- theme_output = gr.Textbox(label="Detected Theme", elem_id="theme_output", visible=False)
556
 
557
  # Explanation section with creative spacing and minimal design
558
  gr.Markdown("""
 
24
  raw_cm = compute_average_confusion_matrix(raw_folder)
25
  if raw_cm is not None:
26
  raw_cm_path = os.path.join(raw_folder, "confusion_matrix_raw.png")
27
+ plot_confusion_matrix_beamPred(raw_cm,
28
+ classes=np.arange(raw_cm.shape[0]),
29
+ title=f"Raw Confusion Matrix\n({data_percentage}% data, {task_complexity} beams)",
30
+ save_path=raw_cm_path,
31
+ theme=theme)
32
  raw_img = Image.open(raw_cm_path)
33
  else:
34
  raw_img = None
 
37
  embeddings_cm = compute_average_confusion_matrix(embeddings_folder)
38
  if embeddings_cm is not None:
39
  embeddings_cm_path = os.path.join(embeddings_folder, "confusion_matrix_embeddings.png")
40
+ plot_confusion_matrix_beamPred(embeddings_cm,
41
+ classes=np.arange(embeddings_cm.shape[0]),
42
+ title=f"Embeddings Confusion Matrix\n({data_percentage}% data, {task_complexity} beams)",
43
+ save_path=embeddings_cm_path,
44
+ theme=theme)
45
  embeddings_img = Image.open(embeddings_cm_path)
46
  else:
47
  embeddings_img = None
 
482
  sys.stdout = sys.__stdout__ # Reset print statements
483
 
484
  ######################## Define the Gradio interface ###############################
 
 
485
  <script>
486
+ function detectTheme() {
487
+ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
488
+ return 'dark';
489
+ } else {
490
+ return 'light';
 
491
  }
492
+ }
493
+
494
+ window.onload = function() {
495
+ const theme = detectTheme();
496
+ const themeTextbox = document.getElementById('theme_output');
497
+ if (themeTextbox) {
498
+ themeTextbox.value = theme;
499
+ themeTextbox.dispatchEvent(new Event('change')); // Manually trigger change event
500
+ }
501
+ };
502
  </script>
 
503
 
504
  with gr.Blocks(css="""
505
  .slider-container {
 
564
  gr.HTML(detect_theme_js)
565
 
566
  # Hidden textbox to store the detected theme
567
+ theme_output = gr.Textbox(label="Theme", value="light", visible=False, interactive=False) # Hidden by default
568
 
569
  # Explanation section with creative spacing and minimal design
570
  gr.Markdown("""