Spaces:
Sleeping
Sleeping
test using aws s3 as image host
Browse files- pages/Gallery.py +28 -33
- pages/Ranking.py +25 -1
- pages/__pycache__/Gallery.cpython-39.pyc +0 -0
pages/Gallery.py
CHANGED
@@ -15,33 +15,6 @@ from sklearn.svm import LinearSVC
|
|
15 |
SCORE_NAME_MAPPING = {'clip': 'clip_score', 'rank': 'msq_score', 'pop': 'model_download_count'}
|
16 |
|
17 |
|
18 |
-
# hist_data = pd.DataFrame(np.random.normal(42, 10, (200, 1)), columns=["x"])
|
19 |
-
@st.cache_resource
|
20 |
-
def altair_histogram(hist_data, sort_by, mini, maxi):
|
21 |
-
brushed = alt.selection_interval(encodings=['x'], name="brushed")
|
22 |
-
|
23 |
-
chart = (
|
24 |
-
alt.Chart(hist_data)
|
25 |
-
.mark_bar(opacity=0.7, cornerRadius=2)
|
26 |
-
.encode(alt.X(f"{sort_by}:Q", bin=alt.Bin(maxbins=25)), y="count()")
|
27 |
-
# .add_selection(brushed)
|
28 |
-
# .properties(width=800, height=300)
|
29 |
-
)
|
30 |
-
|
31 |
-
# Create a transparent rectangle for highlighting the range
|
32 |
-
highlight = (
|
33 |
-
alt.Chart(pd.DataFrame({'x1': [mini], 'x2': [maxi]}))
|
34 |
-
.mark_rect(opacity=0.3)
|
35 |
-
.encode(x='x1', x2='x2')
|
36 |
-
# .properties(width=800, height=300)
|
37 |
-
)
|
38 |
-
|
39 |
-
# Layer the chart and the highlight rectangle
|
40 |
-
layered_chart = alt.layer(chart, highlight)
|
41 |
-
|
42 |
-
return layered_chart
|
43 |
-
|
44 |
-
|
45 |
class GalleryApp:
|
46 |
def __init__(self, promptBook, images_ds):
|
47 |
self.promptBook = promptBook
|
@@ -58,7 +31,8 @@ class GalleryApp:
|
|
58 |
if idx + j < len(items):
|
59 |
with cols[j]:
|
60 |
# show image
|
61 |
-
image = self.images_ds[items.iloc[idx + j]['row_idx'].item()]['image']
|
|
|
62 |
st.image(image, use_column_width=True)
|
63 |
|
64 |
# handel checkbox information
|
@@ -404,7 +378,31 @@ class GalleryApp:
|
|
404 |
st.session_state.score_weights[0: 3] = optimal_weight
|
405 |
|
406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
|
|
|
408 |
|
409 |
|
410 |
@st.cache_data
|
@@ -415,16 +413,13 @@ def load_hf_dataset():
|
|
415 |
# load from huggingface
|
416 |
roster = pd.DataFrame(load_dataset('NYUSHPRP/ModelCofferRoster', split='train'))
|
417 |
promptBook = pd.DataFrame(load_dataset('NYUSHPRP/ModelCofferMetadata', split='train'))
|
418 |
-
images_ds = load_from_disk(os.path.join(os.getcwd(), 'data', 'promptbook'))
|
|
|
419 |
|
420 |
# process dataset
|
421 |
roster = roster[['model_id', 'model_name', 'modelVersion_id', 'modelVersion_name',
|
422 |
'model_download_count']].drop_duplicates().reset_index(drop=True)
|
423 |
|
424 |
-
# # add 'checked' column to promptBook if not exist
|
425 |
-
# if 'checked' not in promptBook.columns:
|
426 |
-
# promptBook.loc[:, 'checked'] = False
|
427 |
-
|
428 |
# add 'custom_score_weights' column to promptBook if not exist
|
429 |
if 'weighted_score_sum' not in promptBook.columns:
|
430 |
promptBook.loc[:, 'weighted_score_sum'] = 0
|
|
|
15 |
SCORE_NAME_MAPPING = {'clip': 'clip_score', 'rank': 'msq_score', 'pop': 'model_download_count'}
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
class GalleryApp:
|
19 |
def __init__(self, promptBook, images_ds):
|
20 |
self.promptBook = promptBook
|
|
|
31 |
if idx + j < len(items):
|
32 |
with cols[j]:
|
33 |
# show image
|
34 |
+
# image = self.images_ds[items.iloc[idx + j]['row_idx'].item()]['image']
|
35 |
+
image = f"https://modelcofferbucket.s3.us-east-2.amazonaws.com/{items.iloc[idx + j]['image_id']}.png"
|
36 |
st.image(image, use_column_width=True)
|
37 |
|
38 |
# handel checkbox information
|
|
|
378 |
st.session_state.score_weights[0: 3] = optimal_weight
|
379 |
|
380 |
|
381 |
+
# hist_data = pd.DataFrame(np.random.normal(42, 10, (200, 1)), columns=["x"])
|
382 |
+
@st.cache_resource
|
383 |
+
def altair_histogram(hist_data, sort_by, mini, maxi):
|
384 |
+
brushed = alt.selection_interval(encodings=['x'], name="brushed")
|
385 |
+
|
386 |
+
chart = (
|
387 |
+
alt.Chart(hist_data)
|
388 |
+
.mark_bar(opacity=0.7, cornerRadius=2)
|
389 |
+
.encode(alt.X(f"{sort_by}:Q", bin=alt.Bin(maxbins=25)), y="count()")
|
390 |
+
# .add_selection(brushed)
|
391 |
+
# .properties(width=800, height=300)
|
392 |
+
)
|
393 |
+
|
394 |
+
# Create a transparent rectangle for highlighting the range
|
395 |
+
highlight = (
|
396 |
+
alt.Chart(pd.DataFrame({'x1': [mini], 'x2': [maxi]}))
|
397 |
+
.mark_rect(opacity=0.3)
|
398 |
+
.encode(x='x1', x2='x2')
|
399 |
+
# .properties(width=800, height=300)
|
400 |
+
)
|
401 |
+
|
402 |
+
# Layer the chart and the highlight rectangle
|
403 |
+
layered_chart = alt.layer(chart, highlight)
|
404 |
|
405 |
+
return layered_chart
|
406 |
|
407 |
|
408 |
@st.cache_data
|
|
|
413 |
# load from huggingface
|
414 |
roster = pd.DataFrame(load_dataset('NYUSHPRP/ModelCofferRoster', split='train'))
|
415 |
promptBook = pd.DataFrame(load_dataset('NYUSHPRP/ModelCofferMetadata', split='train'))
|
416 |
+
# images_ds = load_from_disk(os.path.join(os.getcwd(), 'data', 'promptbook'))
|
417 |
+
images_ds = None # set to None for now since we use s3 bucket to store images
|
418 |
|
419 |
# process dataset
|
420 |
roster = roster[['model_id', 'model_name', 'modelVersion_id', 'modelVersion_name',
|
421 |
'model_download_count']].drop_duplicates().reset_index(drop=True)
|
422 |
|
|
|
|
|
|
|
|
|
423 |
# add 'custom_score_weights' column to promptBook if not exist
|
424 |
if 'weighted_score_sum' not in promptBook.columns:
|
425 |
promptBook.loc[:, 'weighted_score_sum'] = 0
|
pages/Ranking.py
CHANGED
@@ -1,9 +1,33 @@
|
|
1 |
-
import streamlit as st
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
|
|
|
|
|
|
4 |
from streamlit_extras.switch_page_button import switch_page
|
|
|
5 |
from pages.Gallery import load_hf_dataset
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
if __name__ == "__main__":
|
8 |
st.set_page_config(page_title="Personal Image Ranking", page_icon="🎖️️", layout="wide")
|
9 |
|
|
|
|
|
1 |
import numpy as np
|
2 |
import pandas as pd
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
from streamlit_elements import elements, mui, html, dashboard, nivo
|
6 |
from streamlit_extras.switch_page_button import switch_page
|
7 |
+
|
8 |
from pages.Gallery import load_hf_dataset
|
9 |
|
10 |
+
|
11 |
+
class RankingApp():
|
12 |
+
def __init__(self, promptBook, images_ds):
|
13 |
+
self.promptBook = promptBook
|
14 |
+
self.images_ds = images_ds
|
15 |
+
|
16 |
+
def draggable_images(self, items, layout='vertical'):
|
17 |
+
pass
|
18 |
+
|
19 |
+
def sidebar(self):
|
20 |
+
with st.sidebar:
|
21 |
+
prompt_tags = self.promptBook['tag'].unique()
|
22 |
+
|
23 |
+
|
24 |
+
def app(self):
|
25 |
+
st.title('Personal Image Ranking')
|
26 |
+
st.write('Here you can test out your selected images with any prompt you like.')
|
27 |
+
|
28 |
+
prompt_tags, tag, prompt_id, items= self.sidebar()
|
29 |
+
|
30 |
+
|
31 |
if __name__ == "__main__":
|
32 |
st.set_page_config(page_title="Personal Image Ranking", page_icon="🎖️️", layout="wide")
|
33 |
|
pages/__pycache__/Gallery.cpython-39.pyc
CHANGED
Binary files a/pages/__pycache__/Gallery.cpython-39.pyc and b/pages/__pycache__/Gallery.cpython-39.pyc differ
|
|