vancauwe commited on
Commit
59d7f29
·
1 Parent(s): 3011029

feat: config and ui for physical changes

Browse files
app/checkbox_physical.py CHANGED
@@ -7,9 +7,9 @@ from dropdowns_conditions import retrieve_config_options
7
  def get_options_description(value):
8
  dropdown_config = get_custom_config_dropdowns("/assets/config/config_checkbox_physical.json")
9
  # get options
10
- options = retrieve_config_options(value, dropdown_config)
11
- common = retrieve_config_options("Common", dropdown_config)
12
- options.extend(common)
13
  # get descriptions
14
  descriptions = []
15
  for key, sub_dict in dropdown_config.items():
@@ -20,14 +20,17 @@ def get_options_description(value):
20
  descriptions.append(description)
21
  return options, descriptions
22
  #---------------------------------------------------------
23
- def checkbox(body_part):
24
- options, decriptions = get_options_description(body_part)
25
- descriptions = "".join([f"\t{option}: {description}\n" for option, description in zip(options, decriptions)])
26
  checkbox = gr.CheckboxGroup(options,
27
  label=f"Physical changes observed on {body_part}:",
28
- visible=True)
29
- text = gr.Textbox(descriptions,
 
 
30
  label = "Info",
31
  interactive=False,
32
- visible=True)
 
33
  return checkbox, text
 
7
  def get_options_description(value):
8
  dropdown_config = get_custom_config_dropdowns("/assets/config/config_checkbox_physical.json")
9
  # get options
10
+ options = retrieve_config_options("Common", dropdown_config)
11
+ options_for_value = retrieve_config_options(value, dropdown_config)
12
+ options.extend(options_for_value)
13
  # get descriptions
14
  descriptions = []
15
  for key, sub_dict in dropdown_config.items():
 
20
  descriptions.append(description)
21
  return options, descriptions
22
  #---------------------------------------------------------
23
+ def checkbox(body_part, section):
24
+ options, descriptions = get_options_description(body_part)
25
+ descriptions_info = "".join([f"\t{option}: {description}\n" for option, description in zip(options, descriptions)])
26
  checkbox = gr.CheckboxGroup(options,
27
  label=f"Physical changes observed on {body_part}:",
28
+ visible=True,
29
+ interactive=True,
30
+ elem_id=section)
31
+ text = gr.Textbox(descriptions_info,
32
  label = "Info",
33
  interactive=False,
34
+ visible=True,
35
+ elem_id=section)
36
  return checkbox, text
app/dropdowns_conditions.py CHANGED
@@ -17,7 +17,7 @@ def reinitialise_level2():
17
  def create_dropdown_level1(label):
18
  dropdown_config = get_custom_config_dropdowns("/assets/config/config_dropdown_conditions.json")
19
  options = retrieve_config_options(label, dropdown_config)
20
- dropdown = gr.Dropdown(choices=options, label=label, interactive=True)
21
  dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()
22
  return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
23
 
 
17
  def create_dropdown_level1(label):
18
  dropdown_config = get_custom_config_dropdowns("/assets/config/config_dropdown_conditions.json")
19
  options = retrieve_config_options(label, dropdown_config)
20
+ dropdown = gr.Dropdown(choices=options, label=label, interactive=True, visible=True)
21
  dropdown_level2, openfield_level2, dropdown_extra_level2 = reinitialise_level2()
22
  return dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2
23
 
app/main.py CHANGED
@@ -88,7 +88,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
88
  ])
89
 
90
  img_with_boxes.select(find_bounding_box,
91
- inputs=[img_with_boxes],
92
  outputs=[physical_checkbox, physical_text])
93
  # ---------------------------------------------------------
94
  # Dropdowns Dead
 
88
  ])
89
 
90
  img_with_boxes.select(find_bounding_box,
91
+ inputs=[img_with_boxes, gr.Textbox(value="wounded", label="Keyword", visible=False)],
92
  outputs=[physical_checkbox, physical_text])
