Ricercar commited on
Commit
6847402
1 Parent(s): 25da4fb

add image border and navigation

Browse files
Files changed (1) hide show
  1. pages/Gallery.py +17 -9
pages/Gallery.py CHANGED
@@ -54,6 +54,9 @@ class GalleryApp:
54
  def gallery_graph(self, items):
55
  items = load_tsne_coordinates(items)
56
 
 
 
 
57
  scale = 50
58
  items.loc[:, 'x'] = items['x'] * scale
59
  items.loc[:, 'y'] = items['y'] * scale
@@ -69,18 +72,18 @@ class GalleryApp:
69
 
70
  nodes.append(Node(id=items.loc[idx, 'image_id'],
71
  # label=str(items.loc[idx, 'model_name']),
72
- title = f"model name: {items.loc[idx, 'model_name']}\nmodelVersion name: {items.loc[idx, 'modelVersion_name']}\nclip score: {items.loc[idx, 'clip_score']}\nmcos score: {items.loc[idx, 'mcos_score']}\npopularity: {items.loc[idx, 'model_download_count']}",
73
  size=20,
74
  shape='image',
75
  image=f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{items.loc[idx, 'image_id']}.png",
76
  x=items.loc[idx, 'x'].item(),
77
  y=items.loc[idx, 'y'].item(),
78
- fixed=True,
79
- color={'background': '#00000', 'border': '#ffffff'},
80
  # opacity=opacity,
81
  shadow={'enabled': True, 'color': 'rgba(0,0,0,0.4)', 'size': 10, 'x': 1, 'y': 1},
82
- # borderWidth=1,
83
- # shapeProperties={'useBorderWithImage': True},
84
  )
85
  )
86
 
@@ -89,12 +92,13 @@ class GalleryApp:
89
  directed=True,
90
  physics=False,
91
  hierarchical=False,
 
92
  # **kwargs
93
  )
94
 
95
  return agraph(nodes=nodes,
96
  edges=edges,
97
- config=config
98
  )
99
 
100
 
@@ -297,9 +301,13 @@ class GalleryApp:
297
  switch_page("ranking")
298
 
299
  with graph_cols[0]:
300
- return_value = self.gallery_graph(items)
301
- with graph_cols[1]:
302
 
 
 
 
 
 
303
  if return_value:
304
  with st.form(key=f'{prompt_id}'):
305
  image_url = f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{return_value}.png"
@@ -570,7 +578,7 @@ if __name__ == "__main__":
570
  if home_btn:
571
  switch_page("home")
572
  else:
573
- st.write('You have already logged in as ' + st.session_state.user_id[0])
574
  roster, promptBook, images_ds = load_hf_dataset()
575
  # print(promptBook.columns)
576
 
 
54
  def gallery_graph(self, items):
55
  items = load_tsne_coordinates(items)
56
 
57
+ # sort items to be popularity from low to high, so that most popular ones will be on the top
58
+ items = items.sort_values(by=['model_download_count'], ascending=True).reset_index(drop=True)
59
+
60
  scale = 50
61
  items.loc[:, 'x'] = items['x'] * scale
62
  items.loc[:, 'y'] = items['y'] * scale
 
72
 
73
  nodes.append(Node(id=items.loc[idx, 'image_id'],
74
  # label=str(items.loc[idx, 'model_name']),
75
+ title=f"model name: {items.loc[idx, 'model_name']}\nmodelVersion name: {items.loc[idx, 'modelVersion_name']}\nclip score: {items.loc[idx, 'clip_score']}\nmcos score: {items.loc[idx, 'mcos_score']}\npopularity: {items.loc[idx, 'model_download_count']}",
76
  size=20,
77
  shape='image',
78
  image=f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{items.loc[idx, 'image_id']}.png",
79
  x=items.loc[idx, 'x'].item(),
80
  y=items.loc[idx, 'y'].item(),
81
+ # fixed=True,
82
+ color={'background': '#E0E0E1', 'border': '#ffffff', 'highlight': {'border': '#F04542'}},
83
  # opacity=opacity,
84
  shadow={'enabled': True, 'color': 'rgba(0,0,0,0.4)', 'size': 10, 'x': 1, 'y': 1},
85
+ borderWidth=2,
86
+ shapeProperties={'useBorderWithImage': True},
87
  )
88
  )
89
 
 
92
  directed=True,
93
  physics=False,
94
  hierarchical=False,
95
+ interaction={'navigationButtons': True, 'dragNodes': False},
96
  # **kwargs
97
  )
98
 
99
  return agraph(nodes=nodes,
100
  edges=edges,
101
+ config=config,
102
  )
103
 
104
 
 
301
  switch_page("ranking")
302
 
303
  with graph_cols[0]:
304
+ graph_space = st.empty()
 
305
 
306
+ with graph_space.container():
307
+ with st.spinner('Loading graph...'):
308
+ return_value = self.gallery_graph(items)
309
+
310
+ with graph_cols[1]:
311
  if return_value:
312
  with st.form(key=f'{prompt_id}'):
313
  image_url = f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{return_value}.png"
 
578
  if home_btn:
579
  switch_page("home")
580
  else:
581
+ # st.write('You have already logged in as ' + st.session_state.user_id[0])
582
  roster, promptBook, images_ds = load_hf_dataset()
583
  # print(promptBook.columns)
584