Spaces:
Running
Running
functional update for summary
Browse files- pages/Summary.py +34 -22
pages/Summary.py
CHANGED
@@ -91,10 +91,13 @@ class DashboardApp:
|
|
91 |
# self.podium_expander(tag, n=len(st.session_state.modelVersion_standings[tag]), summary_mode='edit')
|
92 |
|
93 |
with tab2:
|
94 |
-
st.write('
|
95 |
detailed_info = pd.merge(pd.DataFrame(st.session_state.modelVersion_standings[tag], columns=['modelVersion_id', 'ranking_score']), self.roster, on='modelVersion_id')
|
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 |
|
@@ -105,20 +108,22 @@ class DashboardApp:
|
|
105 |
model_id, model_name, modelVersion_name, url = self.roster[self.roster['modelVersion_id'] == modelVersion_id][['model_id', 'model_name', 'modelVersion_name', 'modelVersion_url']].values[0]
|
106 |
|
107 |
icon = 'π₯'if i == 0 else 'π₯' if i == 1 else 'π₯' if i == 2 else 'π'
|
108 |
-
podium_display = st.columns([1, 14])
|
109 |
with podium_display[0]:
|
110 |
if summary_mode == 'display':
|
111 |
st.title(f'{icon}')
|
112 |
elif summary_mode == 'edit':
|
113 |
-
|
114 |
-
|
|
|
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)
|
@@ -127,7 +132,9 @@ class DashboardApp:
|
|
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 |
-
|
|
|
|
|
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(
|
@@ -135,11 +142,12 @@ class DashboardApp:
|
|
135 |
img_style={"margin": "5px", "height": "100px"}
|
136 |
)
|
137 |
|
138 |
-
|
|
|
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.
|
143 |
unsafe_prompts = json.load(open('data/unsafe_prompts.json', 'r'))
|
144 |
# merge dict values into one list
|
145 |
unsafe_prompts = [item for sublist in unsafe_prompts.values() for item in sublist]
|
@@ -168,8 +176,9 @@ class DashboardApp:
|
|
168 |
st.write('---')
|
169 |
|
170 |
def switch_order(self, tag, current, target):
|
171 |
-
st.session_state.modelVersion_standings[tag][current], st.session_state.modelVersion_standings[tag][target] = st.session_state.modelVersion_standings[tag][target], st.session_state.modelVersion_standings[tag][current]
|
172 |
-
|
|
|
173 |
|
174 |
def score_calculator(self, results, db_table):
|
175 |
modelVersion_standings = {}
|
@@ -217,18 +226,21 @@ class DashboardApp:
|
|
217 |
else:
|
218 |
tag = self.sidebar(tags, mode)
|
219 |
self.leaderboard(tag, db_table)
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
232 |
|
233 |
|
234 |
if __name__ == "__main__":
|
|
|
91 |
# self.podium_expander(tag, n=len(st.session_state.modelVersion_standings[tag]), summary_mode='edit')
|
92 |
|
93 |
with tab2:
|
94 |
+
st.write('**Detailed information of all selected models**')
|
95 |
detailed_info = pd.merge(pd.DataFrame(st.session_state.modelVersion_standings[tag], columns=['modelVersion_id', 'ranking_score']), self.roster, on='modelVersion_id')
|
96 |
|
97 |
+
detailed_info = detailed_info[['model_name', 'modelVersion_name', 'model_download_count', 'tag', 'baseModel']]
|
98 |
+
|
99 |
st.data_editor(detailed_info, hide_index=False, disabled=True)
|
100 |
+
st.caption('You can click the header to sort the table by that column.')
|
101 |
|
102 |
def podium_expander(self, tag, example_prompts, n=3, summary_mode: ['display', 'edit'] = 'display'):
|
103 |
|
|
|
108 |
model_id, model_name, modelVersion_name, url = self.roster[self.roster['modelVersion_id'] == modelVersion_id][['model_id', 'model_name', 'modelVersion_name', 'modelVersion_url']].values[0]
|
109 |
|
110 |
icon = 'π₯'if i == 0 else 'π₯' if i == 1 else 'π₯' if i == 2 else 'π'
|
111 |
+
podium_display = st.columns([1, 14], gap='medium')
|
112 |
with podium_display[0]:
|
113 |
if summary_mode == 'display':
|
114 |
st.title(f'{icon}')
|
115 |
elif summary_mode == 'edit':
|
116 |
+
settop = st.button('π', key=f'settop_{modelVersion_id}', help='Set this model to the top', disabled=i == 0, on_click=self.switch_order, args=(tag, i, 0), use_container_width=True)
|
117 |
+
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), use_container_width=True)
|
118 |
+
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), use_container_width=True)
|
119 |
with podium_display[1]:
|
120 |
title_display = st.columns([3, 1, 1, 1])
|
121 |
with title_display[0]:
|
122 |
st.write(f'##### {model_name}, {modelVersion_name}')
|
123 |
# st.write(f'Ranking Score: {winning_times}')
|
124 |
with title_display[1]:
|
125 |
+
# image_display = st.selectbox('image display', ['Featured', 'All Images'], key=f'image_display_{modelVersion_id}', label_visibility='collapsed')
|
126 |
+
image_display = st.checkbox('Show all images', key=f'image_display_{modelVersion_id}')
|
127 |
|
128 |
with title_display[2]:
|
129 |
st.link_button('Download Model', url, use_container_width=True)
|
|
|
132 |
# st.write(f'[Civitai Page](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id}), [Model Download Link]({url}), Ranking Score: {winning_times}')
|
133 |
# with st.expander(f'**{icon} {model_name}, [{modelVersion_name}](https://civitai.com/models/{model_id}?modelVersionId={modelVersion_id})**, Ranking Score: {winning_times}'):
|
134 |
|
135 |
+
|
136 |
+
|
137 |
+
if not image_display:
|
138 |
example_images = self.promptBook[self.promptBook['prompt_id'].isin(example_prompts) & (self.promptBook['modelVersion_id']==modelVersion_id)]['image_id'].values
|
139 |
example_images = [f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{image}.png" for image in example_images]
|
140 |
clickable_images(
|
|
|
142 |
img_style={"margin": "5px", "height": "100px"}
|
143 |
)
|
144 |
|
145 |
+
else:
|
146 |
+
st.toast('π It may take a while to load all images. Please be patient.')
|
147 |
# with st.expander(f'Show Images'):
|
148 |
images = self.promptBook[self.promptBook['modelVersion_id'] == modelVersion_id]['image_id'].values
|
149 |
|
150 |
+
safety_check = st.checkbox('Include potentially unsafe or offensive images', value=False, key=modelVersion_id)
|
151 |
unsafe_prompts = json.load(open('data/unsafe_prompts.json', 'r'))
|
152 |
# merge dict values into one list
|
153 |
unsafe_prompts = [item for sublist in unsafe_prompts.values() for item in sublist]
|
|
|
176 |
st.write('---')
|
177 |
|
178 |
def switch_order(self, tag, current, target):
|
179 |
+
# st.session_state.modelVersion_standings[tag][current], st.session_state.modelVersion_standings[tag][target] = st.session_state.modelVersion_standings[tag][target], st.session_state.modelVersion_standings[tag][current]
|
180 |
+
# insert the current before the target
|
181 |
+
st.session_state.modelVersion_standings[tag].insert(target, st.session_state.modelVersion_standings[tag].pop(current))
|
182 |
|
183 |
def score_calculator(self, results, db_table):
|
184 |
modelVersion_standings = {}
|
|
|
226 |
else:
|
227 |
tag = self.sidebar(tags, mode)
|
228 |
self.leaderboard(tag, db_table)
|
229 |
+
|
230 |
+
with st.sidebar:
|
231 |
+
with st.form('overall_feedback'):
|
232 |
+
comment = st.text_area('Please leave your comments here.', key='comment')
|
233 |
+
submit_feedback = st.form_submit_button('Submit Feedback')
|
234 |
+
if submit_feedback:
|
235 |
+
commenttime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
236 |
+
curser = RANKING_CONN.cursor()
|
237 |
+
# parse the comment to at most 300 to avoid SQL injection
|
238 |
+
for i in range(0, len(comment), 300):
|
239 |
+
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}')")
|
240 |
+
RANKING_CONN.commit()
|
241 |
+
curser.close()
|
242 |
+
|
243 |
+
st.toast('Thanks for your feedback! We will take it into consideration in our future work.')
|
244 |
|
245 |
|
246 |
if __name__ == "__main__":
|