Spaces:
Sleeping
Sleeping
fix sql writing bug, add auto image complete
Browse filesauto image complete will based on model download count
- pages/Gallery.py +7 -7
- pages/Ranking.py +15 -1
pages/Gallery.py
CHANGED
@@ -101,10 +101,6 @@ class GalleryApp:
|
|
101 |
config=config,
|
102 |
)
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
def selection_panel(self, items):
|
109 |
# temperal function
|
110 |
|
@@ -304,8 +300,7 @@ class GalleryApp:
|
|
304 |
graph_space = st.empty()
|
305 |
|
306 |
with graph_space.container():
|
307 |
-
|
308 |
-
return_value = self.gallery_graph(items)
|
309 |
|
310 |
with graph_cols[1]:
|
311 |
if return_value:
|
@@ -344,7 +339,12 @@ class GalleryApp:
|
|
344 |
# st.write(item)
|
345 |
infos = ['model_name', 'modelVersion_name', 'model_download_count', 'clip_score', 'mcos_score',
|
346 |
'nsfw_score']
|
347 |
-
|
|
|
|
|
|
|
|
|
|
|
348 |
# for info in infos:
|
349 |
# st.write(f"**{info}**:")
|
350 |
# st.write(item[info])
|
|
|
101 |
config=config,
|
102 |
)
|
103 |
|
|
|
|
|
|
|
|
|
104 |
def selection_panel(self, items):
|
105 |
# temperal function
|
106 |
|
|
|
300 |
graph_space = st.empty()
|
301 |
|
302 |
with graph_space.container():
|
303 |
+
return_value = self.gallery_graph(items)
|
|
|
304 |
|
305 |
with graph_cols[1]:
|
306 |
if return_value:
|
|
|
339 |
# st.write(item)
|
340 |
infos = ['model_name', 'modelVersion_name', 'model_download_count', 'clip_score', 'mcos_score',
|
341 |
'nsfw_score']
|
342 |
+
|
343 |
+
infos_df = item[infos]
|
344 |
+
# rename columns
|
345 |
+
infos_df = infos_df.rename(index={'model_name': 'Model', 'modelVersion_name': 'Version', 'model_download_count': 'Downloads', 'clip_score': 'Clip Score', 'mcos_score': 'mcos Score', 'nsfw_score': 'NSFW Score'})
|
346 |
+
st.table(infos_df)
|
347 |
+
|
348 |
# for info in infos:
|
349 |
# st.write(f"**{info}**:")
|
350 |
# st.write(item[info])
|
pages/Ranking.py
CHANGED
@@ -60,6 +60,7 @@ class RankingApp:
|
|
60 |
st.session_state.ranking[prompt_id][st.session_state.counter[prompt_id]][str(items['image_id'][i])] = i
|
61 |
else:
|
62 |
# set the index of items to the corresponding ranking value of the image_id
|
|
|
63 |
items.index = items['image_id'].apply(lambda x: st.session_state.ranking[prompt_id][st.session_state.counter[prompt_id]][str(x)])
|
64 |
|
65 |
with elements('dashboard'):
|
@@ -184,6 +185,10 @@ class RankingApp:
|
|
184 |
# print({'image_id': image_id, 'modelVersion_id': modelVersion_id, 'ranking': ranking, "user_name": st.session_state.user_id[0], "timestamp": st.session_state.user_id[1]})
|
185 |
# ranking_dataset = ranking_dataset.add_item({'image_id': image_id, 'modelVersion_id': modelVersion_id, 'ranking': ranking, "user_name": st.session_state.user_id[0], "timestamp": st.session_state.user_id[1]})
|
186 |
|
|
|
|
|
|
|
|
|
187 |
query = "INSERT INTO rankings (image_id, modelVersion_id, ranking, user_name, timestamp) VALUES (%s, %s, %s, %s, %s)"
|
188 |
curser.execute(query, (image_id, modelVersion_id, ranking, st.session_state.user_id[0], st.session_state.user_id[1]))
|
189 |
|
@@ -250,7 +255,16 @@ if __name__ == "__main__":
|
|
250 |
for key, value in st.session_state.selected_dict.items():
|
251 |
# promptBook_selected = promptBook_selected.append(promptBook[(promptBook['prompt_id'] == key) & (promptBook['modelVersion_id'].isin(value))])
|
252 |
# replace append with pd.concat
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
promptBook_selected = promptBook_selected.reset_index(drop=True)
|
255 |
# st.write(promptBook_selected)
|
256 |
images_endpoint = "https://modelcofferbucket.s3-accelerate.amazonaws.com/"
|
|
|
60 |
st.session_state.ranking[prompt_id][st.session_state.counter[prompt_id]][str(items['image_id'][i])] = i
|
61 |
else:
|
62 |
# set the index of items to the corresponding ranking value of the image_id
|
63 |
+
print(items['image_id'])
|
64 |
items.index = items['image_id'].apply(lambda x: st.session_state.ranking[prompt_id][st.session_state.counter[prompt_id]][str(x)])
|
65 |
|
66 |
with elements('dashboard'):
|
|
|
185 |
# print({'image_id': image_id, 'modelVersion_id': modelVersion_id, 'ranking': ranking, "user_name": st.session_state.user_id[0], "timestamp": st.session_state.user_id[1]})
|
186 |
# ranking_dataset = ranking_dataset.add_item({'image_id': image_id, 'modelVersion_id': modelVersion_id, 'ranking': ranking, "user_name": st.session_state.user_id[0], "timestamp": st.session_state.user_id[1]})
|
187 |
|
188 |
+
# remove the old ranking if exists
|
189 |
+
query = "DELETE FROM rankings WHERE image_id = %s AND user_name = %s AND timestamp = %s"
|
190 |
+
curser.execute(query, (image_id, st.session_state.user_id[0], st.session_state.user_id[1]))
|
191 |
+
|
192 |
query = "INSERT INTO rankings (image_id, modelVersion_id, ranking, user_name, timestamp) VALUES (%s, %s, %s, %s, %s)"
|
193 |
curser.execute(query, (image_id, modelVersion_id, ranking, st.session_state.user_id[0], st.session_state.user_id[1]))
|
194 |
|
|
|
255 |
for key, value in st.session_state.selected_dict.items():
|
256 |
# promptBook_selected = promptBook_selected.append(promptBook[(promptBook['prompt_id'] == key) & (promptBook['modelVersion_id'].isin(value))])
|
257 |
# replace append with pd.concat
|
258 |
+
user_selections = promptBook[(promptBook['prompt_id'] == key) & (promptBook['modelVersion_id'].isin(value))]
|
259 |
+
|
260 |
+
# auto complete the selection with random images
|
261 |
+
residual = len(user_selections) % 4
|
262 |
+
if residual != 0:
|
263 |
+
# select 4-residual items from the promptbook outside the user_selections
|
264 |
+
npc = promptBook[(promptBook['prompt_id'] == key) & (~promptBook['modelVersion_id'].isin(value))].sort_values(by=['model_download_count'], ascending=False).reset_index(drop=True).iloc[:4-residual]
|
265 |
+
user_selections = pd.concat([user_selections, npc])
|
266 |
+
|
267 |
+
promptBook_selected = pd.concat([promptBook_selected, user_selections])
|
268 |
promptBook_selected = promptBook_selected.reset_index(drop=True)
|
269 |
# st.write(promptBook_selected)
|
270 |
images_endpoint = "https://modelcofferbucket.s3-accelerate.amazonaws.com/"
|