Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -243,7 +243,7 @@ def uploadNote(prompt,num_inference_steps,guidance_scale,timestamp):
|
|
243 |
f.write(f"Model UNET: ford442/RealVisXL_V5.0_BF16 \n")
|
244 |
upload_to_ftp(filename)
|
245 |
|
246 |
-
def captioning(img,
|
247 |
'''prompts_array = [
|
248 |
"Adjectives describing this scene are:",
|
249 |
# "The color scheme of this image is",
|
@@ -310,8 +310,17 @@ def captioning(img, prompts_array):
|
|
310 |
generated_textb = generated_textb.replace(cap_prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()
|
311 |
output_prompt.append(generated_text)
|
312 |
print(generated_text)
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
for prompt in prompts_array:
|
316 |
inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
|
317 |
#with torch.no_grad():
|
@@ -350,7 +359,7 @@ def captioning(img, prompts_array):
|
|
350 |
response_text = generated_texta.replace(generated_text, "").strip()
|
351 |
print(f"{response_text}\n")
|
352 |
output_prompt.append(response_text)
|
353 |
-
|
354 |
output_prompt = " ".join(output_prompt)
|
355 |
return output_prompt, generated_textb
|
356 |
|
@@ -443,8 +452,12 @@ def generate_30(
|
|
443 |
latent_file_3_scale: float = 1.0,
|
444 |
latent_file_4_scale: float = 1.0,
|
445 |
latent_file_5_scale: float = 1.0,
|
446 |
-
samples
|
447 |
-
|
|
|
|
|
|
|
|
|
448 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
449 |
):
|
450 |
prompt1=None
|
@@ -462,14 +475,14 @@ def generate_30(
|
|
462 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
463 |
caption=[]
|
464 |
#caption.append(captioning(sd_image_a))
|
465 |
-
prompt1, cap=captioning(sd_image_a,
|
466 |
capt.append(cap)
|
467 |
if latent_file_2 is not None: # Check if a latent file is provided
|
468 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
469 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
470 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
471 |
#caption.append(captioning(sd_image_b))
|
472 |
-
prompt2, cap=captioning(sd_image_b,
|
473 |
capt.append(cap)
|
474 |
else:
|
475 |
sd_image_b = None
|
@@ -478,7 +491,7 @@ def generate_30(
|
|
478 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
479 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
480 |
#caption.append(captioning(sd_image_c))
|
481 |
-
prompt3, cap=captioning(sd_image_c,
|
482 |
capt.append(cap)
|
483 |
else:
|
484 |
sd_image_c = None
|
@@ -487,7 +500,7 @@ def generate_30(
|
|
487 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
488 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
489 |
#caption.append(captioning(sd_image_d))
|
490 |
-
prompt4, cap=captioning(sd_image_d,
|
491 |
capt.append(cap)
|
492 |
else:
|
493 |
sd_image_d = None
|
@@ -496,7 +509,7 @@ def generate_30(
|
|
496 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
497 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
498 |
#caption.append(captioning(sd_image_e))
|
499 |
-
prompt5, cap=captioning(sd_image_e,
|
500 |
capt.append(cap)
|
501 |
else:
|
502 |
sd_image_e = None
|
@@ -595,8 +608,12 @@ def generate_60(
|
|
595 |
latent_file_3_scale: float = 1.0,
|
596 |
latent_file_4_scale: float = 1.0,
|
597 |
latent_file_5_scale: float = 1.0,
|
598 |
-
samples
|
599 |
-
|
|
|
|
|
|
|
|
|
600 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
601 |
):
|
602 |
prompt1=None
|
@@ -614,14 +631,14 @@ def generate_60(
|
|
614 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
615 |
caption=[]
|
616 |
#caption.append(captioning(sd_image_a))
|
617 |
-
prompt1, cap=captioning(sd_image_a,
|
618 |
capt.append(cap)
|
619 |
if latent_file_2 is not None: # Check if a latent file is provided
|
620 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
621 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
622 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
623 |
#caption.append(captioning(sd_image_b))
|
624 |
-
prompt2, cap=captioning(sd_image_b,
|
625 |
capt.append(cap)
|
626 |
else:
|
627 |
sd_image_b = None
|
@@ -630,7 +647,7 @@ def generate_60(
|
|
630 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
631 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
632 |
#caption.append(captioning(sd_image_c))
|
633 |
-
prompt3, cap=captioning(sd_image_c,
|
634 |
capt.append(cap)
|
635 |
else:
|
636 |
sd_image_c = None
|
@@ -639,7 +656,7 @@ def generate_60(
|
|
639 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
640 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
641 |
#caption.append(captioning(sd_image_d))
|
642 |
-
prompt4, cap=captioning(sd_image_d,
|
643 |
capt.append(cap)
|
644 |
else:
|
645 |
sd_image_d = None
|
@@ -648,7 +665,7 @@ def generate_60(
|
|
648 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
649 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
650 |
#caption.append(captioning(sd_image_e))
|
651 |
-
prompt5, cap=captioning(sd_image_e,
|
652 |
capt.append(cap)
|
653 |
else:
|
654 |
sd_image_e = None
|
@@ -747,9 +764,13 @@ def generate_90(
|
|
747 |
latent_file_3_scale: float = 1.0,
|
748 |
latent_file_4_scale: float = 1.0,
|
749 |
latent_file_5_scale: float = 1.0,
|
750 |
-
samples
|
751 |
-
|
752 |
-
|
|
|
|
|
|
|
|
|
753 |
):
|
754 |
prompt1=None
|
755 |
prompt2=None
|
@@ -766,14 +787,14 @@ def generate_90(
|
|
766 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
767 |
caption=[]
|
768 |
#caption.append(captioning(sd_image_a))
|
769 |
-
prompt1, cap=captioning(sd_image_a,
|
770 |
capt.append(cap)
|
771 |
if latent_file_2 is not None: # Check if a latent file is provided
|
772 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
773 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
774 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
775 |
#caption.append(captioning(sd_image_b))
|
776 |
-
prompt2, cap=captioning(sd_image_b,
|
777 |
capt.append(cap)
|
778 |
else:
|
779 |
sd_image_b = None
|
@@ -782,7 +803,7 @@ def generate_90(
|
|
782 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
783 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
784 |
#caption.append(captioning(sd_image_c))
|
785 |
-
prompt3, cap=captioning(sd_image_c,
|
786 |
capt.append(cap)
|
787 |
else:
|
788 |
sd_image_c = None
|
@@ -791,7 +812,7 @@ def generate_90(
|
|
791 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
792 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
793 |
#caption.append(captioning(sd_image_d))
|
794 |
-
prompt4, cap=captioning(sd_image_d,
|
795 |
capt.append(cap)
|
796 |
else:
|
797 |
sd_image_d = None
|
@@ -800,7 +821,7 @@ def generate_90(
|
|
800 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
801 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
802 |
#caption.append(captioning(sd_image_e))
|
803 |
-
prompt5, cap=captioning(sd_image_e,
|
804 |
capt.append(cap)
|
805 |
else:
|
806 |
sd_image_e = None
|
@@ -994,10 +1015,12 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
994 |
value="('deformed', 'distorted', 'disfigured':1.3),'not photorealistic':1.5, 'poorly drawn', 'bad anatomy', 'wrong anatomy', 'extra limb', 'missing limb', 'floating limbs', 'poorly drawn hands', 'poorly drawn feet', 'poorly drawn face':1.3, 'out of frame', 'extra limbs', 'bad anatomy', 'bad art', 'beginner', 'distorted face','amateur'",
|
995 |
visible=True,
|
996 |
)
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
|
|
|
|
1001 |
label="Samples",
|
1002 |
minimum=0,
|
1003 |
maximum=20,
|
@@ -1077,7 +1100,11 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
1077 |
file_4_strength,
|
1078 |
file_5_strength,
|
1079 |
samples,
|
1080 |
-
|
|
|
|
|
|
|
|
|
1081 |
],
|
1082 |
outputs=[result],
|
1083 |
)
|
@@ -1110,7 +1137,11 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
1110 |
file_4_strength,
|
1111 |
file_5_strength,
|
1112 |
samples,
|
1113 |
-
|
|
|
|
|
|
|
|
|
1114 |
],
|
1115 |
outputs=[result],
|
1116 |
)
|
@@ -1143,7 +1174,11 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
1143 |
file_4_strength,
|
1144 |
file_5_strength,
|
1145 |
samples,
|
1146 |
-
|
|
|
|
|
|
|
|
|
1147 |
],
|
1148 |
outputs=[result],
|
1149 |
)
|
|
|
243 |
f.write(f"Model UNET: ford442/RealVisXL_V5.0_BF16 \n")
|
244 |
upload_to_ftp(filename)
|
245 |
|
246 |
+
def captioning(img, prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)):
|
247 |
'''prompts_array = [
|
248 |
"Adjectives describing this scene are:",
|
249 |
# "The color scheme of this image is",
|
|
|
310 |
generated_textb = generated_textb.replace(cap_prompt, "").strip() #Or could try .split(prompt, 1)[-1].strip()
|
311 |
output_prompt.append(generated_text)
|
312 |
print(generated_text)
|
313 |
+
prompt_array=[]
|
314 |
+
if prompt_1 in not None:
|
315 |
+
prompt_array.append(prompt_1)
|
316 |
+
if prompt_2 in not None:
|
317 |
+
prompt_array.append(prompt_2)
|
318 |
+
if prompt_3 in not None:
|
319 |
+
prompt_array.append(prompt_3)
|
320 |
+
if prompt_4 in not None:
|
321 |
+
prompt_array.append(prompt_4)
|
322 |
+
if prompt_5 in not None:
|
323 |
+
prompt_array.append(prompt_5)
|
324 |
for prompt in prompts_array:
|
325 |
inputs = processor5(images=img, text=prompt, return_tensors="pt").to('cuda')
|
326 |
#with torch.no_grad():
|
|
|
359 |
response_text = generated_texta.replace(generated_text, "").strip()
|
360 |
print(f"{response_text}\n")
|
361 |
output_prompt.append(response_text)
|
362 |
+
|
363 |
output_prompt = " ".join(output_prompt)
|
364 |
return output_prompt, generated_textb
|
365 |
|
|
|
452 |
latent_file_3_scale: float = 1.0,
|
453 |
latent_file_4_scale: float = 1.0,
|
454 |
latent_file_5_scale: float = 1.0,
|
455 |
+
samples=1,
|
456 |
+
prompt_1: str = "",
|
457 |
+
prompt_2: str = "",
|
458 |
+
prompt_3: str = "",
|
459 |
+
prompt_4: str = "",
|
460 |
+
prompt_5: str = "",
|
461 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
462 |
):
|
463 |
prompt1=None
|
|
|
475 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
476 |
caption=[]
|
477 |
#caption.append(captioning(sd_image_a))
|
478 |
+
prompt1, cap=captioning(sd_image_a,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
479 |
capt.append(cap)
|
480 |
if latent_file_2 is not None: # Check if a latent file is provided
|
481 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
482 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
483 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
484 |
#caption.append(captioning(sd_image_b))
|
485 |
+
prompt2, cap=captioning(sd_image_b,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
486 |
capt.append(cap)
|
487 |
else:
|
488 |
sd_image_b = None
|
|
|
491 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
492 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
493 |
#caption.append(captioning(sd_image_c))
|
494 |
+
prompt3, cap=captioning(sd_image_c,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
495 |
capt.append(cap)
|
496 |
else:
|
497 |
sd_image_c = None
|
|
|
500 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
501 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
502 |
#caption.append(captioning(sd_image_d))
|
503 |
+
prompt4, cap=captioning(sd_image_d,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
504 |
capt.append(cap)
|
505 |
else:
|
506 |
sd_image_d = None
|
|
|
509 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
510 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
511 |
#caption.append(captioning(sd_image_e))
|
512 |
+
prompt5, cap=captioning(sd_image_e,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
513 |
capt.append(cap)
|
514 |
else:
|
515 |
sd_image_e = None
|
|
|
608 |
latent_file_3_scale: float = 1.0,
|
609 |
latent_file_4_scale: float = 1.0,
|
610 |
latent_file_5_scale: float = 1.0,
|
611 |
+
samples=1,
|
612 |
+
prompt_1: str = "",
|
613 |
+
prompt_2: str = "",
|
614 |
+
prompt_3: str = "",
|
615 |
+
prompt_4: str = "",
|
616 |
+
prompt_5: str = "",
|
617 |
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
618 |
):
|
619 |
prompt1=None
|
|
|
631 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
632 |
caption=[]
|
633 |
#caption.append(captioning(sd_image_a))
|
634 |
+
prompt1, cap=captioning(sd_image_a,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
635 |
capt.append(cap)
|
636 |
if latent_file_2 is not None: # Check if a latent file is provided
|
637 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
638 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
639 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
640 |
#caption.append(captioning(sd_image_b))
|
641 |
+
prompt2, cap=captioning(sd_image_b,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
642 |
capt.append(cap)
|
643 |
else:
|
644 |
sd_image_b = None
|
|
|
647 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
648 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
649 |
#caption.append(captioning(sd_image_c))
|
650 |
+
prompt3, cap=captioning(sd_image_c,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
651 |
capt.append(cap)
|
652 |
else:
|
653 |
sd_image_c = None
|
|
|
656 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
657 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
658 |
#caption.append(captioning(sd_image_d))
|
659 |
+
prompt4, cap=captioning(sd_image_d,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
660 |
capt.append(cap)
|
661 |
else:
|
662 |
sd_image_d = None
|
|
|
665 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
666 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
667 |
#caption.append(captioning(sd_image_e))
|
668 |
+
prompt5, cap=captioning(sd_image_e,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
669 |
capt.append(cap)
|
670 |
else:
|
671 |
sd_image_e = None
|
|
|
764 |
latent_file_3_scale: float = 1.0,
|
765 |
latent_file_4_scale: float = 1.0,
|
766 |
latent_file_5_scale: float = 1.0,
|
767 |
+
samples=1,
|
768 |
+
prompt_1: str = "",
|
769 |
+
prompt_2: str = "",
|
770 |
+
prompt_3: str = "",
|
771 |
+
prompt_4: str = "",
|
772 |
+
prompt_5: str = "",
|
773 |
+
progress=gr.Progress(track_tqdm=True) # Add progress as a keyword argument
|
774 |
):
|
775 |
prompt1=None
|
776 |
prompt2=None
|
|
|
787 |
#sd_image_a.resize((height,width), Image.LANCZOS)
|
788 |
caption=[]
|
789 |
#caption.append(captioning(sd_image_a))
|
790 |
+
prompt1, cap=captioning(sd_image_a,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
791 |
capt.append(cap)
|
792 |
if latent_file_2 is not None: # Check if a latent file is provided
|
793 |
sd_image_b = Image.open(latent_file_2.name).convert('RGB')
|
794 |
#sd_image_b.resize((height,width), Image.LANCZOS)
|
795 |
sd_image_b.resize((768,768), Image.LANCZOS)
|
796 |
#caption.append(captioning(sd_image_b))
|
797 |
+
prompt2, cap=captioning(sd_image_b,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
798 |
capt.append(cap)
|
799 |
else:
|
800 |
sd_image_b = None
|
|
|
803 |
#sd_image_c.resize((height,width), Image.LANCZOS)
|
804 |
sd_image_c.resize((768,768), Image.LANCZOS)
|
805 |
#caption.append(captioning(sd_image_c))
|
806 |
+
prompt3, cap=captioning(sd_image_c,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
807 |
capt.append(cap)
|
808 |
else:
|
809 |
sd_image_c = None
|
|
|
812 |
#sd_image_d.resize((height,width), Image.LANCZOS)
|
813 |
sd_image_d.resize((768,768), Image.LANCZOS)
|
814 |
#caption.append(captioning(sd_image_d))
|
815 |
+
prompt4, cap=captioning(sd_image_d,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
816 |
capt.append(cap)
|
817 |
else:
|
818 |
sd_image_d = None
|
|
|
821 |
#sd_image_e.resize((height,width), Image.LANCZOS)
|
822 |
sd_image_e.resize((768,768), Image.LANCZOS)
|
823 |
#caption.append(captioning(sd_image_e))
|
824 |
+
prompt5, cap=captioning(sd_image_e,prompt_1,prompt_2,prompt_3,prompt_4,prompt_5)
|
825 |
capt.append(cap)
|
826 |
else:
|
827 |
sd_image_e = None
|
|
|
1015 |
value="('deformed', 'distorted', 'disfigured':1.3),'not photorealistic':1.5, 'poorly drawn', 'bad anatomy', 'wrong anatomy', 'extra limb', 'missing limb', 'floating limbs', 'poorly drawn hands', 'poorly drawn feet', 'poorly drawn face':1.3, 'out of frame', 'extra limbs', 'bad anatomy', 'bad art', 'beginner', 'distorted face','amateur'",
|
1016 |
visible=True,
|
1017 |
)
|
1018 |
+
prompt_1 = gr.Textbox(label="Custom Prompt 1", lines=2, placeholder="Enter custom prompt 1")
|
1019 |
+
prompt_2 = gr.Textbox(label="Custom Prompt 2", lines=2, placeholder="Enter custom prompt 2")
|
1020 |
+
prompt_3 = gr.Textbox(label="Custom Prompt 3", lines=2, placeholder="Enter custom prompt 3")
|
1021 |
+
prompt_4 = gr.Textbox(label="Custom Prompt 4", lines=2, placeholder="Enter custom prompt 4")
|
1022 |
+
prompt_5 = gr.Textbox(label="Custom Prompt 5", lines=2, placeholder="Enter custom prompt 5")
|
1023 |
+
samples = gr.Slider(
|
1024 |
label="Samples",
|
1025 |
minimum=0,
|
1026 |
maximum=20,
|
|
|
1100 |
file_4_strength,
|
1101 |
file_5_strength,
|
1102 |
samples,
|
1103 |
+
prompt_1,
|
1104 |
+
prompt_2,
|
1105 |
+
prompt_3,
|
1106 |
+
prompt_4,
|
1107 |
+
prompt_5,
|
1108 |
],
|
1109 |
outputs=[result],
|
1110 |
)
|
|
|
1137 |
file_4_strength,
|
1138 |
file_5_strength,
|
1139 |
samples,
|
1140 |
+
prompt_1,
|
1141 |
+
prompt_2,
|
1142 |
+
prompt_3,
|
1143 |
+
prompt_4,
|
1144 |
+
prompt_5,
|
1145 |
],
|
1146 |
outputs=[result],
|
1147 |
)
|
|
|
1174 |
file_4_strength,
|
1175 |
file_5_strength,
|
1176 |
samples,
|
1177 |
+
prompt_1,
|
1178 |
+
prompt_2,
|
1179 |
+
prompt_3,
|
1180 |
+
prompt_4,
|
1181 |
+
prompt_5,
|
1182 |
],
|
1183 |
outputs=[result],
|
1184 |
)
|