Spaces:
Running
Running
Simplify Gallery Choice
Browse filesChange time to utc
Add new database to record image click
Select image on click
Add hover color
Add report button
- Home.py +1 -1
- pages/Gallery.py +101 -41
- pages/Ranking.py +2 -2
- pages/Summary.py +3 -18
Home.py
CHANGED
@@ -38,7 +38,7 @@ def save_user_id(user_id):
|
|
38 |
print(user_id)
|
39 |
if not user_id:
|
40 |
user_id = 'anonymous' + str(random.randint(0, 100000))
|
41 |
-
st.session_state.user_id = [user_id, datetime.
|
42 |
st.session_state.assigned_rank_mode = random.choice(['Drag and Sort', 'Battle'])
|
43 |
st.session_state.epoch = {'gallery': 0, 'ranking': {}, 'summary': {'overall': 0}}
|
44 |
|
|
|
38 |
print(user_id)
|
39 |
if not user_id:
|
40 |
user_id = 'anonymous' + str(random.randint(0, 100000))
|
41 |
+
st.session_state.user_id = [user_id, datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")]
|
42 |
st.session_state.assigned_rank_mode = random.choice(['Drag and Sort', 'Battle'])
|
43 |
st.session_state.epoch = {'gallery': 0, 'ranking': {}, 'summary': {'overall': 0}}
|
44 |
|
pages/Gallery.py
CHANGED
@@ -8,7 +8,6 @@ import random
|
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
10 |
import streamlit as st
|
11 |
-
import streamlit.components.v1 as components
|
12 |
|
13 |
from bs4 import BeautifulSoup
|
14 |
from datasets import load_dataset, Dataset, load_from_disk
|
@@ -95,7 +94,8 @@ class GalleryApp:
|
|
95 |
|
96 |
nodes.append(Node(id=items.loc[idx, 'image_id'],
|
97 |
# label=str(items.loc[idx, 'model_name']),
|
98 |
-
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']}",
|
|
|
99 |
size=20,
|
100 |
shape='image',
|
101 |
image=f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{items.loc[idx, 'image_id']}.png",
|
@@ -105,7 +105,8 @@ class GalleryApp:
|
|
105 |
color={'background': '#E0E0E1', 'border': '#ffffff', 'highlight': {'border': '#F04542'}},
|
106 |
# opacity=opacity,
|
107 |
shadow={'enabled': True, 'color': 'rgba(0,0,0,0.4)', 'size': 10, 'x': 1, 'y': 1},
|
108 |
-
borderWidth=
|
|
|
109 |
shapeProperties={'useBorderWithImage': True},
|
110 |
)
|
111 |
)
|
@@ -115,7 +116,7 @@ class GalleryApp:
|
|
115 |
directed=True,
|
116 |
physics=False,
|
117 |
hierarchical=False,
|
118 |
-
interaction={'navigationButtons': True, 'dragNodes': False, 'multiselect': False},
|
119 |
# **kwargs
|
120 |
)
|
121 |
|
@@ -349,45 +350,106 @@ class GalleryApp:
|
|
349 |
modelVersion_id = item['modelVersion_id']
|
350 |
|
351 |
# handle selection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
if 'selected_dict' in st.session_state:
|
353 |
if item['prompt_id'] not in st.session_state.selected_dict:
|
354 |
st.session_state.selected_dict[item['prompt_id']] = []
|
355 |
|
356 |
-
if
|
357 |
-
|
358 |
-
|
359 |
-
|
|
|
|
|
360 |
|
361 |
-
|
362 |
-
#
|
363 |
-
|
|
|
|
|
|
|
364 |
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
# st.write(item)
|
370 |
-
infos = ['model_name', 'modelVersion_name', 'model_download_count', 'clip_score', 'mcos_score',
|
371 |
-
|
372 |
-
|
373 |
-
infos_df = item[infos]
|
374 |
-
# rename columns
|
375 |
-
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'})
|
376 |
-
st.table(infos_df)
|
377 |
|
378 |
else:
|
379 |
st.info('Please click on an image to show')
|
380 |
|
381 |
-
def image_selection_control(self, tag, prompt, prompt_id, modelVersion_id,
|
382 |
self.remove_ranking_states(prompt_id)
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
st.session_state.selected_dict[prompt_id].append(modelVersion_id)
|
385 |
# add focus to session state
|
386 |
st.session_state.gallery_focus['tag'] = tag
|
387 |
st.session_state.gallery_focus['prompt'] = prompt
|
388 |
|
389 |
-
|
390 |
-
st.session_state.selected_dict[prompt_id]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
def checkout_mode(self, tag, items):
|
393 |
# st.write(items)
|
@@ -446,7 +508,7 @@ class GalleryApp:
|
|
446 |
if keys[0] == 'select' and keys[1] == str(prompt_id):
|
447 |
if st.session_state[key]:
|
448 |
st.session_state.selected_dict[prompt_id].append(int(keys[2]))
|
449 |
-
|
450 |
st.session_state.edit_state = False
|
451 |
st.rerun()
|
452 |
|
@@ -459,24 +521,22 @@ class GalleryApp:
|
|
459 |
st.session_state.gallery_state = 'graph'
|
460 |
|
461 |
print('selected_dict: ', st.session_state.selected_dict)
|
|
|
|
|
462 |
# cursor = GALLERY_CONN.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
463 |
# cursor.close()
|
464 |
|
465 |
-
# save the user selection to database
|
466 |
-
cursor = GALLERY_CONN.cursor()
|
467 |
-
st.session_state.epoch['gallery'] += 1
|
468 |
-
checkouttime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
469 |
-
# for modelVersion_id in st.session_state.selected_dict[prompt_id]:
|
470 |
-
for key, values in st.session_state.selected_dict.items():
|
471 |
-
# print('key: ', key, 'values: ', values)
|
472 |
-
key_tag = self.promptBook[self.promptBook['prompt_id'] == key]['tag'].unique()[0]
|
473 |
-
for value in values:
|
474 |
-
query = "INSERT INTO gallery_selections (username, timestamp, tag, prompt_id, modelVersion_id, checkouttime, epoch) VALUES ('{}', '{}', '{}', '{}', {}, '{}', {})".format(st.session_state.user_id[0], st.session_state.user_id[1], key_tag, key, value, checkouttime, st.session_state.epoch['gallery'])
|
475 |
-
print(query)
|
476 |
-
cursor.execute(query)
|
477 |
-
GALLERY_CONN.commit()
|
478 |
-
cursor.close()
|
479 |
-
|
480 |
# get the largest epoch number of this user and prompt
|
481 |
cursor = GALLERY_CONN.cursor()
|
482 |
db_table = 'battle_results' if st.session_state.assigned_rank_mode=='Battle' else 'sort_results'
|
|
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
10 |
import streamlit as st
|
|
|
11 |
|
12 |
from bs4 import BeautifulSoup
|
13 |
from datasets import load_dataset, Dataset, load_from_disk
|
|
|
94 |
|
95 |
nodes.append(Node(id=items.loc[idx, 'image_id'],
|
96 |
# label=str(items.loc[idx, 'model_name']),
|
97 |
+
# 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']}",
|
98 |
+
title=" ",
|
99 |
size=20,
|
100 |
shape='image',
|
101 |
image=f"https://modelcofferbucket.s3-accelerate.amazonaws.com/{items.loc[idx, 'image_id']}.png",
|
|
|
105 |
color={'background': '#E0E0E1', 'border': '#ffffff', 'highlight': {'border': '#F04542'}},
|
106 |
# opacity=opacity,
|
107 |
shadow={'enabled': True, 'color': 'rgba(0,0,0,0.4)', 'size': 10, 'x': 1, 'y': 1},
|
108 |
+
borderWidth=3,
|
109 |
+
borderWidthSelected=3,
|
110 |
shapeProperties={'useBorderWithImage': True},
|
111 |
)
|
112 |
)
|
|
|
116 |
directed=True,
|
117 |
physics=False,
|
118 |
hierarchical=False,
|
119 |
+
interaction={'navigationButtons': True, 'dragNodes': False, 'multiselect': False, 'hover': True},
|
120 |
# **kwargs
|
121 |
)
|
122 |
|
|
|
350 |
modelVersion_id = item['modelVersion_id']
|
351 |
|
352 |
# handle selection
|
353 |
+
# get the latest record in database
|
354 |
+
cursor = GALLERY_CONN.cursor()
|
355 |
+
query = "SELECT * FROM gallery_clicks WHERE username = '{}' AND timestamp = '{}' AND prompt_id = '{}' AND modelVersion_id = {} ORDER BY clicktime DESC LIMIT 1".format(
|
356 |
+
st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, modelVersion_id)
|
357 |
+
cursor.execute(query)
|
358 |
+
record = cursor.fetchone()
|
359 |
+
try:
|
360 |
+
image_status = record['status']
|
361 |
+
except:
|
362 |
+
image_status = None
|
363 |
+
|
364 |
+
print('image_status: ', image_status)
|
365 |
+
|
366 |
if 'selected_dict' in st.session_state:
|
367 |
if item['prompt_id'] not in st.session_state.selected_dict:
|
368 |
st.session_state.selected_dict[item['prompt_id']] = []
|
369 |
|
370 |
+
# if 'last_clicked' not in st.session_state or item['image_id'] != st.session_state.last_clicked:
|
371 |
+
# print('last_clicked not in session state')
|
372 |
+
# self.image_selection_control(item['tag'], item['prompt'], item['prompt_id'], modelVersion_id, 'select')
|
373 |
+
# st.toast('Image selected.', icon='👍')
|
374 |
+
#
|
375 |
+
# st.session_state.last_clicked = item['image_id']
|
376 |
|
377 |
+
# if modelVersion_id in st.session_state.selected_dict[item['prompt_id']]:
|
378 |
+
# checked = True
|
379 |
+
# else:
|
380 |
+
# checked = False
|
381 |
+
selection_control_button = st.empty()
|
382 |
+
report_control_button = st.empty()
|
383 |
|
384 |
+
if image_status == 'report':
|
385 |
+
st.warning('You have reported this image')
|
386 |
+
unreport = report_control_button.form_submit_button('Withdraw report', use_container_width=True, type='secondary', on_click=self.image_selection_control, args=(item['tag'], item['prompt'], item['prompt_id'], item['modelVersion_id'], 'deselect'))
|
387 |
|
388 |
+
else:
|
389 |
+
if image_status is None:
|
390 |
+
self.image_selection_control(item['tag'], item['prompt'], item['prompt_id'],
|
391 |
+
modelVersion_id,
|
392 |
+
'select')
|
393 |
+
# st.toast('Image selected.', icon='👍')
|
394 |
+
|
395 |
+
if image_status == 'select' or image_status == 'reselect' or image_status is None:
|
396 |
+
# deselect = st.button('Deselect', key=f'select_{item["prompt_id"]}_{item["modelVersion_id"]}', use_container_width=True)
|
397 |
+
deselect = selection_control_button.form_submit_button('Deselect', use_container_width=True, on_click=self.image_selection_control, args=(item['tag'], item['prompt'], item['prompt_id'], item['modelVersion_id'], 'deselect'))
|
398 |
+
|
399 |
+
st.info(
|
400 |
+
"Image selected. **Click the 'Check out selections ➡️' on top to see all selected images**. You can get back to gallery graph at anytime.")
|
401 |
+
|
402 |
+
elif image_status =='deselect':
|
403 |
+
# select = st.button('Select', key=f'select_{item["prompt_id"]}_{item["modelVersion_id"]}', use_container_width=True, type='primary')
|
404 |
+
reselect = selection_control_button.form_submit_button('Reselect', use_container_width=True, type='primary', on_click=self.image_selection_control, args=(item['tag'], item['prompt'], item['prompt_id'], item['modelVersion_id'], 'reselect'))
|
405 |
+
|
406 |
+
report = report_control_button.form_submit_button('⚠️Report', use_container_width=True, type='secondary',
|
407 |
+
on_click=self.image_selection_control, args=(
|
408 |
+
item['tag'], item['prompt'], item['prompt_id'], item['modelVersion_id'], 'report'))
|
409 |
# st.write(item)
|
410 |
+
# infos = ['model_name', 'modelVersion_name', 'model_download_count', 'clip_score', 'mcos_score',
|
411 |
+
# 'nsfw_score']
|
412 |
+
#
|
413 |
+
# infos_df = item[infos]
|
414 |
+
# # rename columns
|
415 |
+
# 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'})
|
416 |
+
# st.table(infos_df)
|
417 |
|
418 |
else:
|
419 |
st.info('Please click on an image to show')
|
420 |
|
421 |
+
def image_selection_control(self, tag, prompt, prompt_id, modelVersion_id, operation:['select', 'reselect', 'deselect','report']):
|
422 |
self.remove_ranking_states(prompt_id)
|
423 |
+
|
424 |
+
# # update the status of the lastest clicktime
|
425 |
+
# query = "UPDATE gallery_clicks SET status= '{}' " \
|
426 |
+
# "WHERE username = '{}' AND timestamp = '{}' AND prompt_id = '{}' AND modelVersion_id = {} AND clicktime = " \
|
427 |
+
# "(SELECT MAX(clicktime) WHERE username = '{}' AND timestamp = '{}' AND prompt_id = '{}' AND modelVersion_id = {}" \
|
428 |
+
# .format(operation,
|
429 |
+
# st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, modelVersion_id,
|
430 |
+
# st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, modelVersion_id)
|
431 |
+
|
432 |
+
if operation == 'select' or operation == 'reselect':
|
433 |
st.session_state.selected_dict[prompt_id].append(modelVersion_id)
|
434 |
# add focus to session state
|
435 |
st.session_state.gallery_focus['tag'] = tag
|
436 |
st.session_state.gallery_focus['prompt'] = prompt
|
437 |
|
438 |
+
elif operation == 'deselect':
|
439 |
+
if modelVersion_id in st.session_state.selected_dict[prompt_id]:
|
440 |
+
st.session_state.selected_dict[prompt_id].remove(modelVersion_id)
|
441 |
+
elif operation == 'report':
|
442 |
+
pass
|
443 |
+
|
444 |
+
cursor = GALLERY_CONN.cursor()
|
445 |
+
clicktime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
446 |
+
query = "INSERT INTO gallery_clicks (username, timestamp, tag, prompt_id, modelVersion_id, clicktime, status) VALUES ('{}', '{}', '{}', '{}', {}, '{}', '{}')".format(
|
447 |
+
st.session_state.user_id[0], st.session_state.user_id[1], tag, prompt_id, modelVersion_id, clicktime,
|
448 |
+
operation)
|
449 |
+
|
450 |
+
cursor.execute(query)
|
451 |
+
GALLERY_CONN.commit()
|
452 |
+
cursor.close()
|
453 |
|
454 |
def checkout_mode(self, tag, items):
|
455 |
# st.write(items)
|
|
|
508 |
if keys[0] == 'select' and keys[1] == str(prompt_id):
|
509 |
if st.session_state[key]:
|
510 |
st.session_state.selected_dict[prompt_id].append(int(keys[2]))
|
511 |
+
self.image_selection_control(tag, prompt, prompt_id, int(keys[2]), 'select') # update database
|
512 |
st.session_state.edit_state = False
|
513 |
st.rerun()
|
514 |
|
|
|
521 |
st.session_state.gallery_state = 'graph'
|
522 |
|
523 |
print('selected_dict: ', st.session_state.selected_dict)
|
524 |
+
|
525 |
+
# # save the user selection to database
|
526 |
# cursor = GALLERY_CONN.cursor()
|
527 |
+
# st.session_state.epoch['gallery'] += 1
|
528 |
+
# checkouttime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
529 |
+
# # for modelVersion_id in st.session_state.selected_dict[prompt_id]:
|
530 |
+
# for key, values in st.session_state.selected_dict.items():
|
531 |
+
# # print('key: ', key, 'values: ', values)
|
532 |
+
# key_tag = self.promptBook[self.promptBook['prompt_id'] == key]['tag'].unique()[0]
|
533 |
+
# for value in values:
|
534 |
+
# query = "INSERT INTO gallery_selections (username, timestamp, tag, prompt_id, modelVersion_id, checkouttime, epoch) VALUES ('{}', '{}', '{}', '{}', {}, '{}', {})".format(st.session_state.user_id[0], st.session_state.user_id[1], key_tag, key, value, checkouttime, st.session_state.epoch['gallery'])
|
535 |
+
# print(query)
|
536 |
+
# cursor.execute(query)
|
537 |
+
# GALLERY_CONN.commit()
|
538 |
# cursor.close()
|
539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
540 |
# get the largest epoch number of this user and prompt
|
541 |
cursor = GALLERY_CONN.cursor()
|
542 |
db_table = 'battle_results' if st.session_state.assigned_rank_mode=='Battle' else 'sort_results'
|
pages/Ranking.py
CHANGED
@@ -183,7 +183,7 @@ class RankingApp:
|
|
183 |
# query = "DELETE FROM sort_results WHERE username = %s AND timestamp = %s AND prompt_id = %s AND position1 = %s AND position2 = %s AND position3 = %s AND position4 = %s"
|
184 |
# curser.execute(query, (st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, result['position1'], result['position2'], result['position3'], result['position4']))
|
185 |
|
186 |
-
sorttime = datetime.
|
187 |
# handle the case where user press the 'prev' button
|
188 |
query = "DELETE FROM sort_results WHERE username = %s AND timestamp = %s AND prompt_id = %s AND epoch = %s"
|
189 |
curser.execute(query, (st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, st.session_state.epoch['ranking'][prompt_id]))
|
@@ -247,7 +247,7 @@ class RankingApp:
|
|
247 |
|
248 |
def next_battle(self, tag, prompt_id, image_ids, winner, curr_position, total_num):
|
249 |
loser = 'left' if winner == 'right' else 'right'
|
250 |
-
battletime = datetime.
|
251 |
|
252 |
curser = RANKING_CONN.cursor()
|
253 |
|
|
|
183 |
# query = "DELETE FROM sort_results WHERE username = %s AND timestamp = %s AND prompt_id = %s AND position1 = %s AND position2 = %s AND position3 = %s AND position4 = %s"
|
184 |
# curser.execute(query, (st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, result['position1'], result['position2'], result['position3'], result['position4']))
|
185 |
|
186 |
+
sorttime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
187 |
# handle the case where user press the 'prev' button
|
188 |
query = "DELETE FROM sort_results WHERE username = %s AND timestamp = %s AND prompt_id = %s AND epoch = %s"
|
189 |
curser.execute(query, (st.session_state.user_id[0], st.session_state.user_id[1], prompt_id, st.session_state.epoch['ranking'][prompt_id]))
|
|
|
247 |
|
248 |
def next_battle(self, tag, prompt_id, image_ids, winner, curr_position, total_num):
|
249 |
loser = 'left' if winner == 'right' else 'right'
|
250 |
+
battletime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
251 |
|
252 |
curser = RANKING_CONN.cursor()
|
253 |
|
pages/Summary.py
CHANGED
@@ -46,7 +46,7 @@ class DashboardApp:
|
|
46 |
comment = st.text_area('Please leave your comments here.', key='comment')
|
47 |
submit_feedback = st.form_submit_button('Submit Feedback')
|
48 |
if submit_feedback:
|
49 |
-
commenttime = datetime.
|
50 |
curser = RANKING_CONN.cursor()
|
51 |
# parse the comment to at most 300 to avoid SQL injection
|
52 |
for i in range(0, len(comment), 300):
|
@@ -190,7 +190,7 @@ class DashboardApp:
|
|
190 |
# print('latest_epoch',latest_epoch)
|
191 |
if latest_epoch is None or latest_epoch['epoch'] < st.session_state.epoch['summary'][tag_name]:
|
192 |
# save the current ranking results to the database
|
193 |
-
summarytime = datetime.
|
194 |
curser = RANKING_CONN.cursor()
|
195 |
for i in range(len(st.session_state.modelVersion_standings[tag])):
|
196 |
curser.execute(f"INSERT INTO summary_results (username, timestamp, tag, modelVersion_id, position, ranking_score, summarytime, epoch, customized) VALUES ('{st.session_state.user_id[0]}', '{st.session_state.user_id[1]}', '{tag_name}', '{st.session_state.modelVersion_standings[tag][i][0]}', {i+1}, {st.session_state.modelVersion_standings[tag][i][1]}, '{summarytime}', {st.session_state.epoch['summary'][tag_name]}, 0)")
|
@@ -201,7 +201,7 @@ class DashboardApp:
|
|
201 |
# insert the current before the target
|
202 |
st.session_state.modelVersion_standings[tag].insert(target, st.session_state.modelVersion_standings[tag].pop(current))
|
203 |
tag_name = 'overview' if tag == '%' else tag
|
204 |
-
summarytime = datetime.
|
205 |
curser = RANKING_CONN.cursor()
|
206 |
# clear the current user's ranking results
|
207 |
curser.execute(f"DELETE FROM summary_results WHERE username = '{st.session_state.user_id[0]}' AND timestamp = '{st.session_state.user_id[1]}' AND tag = '{tag_name}' AND epoch = {st.session_state.epoch['summary'][tag_name]}")
|
@@ -259,21 +259,6 @@ class DashboardApp:
|
|
259 |
self.sidebar(tags, mode)
|
260 |
self.leaderboard(tag, db_table)
|
261 |
|
262 |
-
# with st.sidebar:
|
263 |
-
# with st.form('overall_feedback'):
|
264 |
-
# comment = st.text_area('Please leave your comments here.', key='comment')
|
265 |
-
# submit_feedback = st.form_submit_button('Submit Feedback')
|
266 |
-
# if submit_feedback:
|
267 |
-
# commenttime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
268 |
-
# curser = RANKING_CONN.cursor()
|
269 |
-
# # parse the comment to at most 300 to avoid SQL injection
|
270 |
-
# for i in range(0, len(comment), 300):
|
271 |
-
# 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}')")
|
272 |
-
# RANKING_CONN.commit()
|
273 |
-
# curser.close()
|
274 |
-
#
|
275 |
-
# st.sidebar.info('🙏 **Thanks for your feedback! We will take it into consideration in our future work.**')
|
276 |
-
|
277 |
|
278 |
if __name__ == "__main__":
|
279 |
st.set_page_config(layout="wide")
|
|
|
46 |
comment = st.text_area('Please leave your comments here.', key='comment')
|
47 |
submit_feedback = st.form_submit_button('Submit Feedback')
|
48 |
if submit_feedback:
|
49 |
+
commenttime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
50 |
curser = RANKING_CONN.cursor()
|
51 |
# parse the comment to at most 300 to avoid SQL injection
|
52 |
for i in range(0, len(comment), 300):
|
|
|
190 |
# print('latest_epoch',latest_epoch)
|
191 |
if latest_epoch is None or latest_epoch['epoch'] < st.session_state.epoch['summary'][tag_name]:
|
192 |
# save the current ranking results to the database
|
193 |
+
summarytime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
194 |
curser = RANKING_CONN.cursor()
|
195 |
for i in range(len(st.session_state.modelVersion_standings[tag])):
|
196 |
curser.execute(f"INSERT INTO summary_results (username, timestamp, tag, modelVersion_id, position, ranking_score, summarytime, epoch, customized) VALUES ('{st.session_state.user_id[0]}', '{st.session_state.user_id[1]}', '{tag_name}', '{st.session_state.modelVersion_standings[tag][i][0]}', {i+1}, {st.session_state.modelVersion_standings[tag][i][1]}, '{summarytime}', {st.session_state.epoch['summary'][tag_name]}, 0)")
|
|
|
201 |
# insert the current before the target
|
202 |
st.session_state.modelVersion_standings[tag].insert(target, st.session_state.modelVersion_standings[tag].pop(current))
|
203 |
tag_name = 'overview' if tag == '%' else tag
|
204 |
+
summarytime = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
|
205 |
curser = RANKING_CONN.cursor()
|
206 |
# clear the current user's ranking results
|
207 |
curser.execute(f"DELETE FROM summary_results WHERE username = '{st.session_state.user_id[0]}' AND timestamp = '{st.session_state.user_id[1]}' AND tag = '{tag_name}' AND epoch = {st.session_state.epoch['summary'][tag_name]}")
|
|
|
259 |
self.sidebar(tags, mode)
|
260 |
self.leaderboard(tag, db_table)
|
261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
if __name__ == "__main__":
|
264 |
st.set_page_config(layout="wide")
|