Sadjad Alikhani commited on
Commit
de0a7e9
·
verified ·
1 Parent(s): fc61532

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -15
app.py CHANGED
@@ -6,8 +6,16 @@ from PIL import Image
6
  RAW_PATH = os.path.join("images", "raw")
7
  EMBEDDINGS_PATH = os.path.join("images", "embeddings")
8
 
 
 
 
 
9
  # Function to load and display images based on user selection
10
- def display_images(percentage, complexity):
 
 
 
 
11
  # Generate the paths to the images
12
  raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
13
  embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
@@ -20,27 +28,32 @@ def display_images(percentage, complexity):
20
  return raw_image, embeddings_image
21
 
22
  # Define the Gradio interface
23
- data_percentage_options = [10, 30, 50, 70, 100] # Specific percentage values
24
- task_complexity_options = [16, 32] # Specific task complexity values
25
-
26
- # Define the layout and appearance of the UI
27
  with gr.Blocks() as demo:
28
  gr.Markdown("# Raw vs. Embeddings Inference Results")
29
- gr.Markdown("Select a data percentage and task complexity to view the corresponding inference result for raw channels and embeddings.")
30
-
31
- # Inputs (using Dropdowns for discrete values)
32
- with gr.Column():
33
- percentage_dropdown = gr.Dropdown(choices=data_percentage_options, label="Percentage of Data for Training", value=10)
34
- complexity_dropdown = gr.Dropdown(choices=task_complexity_options, label="Task Complexity", value=16)
35
-
 
 
 
 
 
 
 
 
 
36
  # Outputs (display the images side by side and set a smaller size for the images)
37
  with gr.Row():
38
  raw_img = gr.Image(label="Raw Channels", type="pil", width=300, height=300, interactive=False) # Smaller image size
39
  embeddings_img = gr.Image(label="Embeddings", type="pil", width=300, height=300, interactive=False) # Smaller image size
40
 
41
- # Trigger image updates when inputs change
42
- percentage_dropdown.change(fn=display_images, inputs=[percentage_dropdown, complexity_dropdown], outputs=[raw_img, embeddings_img])
43
- complexity_dropdown.change(fn=display_images, inputs=[percentage_dropdown, complexity_dropdown], outputs=[raw_img, embeddings_img])
44
 
45
  # Launch the app
46
  if __name__ == "__main__":
 
6
  RAW_PATH = os.path.join("images", "raw")
7
  EMBEDDINGS_PATH = os.path.join("images", "embeddings")
8
 
9
+ # Specific values for percentage and complexity
10
+ percentage_values = [10, 30, 50, 70, 100]
11
+ complexity_values = [16, 32]
12
+
13
  # Function to load and display images based on user selection
14
+ def display_images(percentage_idx, complexity_idx):
15
+ # Map the slider index to the actual value
16
+ percentage = percentage_values[percentage_idx]
17
+ complexity = complexity_values[complexity_idx]
18
+
19
  # Generate the paths to the images
20
  raw_image_path = os.path.join(RAW_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
21
  embeddings_image_path = os.path.join(EMBEDDINGS_PATH, f"percentage_{percentage}_complexity_{complexity}.png")
 
28
  return raw_image, embeddings_image
29
 
30
  # Define the Gradio interface
 
 
 
 
31
  with gr.Blocks() as demo:
32
  gr.Markdown("# Raw vs. Embeddings Inference Results")
33
+ gr.Markdown("Use the sliders to adjust the percentage of data for training and task complexity.")
34
+
35
+ # Layout for vertical side-by-side sliders
36
+ with gr.Row():
37
+ # Column for percentage slider
38
+ with gr.Column():
39
+ percentage_slider = gr.Slider(minimum=0, maximum=4, step=1, value=0,
40
+ label="Percentage of Data for Training (10, 30, 50, 70, 100)",
41
+ interactive=True, orientation="vertical")
42
+
43
+ # Column for complexity slider
44
+ with gr.Column():
45
+ complexity_slider = gr.Slider(minimum=0, maximum=1, step=1, value=0,
46
+ label="Task Complexity (16, 32)",
47
+ interactive=True, orientation="vertical")
48
+
49
  # Outputs (display the images side by side and set a smaller size for the images)
50
  with gr.Row():
51
  raw_img = gr.Image(label="Raw Channels", type="pil", width=300, height=300, interactive=False) # Smaller image size
52
  embeddings_img = gr.Image(label="Embeddings", type="pil", width=300, height=300, interactive=False) # Smaller image size
53
 
54
+ # Trigger image updates when sliders change
55
+ percentage_slider.change(fn=display_images, inputs=[percentage_slider, complexity_slider], outputs=[raw_img, embeddings_img])
56
+ complexity_slider.change(fn=display_images, inputs=[percentage_slider, complexity_slider], outputs=[raw_img, embeddings_img])
57
 
58
  # Launch the app
59
  if __name__ == "__main__":