jennysun commited on
Commit
95bed10
Β·
1 Parent(s): 5e3ac87

Clean Code: Remove print statements and commented out trial/test debugging code

Browse files
Files changed (1) hide show
  1. app.py +8 -70
app.py CHANGED
@@ -19,7 +19,6 @@ import sys
19
 
20
  import os
21
  import openai
22
- from gradio.components import Textbox, Text
23
 
24
  sys.tracebacklimit = 0
25
 
@@ -212,7 +211,9 @@ def inference(task, language_instruction, grounding_instruction, inpainting_boxe
212
  inpainting_boxes_nodrop = inpainting_boxes_nodrop,
213
  )
214
 
215
- print("instruction values", instruction)
 
 
216
 
217
  get_model = partial(instance.get_model,
218
  batch_size=batch_size,
@@ -308,7 +309,7 @@ Please draw boxes accordingly on the sketch pad.""".format(len(boxes), len(groun
308
  boxes = boxes.tolist()
309
  grounding_instruction = json.dumps({obj: box for obj,box in zip(grounding_texts, boxes) if obj != 'auto'})
310
 
311
- # Try to remove append grounding
312
  # if append_grounding:
313
  # language_instruction = auto_append_grounding(language_instruction, grounding_texts)
314
 
@@ -507,17 +508,6 @@ prompt_base = 'Separate the subjects in this sentence by semicolons. For example
507
  original_input = ""
508
  separated_subjects = ""
509
 
510
- # language_instruction = gr.Textbox(
511
- # label="Language Instruction by User",
512
- # value="2 horses running",
513
- # visible=False
514
- # )
515
- # grounding_instruction = gr.Textbox(
516
- # label="Subjects in image (Separated by semicolon)",
517
- # value="horse; horse",
518
- # visible=False
519
- # )
520
-
521
  def separate_subjects(input_text):
522
  prompt = prompt_base + input_text
523
  response = openai.Completion.create(
@@ -547,7 +537,7 @@ with Blocks(
547
  image_scale = gr.Number(value=0, elem_id="image_scale", visible=False)
548
  new_image_trigger = gr.Number(value=0, visible=False)
549
 
550
- # UNCOMMENT THIS WHEN YOU WANT TO TOGGLE INPAINTING OPTION
551
  task = gr.Radio(
552
  choices=["Version 1: Single Layer", 'Version 2: Inpainting w/ Multiple Layers'],
553
  type="value",
@@ -556,17 +546,6 @@ with Blocks(
556
  visible=False,
557
  )
558
 
559
- # language_instruction = gr.Textbox(
560
- # label="Enter your prompt here",
561
- # )
562
- # grounding_instruction = gr.Textbox(
563
- # label="Grounding instruction (Separated by semicolon)",
564
- # )
565
- # grounding_instruction = separate_subjects(language_instruction.value)
566
- # print(f"The user entered: {language_instruction}")
567
- # print(f"Our function gave: {grounding_instruction}")
568
-
569
- # EXPERIMENTING:
570
  with gr.Column():
571
  user_input = gr.Text(label="Enter your prompt here:")
572
  gr.Examples(["2 horses running", "A cowboy and ninja fighting", "An apple and an orange on a table"], inputs=[user_input])
@@ -575,44 +554,11 @@ with Blocks(
575
  with gr.Column():
576
  separated_text = gr.Text(label="Subjects Separated by Semicolon")
577
  btn.click(separate_subjects, inputs=[user_input], outputs=[separated_text])
578
- # language_instruction = gr.Textbox(
579
- # label="Language Instruction by User",
580
- # value=seed,
581
- # visible=False
582
- # )
583
- print("separated_text", separated_text)
584
  language_instruction=user_input
585
  grounding_instruction=separated_text
586
- print("language_instruction after blocks: ", language_instruction)
587
- print("grounding_instruction after blocks: ", language_instruction)
588
- # language_instruction.value = seed
589
- # grounding_instruction.value = separated_text
590
-
591
- ####################
592
- # language_instruction = gr.Textbox(
593
- # label="Enter your prompt here",
594
- # )
595
- # original_input = language_instruction.value
596
- # start_btn = gr.Button('Start')
597
- # start_btn.click(update_grounding_instruction)
598
- # print("separated subjects 2:", separated_subjects)
599
-
600
- # language_instruction = gr.Textbox(
601
- # label="just needs to be here",
602
- # value=seed,
603
- # visible=False
604
- # )
605
- # grounding_instruction = gr.Textbox(
606
- # label="Subjects in image (Separated by semicolon)",
607
- # value=separated_text,
608
- # visible=False
609
- # )
610
-
611
- # print("Language instruction Value:", language_instruction.value)
612
- # print("Grounding instruction:", grounding_instruction.value)
613
-
614
-
615
- ####################
616
 
617
  with gr.Row():
618
  sketch_pad = ImageMask(label="Sketch Pad", elem_id="img2img_image")
@@ -742,14 +688,6 @@ with Blocks(
742
  outputs=[out_gen_1, out_gen_2, out_gen_3, out_gen_4, state],
743
  queue=True
744
  )
745
- # start_btn.click(
746
- # update_grounding_instruction,
747
- # # inputs=[
748
- # # original_input,
749
- # # ],
750
- # # outputs=[separated_subjects],
751
- # # queue=True
752
- # )
753
  sketch_pad_resize_trigger.change(
754
  None,
755
  None,
 
19
 
20
  import os
21
  import openai
 
22
 
23
  sys.tracebacklimit = 0
24
 
 
211
  inpainting_boxes_nodrop = inpainting_boxes_nodrop,
212
  )
213
 
214
+ # for debugging purposes, uncomment to view all instruction values
215
+ # fed into the model
216
+ # print("instruction values", instruction)
217
 
218
  get_model = partial(instance.get_model,
219
  batch_size=batch_size,
 
309
  boxes = boxes.tolist()
310
  grounding_instruction = json.dumps({obj: box for obj,box in zip(grounding_texts, boxes) if obj != 'auto'})
311
 
312
+ # Removing append grounding
313
  # if append_grounding:
314
  # language_instruction = auto_append_grounding(language_instruction, grounding_texts)
315
 
 
508
  original_input = ""
509
  separated_subjects = ""
510
 
 
 
 
 
 
 
 
 
 
 
 
511
  def separate_subjects(input_text):
512
  prompt = prompt_base + input_text
513
  response = openai.Completion.create(
 
537
  image_scale = gr.Number(value=0, elem_id="image_scale", visible=False)
538
  new_image_trigger = gr.Number(value=0, visible=False)
539
 
540
+ # Make Visible True if desired to include inpainting
541
  task = gr.Radio(
542
  choices=["Version 1: Single Layer", 'Version 2: Inpainting w/ Multiple Layers'],
543
  type="value",
 
546
  visible=False,
547
  )
548
 
 
 
 
 
 
 
 
 
 
 
 
549
  with gr.Column():
550
  user_input = gr.Text(label="Enter your prompt here:")
551
  gr.Examples(["2 horses running", "A cowboy and ninja fighting", "An apple and an orange on a table"], inputs=[user_input])
 
554
  with gr.Column():
555
  separated_text = gr.Text(label="Subjects Separated by Semicolon")
556
  btn.click(separate_subjects, inputs=[user_input], outputs=[separated_text])
557
+
558
+ # set the language and grounding instruction to user input
559
+ # and separated subjects, respectively
 
 
 
560
  language_instruction=user_input
561
  grounding_instruction=separated_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
562
 
563
  with gr.Row():
564
  sketch_pad = ImageMask(label="Sketch Pad", elem_id="img2img_image")
 
688
  outputs=[out_gen_1, out_gen_2, out_gen_3, out_gen_4, state],
689
  queue=True
690
  )
 
 
 
 
 
 
 
 
691
  sketch_pad_resize_trigger.change(
692
  None,
693
  None,