93
  # ---------------------------------------------------------
94
  # Dropdowns Dead
app/select_bird.py CHANGED
@@ -7,26 +7,32 @@ from checkbox_physical import *
7
  from boxes_define import gdf
8
 
9
  # Function to find the matching bounding box for a given point and return the image with boxes
10
- def find_bounding_box(evt: gr.SelectData, img):
11
  x, y = evt.index[0], evt.index[1]
12
  point = Point(x, y)
13
  match = gdf[gdf.contains(point)]
14
  if not match.empty:
15
  matched_box = match.iloc[0]['name']
16
- physical_checkbox, physical_text = checkbox(matched_box)
17
  else:
18
- matched_box = "No bounding box found"
 
19
  return physical_checkbox, physical_text
20
 
 
 
 
 
 
 
21
  # Gradio app
22
- def create_bird_anatomy():
23
  # Draw bounding boxes on the image
24
  img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
25
  show_label=False,
26
- height="600px")
27
- #templates
28
- checkbox = gr.CheckboxGroup([], label="")
29
- text = gr.Textbox("", label = "", interactive=False,)
30
  return img_with_boxes, checkbox, text
31
 
32
 
 
7
  from boxes_define import gdf
8
 
9
  # Function to find the matching bounding box for a given point and return the image with boxes
10
+ def find_bounding_box(evt: gr.SelectData, img, section: str):
11
  x, y = evt.index[0], evt.index[1]
12
  point = Point(x, y)
13
  match = gdf[gdf.contains(point)]
14
  if not match.empty:
15
  matched_box = match.iloc[0]['name']
16
+ physical_checkbox, physical_text = checkbox(matched_box, section)
17
  else:
18
+ matched_box = "None"
19
+ physical_checkbox, physical_text = create_template_checkbox()
20
  return physical_checkbox, physical_text
21
 
22
+ def create_template_checkbox():
23
+ #templates
24
+ checkbox = gr.CheckboxGroup([], label="", visible=False)
25
+ text = gr.Textbox("", label = "", interactive=False, visible=False)
26
+ return checkbox, text
27
+
28
  # Gradio app
29
+ def create_bird_anatomy(section: str):
30
  # Draw bounding boxes on the image
31
  img_with_boxes = gr.Image(value='assets/images/bird_boxed.png',
32
  show_label=False,
33
+ height="600px",
34
+ elem_id=section)
35
+ checkbox, text = create_template_checkbox()
 
36
  return img_with_boxes, checkbox, text
37
 
38
 
app/theme.py CHANGED
@@ -5,6 +5,7 @@ css = """
5
  #image {background-color: #73b9ae}
6
  #dead {background-color: #333333}
7
  #wounded {background-color: #5e0724}
 
8
  #buttons-conditions {background-color: #b3b3b3}
9
  #dropdown-conditions {background-color: #b3b3b3}
10
  #followup {background-color: #38241c}
 
5
  #image {background-color: #73b9ae}
6
  #dead {background-color: #333333}
7
  #wounded {background-color: #5e0724}
8
+ #bird-boxes {background-color: #f2f3f3}
9
  #buttons-conditions {background-color: #b3b3b3}
10
  #dropdown-conditions {background-color: #b3b3b3}
11
  #followup {background-color: #38241c}
app/wounded.py CHANGED
@@ -11,7 +11,7 @@ def show_section_wounded(visible):
11
  image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
12
  dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
13
 
14
- img_with_boxes, physical_checkbox, physical_text = create_bird_anatomy()
15
 
16
  create_followup_section()
17
 
 
11
  image_row, button_collision, button_deliberate_destruction, button_indirect_destruction, button_natural_cause = create_top_section(visible)
12
  dropdown_row, dropdown, dropdown_level2, openfield_level2, dropdown_extra_level2 = create_dropdown(visible)
13
 
14
+ img_with_boxes, physical_checkbox, physical_text = create_bird_anatomy("wounded")
15
 
16
  create_followup_section()
17