Ricercar commited on
Commit
91213ec
1 Parent(s): 85335f2

remove gallery form

Browse files
Files changed (1) hide show
  1. pages/Gallery.py +30 -150
pages/Gallery.py CHANGED
@@ -151,7 +151,7 @@ def selection_panel(items):
151
 
152
  return items, info, col_num
153
 
154
- def sidebar(promptbook, images_db):
155
  with st.sidebar:
156
  prompt_tags = promptBook['tag'].unique()
157
  # sort tags by alphabetical order
@@ -203,11 +203,11 @@ def sidebar(promptbook, images_db):
203
 
204
  return prompt_tags, tag, prompt_id, items
205
 
206
- def app(promptbook, images_db):
207
  st.title('Model Visualization and Retrieval')
208
  st.write('This is a gallery of images generated by the models')
209
 
210
- prompt_tags, tag, prompt_id, items = sidebar(promptbook, images_db)
211
 
212
  # add safety check for some prompts
213
  safety_check = True
@@ -243,32 +243,32 @@ def app(promptbook, images_db):
243
  with dynamic_weight_panel[i]:
244
  btn = st.button(method, use_container_width=True, disabled=btn_disable, on_click=dynamic_weight, args=(prompt_id, items, method))
245
 
246
- with st.form(key=f'{prompt_id}'):
247
- # buttons = st.columns([1, 1, 1])
248
- buttons_space = st.columns([1, 1, 1, 1])
249
- gallery_space = st.empty()
250
-
251
- with buttons_space[0]:
252
- continue_btn = st.form_submit_button('Confirm Selection', use_container_width=True, type='primary')
253
- if continue_btn:
254
- submit_actions('Continue', prompt_id)
255
-
256
- with buttons_space[1]:
257
- select_btn = st.form_submit_button('Select All', use_container_width=True)
258
- if select_btn:
259
- submit_actions('Select', prompt_id)
260
-
261
- with buttons_space[2]:
262
- deselect_btn = st.form_submit_button('Deselect All', use_container_width=True)
263
- if deselect_btn:
264
- submit_actions('Deselect', prompt_id)
265
-
266
- with buttons_space[3]:
267
- refresh_btn = st.form_submit_button('Refresh', on_click=gallery_space.empty, use_container_width=True)
268
-
269
- with gallery_space.container():
270
- with st.spinner('Loading images...'):
271
- gallery_standard(items, col_num, info)
272
 
273
  def submit_actions(status, prompt_id):
274
  if status == 'Select':
@@ -436,124 +436,4 @@ if __name__ == "__main__":
436
  if 'selected_dict' not in st.session_state:
437
  st.session_state['selected_dict'] = {}
438
 
