Ricercar commited on
Commit
f60c57b
·
1 Parent(s): f5fb5a2

allow shuffling in gallery

Browse files
Files changed (2) hide show
  1. pages/Gallery.py +23 -8
  2. pages/Summary.py +1 -1
pages/Gallery.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
 
5
  import altair as alt
6
  import extra_streamlit_components as stx
 
7
  import numpy as np
8
  import pandas as pd
9
  import streamlit as st
@@ -212,6 +213,8 @@ class GalleryApp:
212
 
213
  prompts = np.sort(items['prompt'].unique())[::1].tolist()
214
 
 
 
215
  # selt focus prompt index if exists
216
  if st.session_state.gallery_focus['prompt'] is None or tag != st.session_state.gallery_focus['tag']:
217
  prompt_focus_idx = 0
@@ -221,17 +224,21 @@ class GalleryApp:
221
  # st.caption('Select a prompt')
222
  subset_selector = st.columns([3, 1])
223
  with subset_selector[0]:
 
 
 
224
 
225
- # add coloring to prompt based on selection
226
- prompts_tobe_colored = self.promptBook[self.promptBook['prompt_id'].isin(st.session_state.selected_dict.keys())]['prompt'].unique()
227
- colored_prompts = self.text_coloring_add(prompts_tobe_colored, prompts, color_name='')
 
228
 
229
- selected_prompt = selectbox('Select prompt', colored_prompts, key=f'prompt_{tag}', no_selection_label='---', label_visibility='collapsed', index=prompt_focus_idx)
230
 
231
- # remove coloring from prompt
232
- selected_prompt = self.text_coloring_remove(selected_prompt)
233
- print('selected_prompt: ', selected_prompt)
234
- st.session_state.prompt_idx_last_time = prompts.index(selected_prompt) if selected_prompt else 0
235
 
236
  if selected_prompt is None:
237
  # st.markdown(':orange[Please select a prompt above👆]')
@@ -301,6 +308,14 @@ class GalleryApp:
301
 
302
  self.checkout_mode(tag, items)
303
 
 
 
 
 
 
 
 
 
304
  def graph_mode(self, prompt_id, items):
305
  graph_cols = st.columns([3, 1])
306
  # prompt = st.chat_input(f"Selected model version ids: {str(st.session_state.selected_dict.get(prompt_id, []))}",
 
4
 
5
  import altair as alt
6
  import extra_streamlit_components as stx
7
+ import random
8
  import numpy as np
9
  import pandas as pd
10
  import streamlit as st
 
213
 
214
  prompts = np.sort(items['prompt'].unique())[::1].tolist()
215
 
216
+ # print('prompts: ', prompts, 'tags: ', prompt_tags)
217
+
218
  # selt focus prompt index if exists
219
  if st.session_state.gallery_focus['prompt'] is None or tag != st.session_state.gallery_focus['tag']:
220
  prompt_focus_idx = 0
 
224
  # st.caption('Select a prompt')
225
  subset_selector = st.columns([3, 1])
226
  with subset_selector[0]:
227
+ selector_bar = st.columns([1, 15])
228
+ with selector_bar[0]:
229
+ shuffle = st.button('🎲', key='prompt_shuffle', on_click=self.random_gallery_focus, args=(prompt_tags,), use_container_width=True)
230
 
231
+ with selector_bar[-1]:
232
+ # add coloring to prompt based on selection
233
+ prompts_tobe_colored = self.promptBook[self.promptBook['prompt_id'].isin(st.session_state.selected_dict.keys())]['prompt'].unique()
234
+ colored_prompts = self.text_coloring_add(prompts_tobe_colored, prompts, color_name='✅')
235
 
236
+ selected_prompt = selectbox('Select prompt', colored_prompts, key=f'prompt_{tag}', no_selection_label='---', label_visibility='collapsed', index=prompt_focus_idx)
237
 
238
+ # remove coloring from prompt
239
+ selected_prompt = self.text_coloring_remove(selected_prompt)
240
+ print('selected_prompt: ', selected_prompt)
241
+ st.session_state.prompt_idx_last_time = prompts.index(selected_prompt) if selected_prompt else 0
242
 
243
  if selected_prompt is None:
244
  # st.markdown(':orange[Please select a prompt above👆]')
 
308
 
309
  self.checkout_mode(tag, items)
310
 
311
+
312
+ def random_gallery_focus(self, tags):
313
+ st.session_state.gallery_focus['tag'] = random.choice(tags)
314
+ # st.session_state.gallery_focus['prompt'] = random.choice(prompts)
315
+ prompts = self.promptBook[self.promptBook['tag'] == st.session_state.gallery_focus['tag']]['prompt'].unique()
316
+ st.session_state.gallery_focus['prompt'] = random.choice(prompts)
317
+
318
+
319
  def graph_mode(self, prompt_id, items):
320
  graph_cols = st.columns([3, 1])
321
  # prompt = st.chat_input(f"Selected model version ids: {str(st.session_state.selected_dict.get(prompt_id, []))}",
pages/Summary.py CHANGED
@@ -233,7 +233,7 @@ class DashboardApp:
233
  st.info(f'No rankings are finished with {mode} mode yet.')
234
 
235
  else:
236
- tags = tags[0:1] if len(tags) == 2 else tags
237
  tag = st.radio('Select a tag', tags, index=0, horizontal=True, label_visibility='collapsed')
238
  self.sidebar(tags, mode)
239
  self.leaderboard(tag, db_table)
 
233
  st.info(f'No rankings are finished with {mode} mode yet.')
234
 
235
  else:
236
+ tags = tags[1:2] if len(tags) == 2 else tags
237
  tag = st.radio('Select a tag', tags, index=0, horizontal=True, label_visibility='collapsed')
238
  self.sidebar(tags, mode)
239
  self.leaderboard(tag, db_table)