xinwei89 commited on
Commit
79a62ec
1 Parent(s): ad4b249

fixed gradio logic

Browse files
Files changed (2) hide show
  1. app.py +2 -3
  2. backend.py +9 -6
app.py CHANGED
@@ -18,11 +18,11 @@ with gr.Blocks() as demo:
18
  with gr.Column():
19
  image_input = gr.components.Image(type="pil", label="Input Image")
20
  with gr.Column():
21
- mode_dropdown = gr.Dropdown(choices=["Trees", "Buildings", "Both"], label="Detection Mode", value="Both")
22
  color_mode_select = gr.components.Radio(choices=["Black/white", "Random", "Segmentation"], label="Color Mode", value="Segmentation")
23
 
24
  # split tree and building into two rows side by side
25
- tree_row, building_row , lcz_row = gr.Row(), gr.Row(), gr.Row()
26
  # tree_col, building_col = gr.Column(elem_id="tree_col"), gr.Column(elem_id="building_col")
27
  with tree_row as tree_options:
28
  tree_version_dropdown = gr.Dropdown(choices=list_cfg_file_versions("tree_model_weights"), label="Tree Detection Version", value="treev2", visible=True, interactive=True)
@@ -48,5 +48,4 @@ with gr.Blocks() as demo:
48
  output_image = gr.components.Image(type="pil", label="Output Image")
49
  run_model = gr.Button("Upload Image and Run Model")
50
 
51
- run_model.click(visualize_image, inputs=[image_input, mode_dropdown, tree_threshold_slider, building_threshold_slider, lcz_threshold_slider, color_mode_select, tree_version_dropdown, tree_pth_dropdown, building_version_dropdown, building_pth_dropdown, lcz_version_dropdown, lcz_pth_dropdown], outputs=[output_image])
52
  demo.launch()
 
18
  with gr.Column():
19
  image_input = gr.components.Image(type="pil", label="Input Image")
20
  with gr.Column():
21
+ mode_dropdown = gr.Dropdown(choices=["Trees", "Buildings", "Trees & Buildings", "LCZ"], label="Detection Mode", value="Trees & Buildings")
22
  color_mode_select = gr.components.Radio(choices=["Black/white", "Random", "Segmentation"], label="Color Mode", value="Segmentation")
23
 
24
  # split tree and building into two rows side by side
25
+ tree_row, building_row , lcz_row = gr.Row(), gr.Row(), gr.Row(visible=False)
26
  # tree_col, building_col = gr.Column(elem_id="tree_col"), gr.Column(elem_id="building_col")
27
  with tree_row as tree_options:
28
  tree_version_dropdown = gr.Dropdown(choices=list_cfg_file_versions("tree_model_weights"), label="Tree Detection Version", value="treev2", visible=True, interactive=True)
 
48
  output_image = gr.components.Image(type="pil", label="Output Image")
49
  run_model = gr.Button("Upload Image and Run Model")
50
 
 
51
  demo.launch()
backend.py CHANGED
@@ -51,18 +51,21 @@ def get_version_cfg_yml(path):
51
 
52
  def update_row_visibility(mode):
53
  visibility = {
54
- "tree": mode in ["Trees", "Both"],
55
- "building": mode in ["Buildings", "Both"]
 
56
  }
57
- tree_row, building_row = gr.Row(visible=visibility["tree"]), gr.Row(visible=visibility["building"])
58
-
59
- return tree_row, building_row
60
 
61
  def update_path_options(version):
62
  if "tree" in version:
63
  directory = "tree_model_weights"
64
- else:
65
  directory = "building_model_weights"
 
 
66
  return gr.Dropdown(choices=list_pth_files_in_directory(directory, version), label=f"Select a {version.split('v')[0]} model file", visible=True, interactive=True)
67
 
68
  # Model for trees
 
51
 
52
  def update_row_visibility(mode):
53
  visibility = {
54
+ "tree": mode in ["Trees", "Trees & Buildings"],
55
+ "building": mode in ["Buildings", "Trees & Buildings"],
56
+ "lcz": mode in ["LCZ"]
57
  }
58
+ tree_row, building_row, lcz_row = gr.Row(visible=visibility["tree"]), gr.Row(visible=visibility["building"]), gr.Row(visible=visibility["lcz"])
59
+ print(visibility)
60
+ return tree_row, building_row, lcz_row
61
 
62
  def update_path_options(version):
63
  if "tree" in version:
64
  directory = "tree_model_weights"
65
+ elif "building" in version:
66
  directory = "building_model_weights"
67
+ elif "lcz" in version:
68
+ directory = "lcz_model_weights"
69
  return gr.Dropdown(choices=list_pth_files_in_directory(directory, version), label=f"Select a {version.split('v')[0]} model file", visible=True, interactive=True)
70
 
71
  # Model for trees