Ricercar commited on
Commit
83ab75d
1 Parent(s): 4eb5601

beta testing for image display

Browse files
Files changed (2) hide show
  1. pages/Summary.py +56 -27
  2. requirements.txt +1 -0
pages/Summary.py CHANGED
@@ -12,6 +12,7 @@ from streamlit_elements import elements, mui, html, dashboard, nivo
12
  from streamlit_extras.switch_page_button import switch_page
13
  from streamlit_extras.metric_cards import style_metric_cards
14
  from streamlit_extras.stylable_container import stylable_container
 
15
 
16
  from pages.Gallery import load_hf_dataset
17
  from pages.Ranking import connect_to_db
@@ -69,10 +70,18 @@ class DashboardApp:
69
  with tab1:
70
  # self.podium(modelVersion_standings)
71
  switch_stage = st.toggle('Manual Reorder', key='switch_stage')
 
 
 
 
 
 
 
 
72
  if switch_stage:
73
- self.podium_expander(tag, n=len(st.session_state.modelVersion_standings[tag]), summary_mode='edit')
74
  else:
75
- self.podium_expander(tag, n=3, summary_mode='display')
76
  # if st.session_state.summary_mode == 'display':
77
  # switch_stage = st.button('Manual Reorder', key='switch_stage_edit', on_click=lambda: st.session_state.__setitem__('summary_mode', 'edit'))
78
  # self.podium_expander(tag, n=3, summary_mode='display')
@@ -87,7 +96,7 @@ class DashboardApp:
87
 
88
  st.data_editor(detailed_info, hide_index=False, disabled=True)
89
 
90
- def podium_expander(self, tag, n=3, summary_mode: ['display', 'edit'] = 'display'):
91
 
92
  for i in range(n):
93
  modelVersion_id = st.session_state.modelVersion_standings[tag][i][0]
@@ -104,17 +113,30 @@ class DashboardApp:
104
  moveup = st.button('⬆', key=f'moveup_{modelVersion_id}', help='Move this model up', disabled=i == 0, on_click=self.switch_order, args=(tag, i, i - 1))
105
  movedown = st.button('⬇', key=f'movedown_{modelVersion_id}', help='Move this model down', disabled=i == n - 1, on_click=self.switch_order, args=(tag, i, i + 1))
106
  with podium_display[1]:
107
- title_display = st.columns([4, 1, 1])
108
  with title_display[0]:
109
  st.write(f'##### {model_name}, {modelVersion_name}')
110
- st.write(f'Ranking Score: {winning_times}')
111
  with title_display[1]:
112
- st.link_button('Download Model', url, use_container_width=True)
 
113
  with title_display[2]:
 
 
114
  st.link_button('Civitai Page', f'https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id}', use_container_width=True, type='primary')
115
  # st.write(f'[Civitai Page](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id}), [Model Download Link]({url}), Ranking Score: {winning_times}')
116
  # with st.expander(f'**{icon} {model_name}, [{modelVersion_name}](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id})**, Ranking Score: {winning_times}'):
117
- with st.expander(f'Show Images'):
 
 
 
 
 
 
 
 
 
 
118
  images = self.promptBook[self.promptBook['modelVersion_id'] == modelVersion_id]['image_id'].values
119
 
120
  safety_check = st.toggle('Include potentially unsafe or offensive images', value=False, key=modelVersion_id)
@@ -127,14 +149,21 @@ class DashboardApp:
127
  # exclude unsafe prompts from images
128
  images = [image for image in images if image not in unsafe_images]
129
 
130
- # st.write(f'### Images generated with {icon} {model_name}, {modelVersion_name}')
131
- col_num = 4
132
- image_cols = st.columns(col_num)
133
-
134
- for j in range(len(images)):
135
- with image_cols[j % col_num]:
136
- image = f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{images[j]}.png"
137
- st.image(image, use_column_width=True)
 
 
 
 
 
 
 
138
  if i != n - 1:
139
  st.write('---')
140
 
@@ -188,18 +217,18 @@ class DashboardApp:
188
  else:
189
  tag = self.sidebar(tags, mode)
190
  self.leaderboard(tag, db_table)
191
-
192
- comment = st.chat_input('Please leave your comments here.', key='comment')
193
- if comment:
194
- commenttime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
195
- curser = RANKING_CONN.cursor()
196
- # parse the comment to at most 300 to avoid SQL injection
197
- for i in range(0, len(comment), 300):
198
- curser.execute(f"INSERT INTO comments (username, timestamp, comment, commenttime) VALUES ('{st.session_state.user_id[0]}', '{st.session_state.user_id[1]}', '{comment[i:i+300]}', '{commenttime}')")
199
- RANKING_CONN.commit()
200
- curser.close()
201
-
202
- st.toast('Thanks for your feedback! We will take it into consideration in our future work.')
203
 
204
 
205
  if __name__ == "__main__":
 
12
  from streamlit_extras.switch_page_button import switch_page
13
  from streamlit_extras.metric_cards import style_metric_cards
14
  from streamlit_extras.stylable_container import stylable_container
15
+ from st_clickable_images import clickable_images
16
 
17
  from pages.Gallery import load_hf_dataset
18
  from pages.Ranking import connect_to_db
 
70
  with tab1:
71
  # self.podium(modelVersion_standings)
