multimodalart HF staff commited on
Commit
bc8bb52
1 Parent(s): 46108bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -334,15 +334,19 @@ help_text = """
334
  """
335
 
336
  with gr.Blocks(css="style.css") as demo:
337
-
338
- def remove_concept(sega_concepts_counter,edit_concept1,edit_concept2,edit_concept3):
339
- if(not sega_concepts_counter):
340
- sega_concepts_counter = len([concept for concept in [edit_concept1, edit_concept2, edit_concept3] if concept != ''])-1
341
- else:
342
- sega_concepts_counter -= 1
343
  rows_visibility = [gr.update(visible=False) for _ in range(4)]
344
- rows_visibility[sega_concepts_counter] = gr.update(visible=True)
345
-
 
 
 
 
346
  row1_visibility, row2_visibility, row3_visibility, row4_visibility = rows_visibility
347
 
348
  guidance_scale_label = "Concept Guidance Scale"
@@ -603,17 +607,23 @@ with gr.Blocks(css="style.css") as demo:
603
  #neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
604
  #neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
605
  #neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
606
- add_1.click(fn = update_display_concept, inputs=[add_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
607
- add_2.click(fn = update_display_concept, inputs=[add_2, edit_concept_2, neg_guidance_2, sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3, sega_concepts_counter],queue=False)
608
- add_3.click(fn = update_display_concept, inputs=[add_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3,row3, row4, sega_concepts_counter],queue=False)
609
 
610
  remove_1.click(fn = update_display_concept, inputs=[remove_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
611
  remove_2.click(fn = update_display_concept, inputs=[remove_2, edit_concept_2, neg_guidance_2 ,sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3,sega_concepts_counter],queue=False)
612
  remove_3.click(fn = update_display_concept, inputs=[remove_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3, row3, row4, sega_concepts_counter],queue=False)
613
 
614
- remove_concept1.click(fn = remove_concept, inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs= [box1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1, dropdown1, row1, row2, row3, row4, sega_concepts_counter],queue=False)
615
- remove_concept2.click(fn = remove_concept, inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=[box2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2 , dropdown2, row1, row2, row3, row4, sega_concepts_counter],queue=False)
616
- remove_concept3.click(fn = remove_concept, inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=[box3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3, dropdown3, row1, row2, row3, row4, sega_concepts_counter],queue=False)
 
 
 
 
 
 
617
 
618
  #add_concept_button.click(fn = update_display_concept, inputs=sega_concepts_counter,
619
  # outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
@@ -788,4 +798,4 @@ with gr.Blocks(css="style.css") as demo:
788
 
789
 
790
  demo.queue()
791
- demo.launch()
 
334
  """
335
 
336
  with gr.Blocks(css="style.css") as demo:
337
+ def update_counter(sega_concepts_counter, concept1, concept2, concept3):
338
+ if sega_concepts_counter == "":
339
+ sega_concepts_counter = sum(1 for concept in (concept1, concept2, concept3) if concept != '')
340
+ return sega_concepts_counter
341
+ def remove_concept(sega_concepts_counter, row_triggered):
342
+ sega_concepts_counter -= 1
343
  rows_visibility = [gr.update(visible=False) for _ in range(4)]
344
+
345
+ if(row_triggered-1 > sega_concepts_counter):
346
+ rows_visibility[sega_concepts_counter] = gr.update(visible=True)
347
+ else:
348
+ rows_visibility[row_triggered-1] = gr.update(visible=True)
349
+
350
  row1_visibility, row2_visibility, row3_visibility, row4_visibility = rows_visibility
351
 
352
  guidance_scale_label = "Concept Guidance Scale"
 
607
  #neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
608
  #neg_guidance_2.change(fn = update_label, inputs=[neg_guidance_2], outputs=[add_2])
609
  #neg_guidance_3.change(fn = update_label, inputs=[neg_guidance_3], outputs=[add_3])
610
+ add_1.click(fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(fn = update_display_concept, inputs=[add_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
611
+ add_2.click(fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(fn = update_display_concept, inputs=[add_2, edit_concept_2, neg_guidance_2, sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3, sega_concepts_counter],queue=False)
612
+ add_3.click(fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(fn = update_display_concept, inputs=[add_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3,row3, row4, sega_concepts_counter],queue=False)
613
 
614
  remove_1.click(fn = update_display_concept, inputs=[remove_1, edit_concept_1, neg_guidance_1, sega_concepts_counter], outputs=[box1, concept_1, guidnace_scale_1,neg_guidance_1,row1, row2, sega_concepts_counter],queue=False)
615
  remove_2.click(fn = update_display_concept, inputs=[remove_2, edit_concept_2, neg_guidance_2 ,sega_concepts_counter], outputs=[box2, concept_2, guidnace_scale_2,neg_guidance_2,row2, row3,sega_concepts_counter],queue=False)
616
  remove_3.click(fn = update_display_concept, inputs=[remove_3, edit_concept_3, neg_guidance_3, sega_concepts_counter], outputs=[box3, concept_3, guidnace_scale_3,neg_guidance_3, row3, row4, sega_concepts_counter],queue=False)
617
 
618
+ remove_concept1.click(
619
+ fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(
620
+ fn = remove_concept, inputs=[sega_concepts_counter,gr.State(1)], outputs= [box1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1, dropdown1, row1, row2, row3, row4, sega_concepts_counter],queue=False)
621
+ remove_concept2.click(
622
+ fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(
623
+ fn = remove_concept, inputs=[sega_concepts_counter,gr.State(2)], outputs=[box2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2 , dropdown2, row1, row2, row3, row4, sega_concepts_counter],queue=False)
624
+ remove_concept3.click(
625
+ fn=update_counter,inputs=[sega_concepts_counter,edit_concept_1,edit_concept_2,edit_concept_3], outputs=sega_concepts_counter).then(
626
+ fn = remove_concept,inputs=[sega_concepts_counter,gr.State(3)], outputs=[box3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3, dropdown3, row1, row2, row3, row4, sega_concepts_counter],queue=False)
627
 
628
  #add_concept_button.click(fn = update_display_concept, inputs=sega_concepts_counter,
629
  # outputs= [row2, row2_advanced, row3, row3_advanced, add_concept_button, sega_concepts_counter], queue = False)
 
798
 
799
 
800
  demo.queue()
801
+ demo.launch(share=True)