439
- # app(promptBook, images_ds)
440
-
441
- # specify sidebar
442
- with st.sidebar:
443
- prompt_tags = promptBook['tag'].unique()
444
- # sort tags by alphabetical order
445
- prompt_tags = np.sort(prompt_tags)[::-1]
446
-
447
- tag = st.selectbox('Select a tag', prompt_tags)
448
-
449
- items = promptBook[promptBook['tag'] == tag].reset_index(drop=True)
450
-
451
- prompts = np.sort(items['prompt'].unique())[::-1]
452
-
453
- selected_prompt = st.selectbox('Select prompt', prompts)
454
-
455
- items = items[items['prompt'] == selected_prompt].reset_index(drop=True)
456
- prompt_id = items['prompt_id'].unique()[0]
457
- note = items['note'].unique()[0]
458
-
459
- # show source
460
- if isinstance(note, str):
461
- if note.isdigit():
462
- st.caption(f"`Source: civitai`")
463
- else:
464
- st.caption(f"`Source: {note}`")
465
- else:
466
- st.caption("`Source: Parti-prompts`")
467
-
468
- # show image metadata
469
- image_metadatas = ['prompt_id', 'prompt', 'negativePrompt', 'sampler', 'cfgScale', 'size', 'seed']
470
- for key in image_metadatas:
471
- label = ' '.join(key.split('_')).capitalize()
472
- st.write(f"**{label}**")
473
- if items[key][0] == ' ':
474
- st.write('`None`')
475
- else:
476
- st.caption(f"{items[key][0]}")
477
-
478
- # for note as civitai image id, add civitai reference
479
- if isinstance(note, str) and note.isdigit():
480
- try:
481
- st.write(f'**[Civitai Reference](https://civitai.com/images/{note})**')
482
- res = requests.get(f'https://civitai.com/images/{note}')
483
- # st.write(res.text)
484
- soup = BeautifulSoup(res.text, 'html.parser')
485
- image_section = soup.find('div', {'class': 'mantine-12rlksp'})
486
- image_url = image_section.find('img')['src']
487
- st.image(image_url, use_column_width=True)
488
- except:
489
- pass
490
-
491
-
492
- # move things out of app()
493
- st.title('Model Visualization and Retrieval')
494
- st.write('This is a gallery of images generated by the models')
495
-
496
- # add safety check for some prompts
497
- safety_check = True
498
- unsafe_prompts = {}
499
- # initialize unsafe prompts
500
- for prompt_tag in prompt_tags:
501
- unsafe_prompts[prompt_tag] = []
502
- # manually add unsafe prompts
503
- unsafe_prompts['world knowledge'] = [83]
504
- # unsafe_prompts['art'] = [23]
505
- unsafe_prompts['abstract'] = [1, 3]
506
- # unsafe_prompts['food'] = [34]
507
-
508
- if int(prompt_id.item()) in unsafe_prompts[tag]:
509
- st.warning('This prompt may contain unsafe content. They might be offensive, depressing, or sexual.')
510
- safety_check = st.checkbox(
511
- 'I understand that this prompt may contain unsafe content. Show these images anyway.',
512
- key=f'{prompt_id}')
513
-
514
- if safety_check:
515
- items, info, col_num = selection_panel(items)
516
-
517
- if 'selected_dict' in st.session_state:
518
- st.write('checked: ', str(st.session_state.selected_dict.get(prompt_id, [])))
519
- dynamic_weight_options = ['Grid Search', 'SVM', 'Greedy']
520
- dynamic_weight_panel = st.columns(len(dynamic_weight_options))
521
-
522
- if len(st.session_state.selected_dict.get(prompt_id, [])) > 0:
523
- btn_disable = False
524
- else:
525
- btn_disable = True
526
-
527
- for i in range(len(dynamic_weight_options)):
528
- method = dynamic_weight_options[i]
529
- with dynamic_weight_panel[i]:
530
- btn = st.button(method, use_container_width=True, disabled=btn_disable, on_click=dynamic_weight,
531
- args=(prompt_id, items, method))
532
-
533
- with st.form(key=f'{prompt_id}'):
534
- # buttons = st.columns([1, 1, 1])
535
- buttons_space = st.columns([1, 1, 1, 1])
536
- gallery_space = st.empty()
537
-
538
- with buttons_space[0]:
539
- continue_btn = st.form_submit_button('Confirm Selection', use_container_width=True, type='primary')
540
- if continue_btn:
541
- submit_actions('Continue', prompt_id)
542
-
543
- with buttons_space[1]:
544
- select_btn = st.form_submit_button('Select All', use_container_width=True)
545
- if select_btn:
546
- submit_actions('Select', prompt_id)
547
-
548
- with buttons_space[2]:
549
- deselect_btn = st.form_submit_button('Deselect All', use_container_width=True)
550
- if deselect_btn:
551
- submit_actions('Deselect', prompt_id)
552
-
553
- with buttons_space[3]:
554
- refresh_btn = st.form_submit_button('Refresh', on_click=gallery_space.empty,
555
- use_container_width=True)
556
-
557
- with gallery_space.container():
558
- with st.spinner('Loading images...'):
559
- gallery_standard(items, col_num, info)
 
151
 
152
  return items, info, col_num
153
 
154
+ def sidebar(promptBook, images_ds):
155
  with st.sidebar:
156
  prompt_tags = promptBook['tag'].unique()
157
  # sort tags by alphabetical order
 
203
 
204
  return prompt_tags, tag, prompt_id, items
205
 
206
+ def app(promptBook, images_ds):
207
  st.title('Model Visualization and Retrieval')
208
  st.write('This is a gallery of images generated by the models')
209
 
210
+ prompt_tags, tag, prompt_id, items = sidebar(promptBook, images_ds)
211
 
212
  # add safety check for some prompts
213
  safety_check = True
 
243
  with dynamic_weight_panel[i]:
244
  btn = st.button(method, use_container_width=True, disabled=btn_disable, on_click=dynamic_weight, args=(prompt_id, items, method))
245
 
246
+ # with st.form(key=f'{prompt_id}'):
247
+ # # buttons = st.columns([1, 1, 1])
248
+ # buttons_space = st.columns([1, 1, 1, 1])
249
+ # gallery_space = st.empty()
250
+ #
251
+ # with buttons_space[0]:
252
+ # continue_btn = st.form_submit_button('Confirm Selection', use_container_width=True, type='primary')
253
+ # if continue_btn:
254
+ # submit_actions('Continue', prompt_id)
255
+ #
256
+ # with buttons_space[1]:
257
+ # select_btn = st.form_submit_button('Select All', use_container_width=True)
258
+ # if select_btn:
259
+ # submit_actions('Select', prompt_id)
260
+ #
261
+ # with buttons_space[2]:
262
+ # deselect_btn = st.form_submit_button('Deselect All', use_container_width=True)
263
+ # if deselect_btn:
264
+ # submit_actions('Deselect', prompt_id)
265
+ #
266
+ # with buttons_space[3]:
267
+ # refresh_btn = st.form_submit_button('Refresh', on_click=gallery_space.empty, use_container_width=True)
268
+ #
269
+ # with gallery_space.container():
270
+ # with st.spinner('Loading images...'):
271
+ # gallery_standard(items, col_num, info)
272
 
273
  def submit_actions(status, prompt_id):
274
  if status == 'Select':
 
436
  if 'selected_dict' not in st.session_state:
437
  st.session_state['selected_dict'] = {}
438
 
439
+ app(promptBook, images_ds)