72
  switch_stage = st.toggle('Manual Reorder', key='switch_stage')
73
+
74
+ example_prompts = []
75
+ # get example images
76
+ for key, value in st.session_state.selected_dict.items():
77
+ for model in st.session_state.modelVersion_standings[tag]:
78
+ if model[0] in value:
79
+ example_prompts.append(key)
80
+
81
  if switch_stage:
82
+ self.podium_expander(tag, n=len(st.session_state.modelVersion_standings[tag]), summary_mode='edit', example_prompts=example_prompts)
83
  else:
84
+ self.podium_expander(tag, n=len(st.session_state.modelVersion_standings[tag]), summary_mode='display', example_prompts=example_prompts)
85
  # if st.session_state.summary_mode == 'display':
86
  # switch_stage = st.button('Manual Reorder', key='switch_stage_edit', on_click=lambda: st.session_state.__setitem__('summary_mode', 'edit'))
87
  # self.podium_expander(tag, n=3, summary_mode='display')
 
96
 
97
  st.data_editor(detailed_info, hide_index=False, disabled=True)
98
 
99
+ def podium_expander(self, tag, example_prompts, n=3, summary_mode: ['display', 'edit'] = 'display'):
100
 
101
  for i in range(n):
102
  modelVersion_id = st.session_state.modelVersion_standings[tag][i][0]
 
113
  moveup = st.button('⬆', key=f'moveup_{modelVersion_id}', help='Move this model up', disabled=i == 0, on_click=self.switch_order, args=(tag, i, i - 1))
114
  movedown = st.button('⬇', key=f'movedown_{modelVersion_id}', help='Move this model down', disabled=i == n - 1, on_click=self.switch_order, args=(tag, i, i + 1))
115
  with podium_display[1]:
116
+ title_display = st.columns([3, 1, 1, 1])
117
  with title_display[0]:
118
  st.write(f'##### {model_name}, {modelVersion_name}')
119
+ # st.write(f'Ranking Score: {winning_times}')
120
  with title_display[1]:
121
+ image_display = st.selectbox('image display', ['Featured', 'All Images'], key=f'image_display_{modelVersion_id}', label_visibility='collapsed')
122
+
123
  with title_display[2]:
124
+ st.link_button('Download Model', url, use_container_width=True)
125
+ with title_display[3]:
126
  st.link_button('Civitai Page', f'https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id}', use_container_width=True, type='primary')
127
  # st.write(f'[Civitai Page](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id}), [Model Download Link]({url}), Ranking Score: {winning_times}')
128
  # with st.expander(f'**{icon} {model_name}, [{modelVersion_name}](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id})**, Ranking Score: {winning_times}'):
129
+
130
+ if image_display == 'Featured':
131
+ example_images = self.promptBook[self.promptBook['prompt_id'].isin(example_prompts) & (self.promptBook['modelVersion_id']==modelVersion_id)]['image_id'].values
132
+ example_images = [f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{image}.png" for image in example_images]
133
+ clickable_images(
134
+ example_images,
135
+ img_style={"margin": "5px", "height": "100px"}
136
+ )
137
+
138
+ elif image_display == 'All Images':
139
+ # with st.expander(f'Show Images'):
140
  images = self.promptBook[self.promptBook['modelVersion_id'] == modelVersion_id]['image_id'].values
141
 
142
  safety_check = st.toggle('Include potentially unsafe or offensive images', value=False, key=modelVersion_id)
 
149
  # exclude unsafe prompts from images
150
  images = [image for image in images if image not in unsafe_images]
151
 
152
+ images = [f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{image}.png" for image in images]
153
+ clickable_images(
154
+ images,
155
+ img_style={"margin": "5px", "height": "100px"}
156
+ )
157
+
158
+ # # st.write(f'### Images generated with {icon} {model_name}, {modelVersion_name}')
159
+ # col_num = 4
160
+ # image_cols = st.columns(col_num)
161
+ #
162
+ # for j in range(len(images)):
163
+ # with image_cols[j % col_num]:
164
+ # image = f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{images[j]}.png"
165
+ # st.image(image, use_column_width=True)
166
+ #
167
  if i != n - 1:
168
  st.write('---')
169
 
 
217
  else:
218
  tag = self.sidebar(tags, mode)
219
  self.leaderboard(tag, db_table)
220
+ #
221
+ # comment = st.chat_input('Please leave your comments here.', key='comment')
222
+ # if comment:
223
+ # commenttime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
224
+ # curser = RANKING_CONN.cursor()
225
+ # # parse the comment to at most 300 to avoid SQL injection
226
+ # for i in range(0, len(comment), 300):
227
+ # curser.execute(f"INSERT INTO comments (username, timestamp, comment, commenttime) VALUES ('{st.session_state.user_id[0]}', '{st.session_state.user_id[1]}', '{comment[i:i+300]}', '{commenttime}')")
228
+ # RANKING_CONN.commit()
229
+ # curser.close()
230
+ #
231
+ # st.toast('Thanks for your feedback! We will take it into consideration in our future work.')
232
 
233
 
234
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -7,3 +7,4 @@ streamlit-vega-lite
7
  scikit-learn
8
  pymysql
9
  extra_streamlit_components
 
 
7
  scikit-learn
8
  pymysql
9
  extra_streamlit_components
10
+ st-clickable-images