harishB97 commited on
Commit
0fe4a00
·
verified ·
1 Parent(s): e5b4609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -16,17 +16,17 @@ species_to_imgpath = {'bird': './descendent_specific_topk_heatmap_withbb_ep=last
16
  imgname_to_filepath = {} # this ignores the extension such as .png
17
  nodename_to_protoIDs = defaultdict(list)
18
 
19
- for species, imgpath in species_to_imgpath.items():
20
- for foldername in os.listdir(imgpath):
21
- if os.path.isdir(os.path.join(imgpath, foldername)):
22
- folderpath = os.path.join(imgpath, foldername)
23
- for filename in os.listdir(folderpath):
24
- if filename.endswith('png') or filename.endswith('jpg'):
25
- filepath = os.path.join(folderpath, filename)
26
- imgname_to_filepath[filename] = filepath
27
- nodename = filename.split('.')[0].split('-')[0]
28
- protoID = filename.split('.')[0].split('-')[1]
29
- nodename_to_protoIDs[nodename].append(protoID)
30
 
31
 
32
  class Node():
@@ -291,6 +291,19 @@ def get_protoIDs(nodename):
291
  return gr.Dropdown(choices=nodename_to_protoIDs[nodename], interactive=True)
292
 
293
  def get_nodenames(species_name):
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  return gr.Dropdown(choices=list(nodename_to_protoIDs.keys()), interactive=True)
295
 
296
  def get_image(nodename, protoID):
@@ -299,7 +312,7 @@ def get_image(nodename, protoID):
299
  return gr.Image(filepath)
300
 
301
  def species_change(species_name):
302
- set_nodename_to_protoIDs(species_name)
303
  return [plot_tree_from_species(species_name), get_nodenames(species_name), get_nodenames(species_name)]
304
 
305
  with gr.Blocks() as demo:
@@ -342,7 +355,7 @@ with gr.Blocks() as demo:
342
  dropdown_2_protos = gr.Dropdown(label="Select a prototype ID", choices=[], allow_custom_value=True)
343
  image_output_2 = gr.Image()
344
  # dropdown_species.change(plot_tree_from_species, dropdown_species, tree_output)
345
- dropdown_species.change(species_change, dropdown_species, [tree_output, dropdown_1_nodename, dropdown_1_nodename])
346
  # dropdown_species.change(set_nodename_to_protoIDs)
347
  # dropdown_species.change(get_nodenames, dropdown_species, dropdown_1_nodename)
348
  # dropdown_species.change(get_nodenames, dropdown_species, dropdown_2_nodename)
 
16
  imgname_to_filepath = {} # this ignores the extension such as .png
17
  nodename_to_protoIDs = defaultdict(list)
18
 
19
+ # for species, imgpath in species_to_imgpath.items():
20
+ # for foldername in os.listdir(imgpath):
21
+ # if os.path.isdir(os.path.join(imgpath, foldername)):
22
+ # folderpath = os.path.join(imgpath, foldername)
23
+ # for filename in os.listdir(folderpath):
24
+ # if filename.endswith('png') or filename.endswith('jpg'):
25
+ # filepath = os.path.join(folderpath, filename)
26
+ # imgname_to_filepath[filename] = filepath
27
+ # nodename = filename.split('.')[0].split('-')[0]
28
+ # protoID = filename.split('.')[0].split('-')[1]
29
+ # nodename_to_protoIDs[nodename].append(protoID)
30
 
31
 
32
  class Node():
 
291
  return gr.Dropdown(choices=nodename_to_protoIDs[nodename], interactive=True)
292
 
293
  def get_nodenames(species_name):
294
+ global nodename_to_protoIDs
295
+ imgpath = species_to_imgpath[species_name]
296
+ for foldername in os.listdir(imgpath):
297
+ if os.path.isdir(os.path.join(imgpath, foldername)):
298
+ folderpath = os.path.join(imgpath, foldername)
299
+ for filename in os.listdir(folderpath):
300
+ if filename.endswith('png') or filename.endswith('jpg'):
301
+ filepath = os.path.join(folderpath, filename)
302
+ imgname_to_filepath[filename] = filepath
303
+ nodename = filename.split('.')[0].split('-')[0]
304
+ protoID = filename.split('.')[0].split('-')[1]
305
+ nodename_to_protoIDs[nodename].append(protoID)
306
+
307
  return gr.Dropdown(choices=list(nodename_to_protoIDs.keys()), interactive=True)
308
 
309
  def get_image(nodename, protoID):
 
312
  return gr.Image(filepath)
313
 
314
  def species_change(species_name):
315
+ # set_nodename_to_protoIDs(species_name)
316
  return [plot_tree_from_species(species_name), get_nodenames(species_name), get_nodenames(species_name)]
317
 
318
  with gr.Blocks() as demo:
 
355
  dropdown_2_protos = gr.Dropdown(label="Select a prototype ID", choices=[], allow_custom_value=True)
356
  image_output_2 = gr.Image()
357
  # dropdown_species.change(plot_tree_from_species, dropdown_species, tree_output)
358
+ dropdown_species.change(species_change, dropdown_species, [tree_output, dropdown_1_nodename, dropdown_2_nodename])
359
  # dropdown_species.change(set_nodename_to_protoIDs)
360
  # dropdown_species.change(get_nodenames, dropdown_species, dropdown_1_nodename)
361
  # dropdown_species.change(get_nodenames, dropdown_species, dropdown_2_nodename)