Spaces:
Runtime error
Runtime error
yupeng.zhou
commited on
Commit
·
9b7872b
1
Parent(s):
9675114
fix
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from email.policy import default
|
|
|
2 |
import gradio as gr
|
3 |
import spaces
|
4 |
import numpy as np
|
@@ -103,17 +104,18 @@ class SpatialAttnProcessor2_0(torch.nn.Module):
|
|
103 |
global sa32, sa64
|
104 |
global write
|
105 |
global height,width
|
|
|
106 |
if write:
|
107 |
# print(f"white:{cur_step}")
|
108 |
self.id_bank[cur_step] = [hidden_states[:self.id_length], hidden_states[self.id_length:]]
|
109 |
else:
|
110 |
encoder_hidden_states = torch.cat((self.id_bank[cur_step][0].to(self.device),hidden_states[:1],self.id_bank[cur_step][1].to(self.device),hidden_states[1:]))
|
111 |
# 判断随机数是否大于0.5
|
112 |
-
if cur_step <
|
113 |
-
hidden_states = self.__call2__(attn, hidden_states,
|
114 |
else: # 256 1024 4096
|
115 |
random_number = random.random()
|
116 |
-
if cur_step <
|
117 |
rand_num = 0.3
|
118 |
else:
|
119 |
rand_num = 0.1
|
@@ -403,7 +405,7 @@ version = r"""
|
|
403 |
<h5 >1. Support image ref image. (Cartoon Ref image is not support now)</h5>
|
404 |
<h5 >2. Support Typesetting Style and Captioning.(By default, the prompt is used as the caption for each image. If you need to change the caption, add a # at the end of each line. Only the part after the # will be added as a caption to the image.)</h5>
|
405 |
<h5 >3. [NC]symbol (The [NC] symbol is used as a flag to indicate that no characters should be present in the generated scene images. If you want do that, prepend the "[NC]" at the beginning of the line. For example, to generate a scene of falling leaves without any character, write: "[NC] The leaves are falling."),Currently, support is only using Textual Description</h5>
|
406 |
-
<h5
|
407 |
"""
|
408 |
#################################################
|
409 |
global attn_count, total_count, id_length, total_length,cur_step, cur_model_type
|
@@ -500,7 +502,7 @@ def change_visiale_by_model_type(_model_type):
|
|
500 |
|
501 |
|
502 |
######### Image Generation ##############
|
503 |
-
@spaces.GPU(duration=
|
504 |
def process_generation(_sd_type,_model_type,_upload_images, _num_steps,style_name, _Ip_Adapter_Strength ,_style_strength_ratio, guidance_scale, seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt,prompt_array,G_height,G_width,_comic_type):
|
505 |
_model_type = "Photomaker" if _model_type == "Using Ref Images" else "original"
|
506 |
if _model_type == "Photomaker" and "img" not in general_prompt:
|
@@ -510,14 +512,16 @@ def process_generation(_sd_type,_model_type,_upload_images, _num_steps,style_nam
|
|
510 |
if len(prompt_array.splitlines()) > 6:
|
511 |
raise gr.Error(f"No more than 6 prompts in huggface demo for Speed! But found {len(prompt_array)} prompts!")
|
512 |
global sa32, sa64,id_length,total_length,attn_procs,unet,cur_model_type,device
|
|
|
513 |
global write
|
514 |
global cur_step,attn_count
|
515 |
global height,width
|
516 |
height = G_height
|
517 |
width = G_width
|
518 |
-
global
|
519 |
global sd_model_path,models_dict
|
520 |
sd_model_path = models_dict[_sd_type]
|
|
|
521 |
use_safe_tensor = True
|
522 |
if style_name == "(No style)":
|
523 |
sd_model_path = models_dict["RealVision"]
|
@@ -666,15 +670,15 @@ with gr.Blocks(css=css) as demo:
|
|
666 |
#sa16_ = gr.Slider(label=" (The degree of Paired Attention at 16 x 16 self-attention layers) ", minimum=0, maximum=1., value=0.3, step=0.1)
|
667 |
sa32_ = gr.Slider(label=" (The degree of Paired Attention at 32 x 32 self-attention layers) ", minimum=0, maximum=1., value=0.7, step=0.1)
|
668 |
sa64_ = gr.Slider(label=" (The degree of Paired Attention at 64 x 64 self-attention layers) ", minimum=0, maximum=1., value=0.7, step=0.1)
|
669 |
-
id_length_ = gr.Slider(label= "Number of id images in total images" , minimum=2, maximum=
|
670 |
# total_length_ = gr.Slider(label= "Number of total images", minimum=1, maximum=20, value=1, step=1)
|
671 |
seed_ = gr.Slider(label="Seed", minimum=-1, maximum=MAX_SEED, value=0, step=1)
|
672 |
num_steps = gr.Slider(
|
673 |
label="Number of sample steps",
|
674 |
-
minimum=
|
675 |
maximum=50,
|
676 |
step=1,
|
677 |
-
value=
|
678 |
)
|
679 |
G_height = gr.Slider(
|
680 |
label="height",
|
@@ -685,7 +689,7 @@ with gr.Blocks(css=css) as demo:
|
|
685 |
)
|
686 |
G_width = gr.Slider(
|
687 |
label="width",
|
688 |
-
minimum=
|
689 |
maximum=1024,
|
690 |
step=32,
|
691 |
value=1024,
|
@@ -732,7 +736,7 @@ with gr.Blocks(css=css) as demo:
|
|
732 |
|
733 |
gr.Examples(
|
734 |
examples=[
|
735 |
-
[1,0.5,0.5,
|
736 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
737 |
array2string(["wake up in the bed",
|
738 |
"have breakfast",
|
@@ -740,9 +744,9 @@ with gr.Blocks(css=css) as demo:
|
|
740 |
"work in the company",
|
741 |
"Take a walk next to the company at noon",
|
742 |
"lying in bed at night"]),
|
743 |
-
"
|
744 |
],
|
745 |
-
[0,0.5,0.5,
|
746 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
747 |
array2string(["wake up in the bed",
|
748 |
"have breakfast",
|
@@ -751,9 +755,9 @@ with gr.Blocks(css=css) as demo:
|
|
751 |
"laughing happily",
|
752 |
"lying in bed at night"
|
753 |
]),
|
754 |
-
"
|
755 |
],
|
756 |
-
[0,0.3,0.5,
|
757 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
758 |
array2string([
|
759 |
"at home #at home, began to go to drawing",
|
@@ -766,7 +770,7 @@ with gr.Blocks(css=css) as demo:
|
|
766 |
"[NC]The brown squirrel appear.",
|
767 |
"is very happy # She is very happy to see the squirrel again",
|
768 |
"[NC]The brown squirrel takes the cracker and scampers up a tree. # She gives the squirrel cracker"]),
|
769 |
-
"Japanese Anime","Only Using Textual Description",get_image_path_list('./examples/taylor'),
|
770 |
]
|
771 |
],
|
772 |
inputs=[seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array,style,model_type,files,G_height,G_width],
|
|
|
1 |
from email.policy import default
|
2 |
+
from json import encoder
|
3 |
import gradio as gr
|
4 |
import spaces
|
5 |
import numpy as np
|
|
|
104 |
global sa32, sa64
|
105 |
global write
|
106 |
global height,width
|
107 |
+
global num_steps
|
108 |
if write:
|
109 |
# print(f"white:{cur_step}")
|
110 |
self.id_bank[cur_step] = [hidden_states[:self.id_length], hidden_states[self.id_length:]]
|
111 |
else:
|
112 |
encoder_hidden_states = torch.cat((self.id_bank[cur_step][0].to(self.device),hidden_states[:1],self.id_bank[cur_step][1].to(self.device),hidden_states[1:]))
|
113 |
# 判断随机数是否大于0.5
|
114 |
+
if cur_step <0.1* num_steps:
|
115 |
+
hidden_states = self.__call2__(attn, hidden_states,None,attention_mask,temb)
|
116 |
else: # 256 1024 4096
|
117 |
random_number = random.random()
|
118 |
+
if cur_step <0.4 * num_steps:
|
119 |
rand_num = 0.3
|
120 |
else:
|
121 |
rand_num = 0.1
|
|
|
405 |
<h5 >1. Support image ref image. (Cartoon Ref image is not support now)</h5>
|
406 |
<h5 >2. Support Typesetting Style and Captioning.(By default, the prompt is used as the caption for each image. If you need to change the caption, add a # at the end of each line. Only the part after the # will be added as a caption to the image.)</h5>
|
407 |
<h5 >3. [NC]symbol (The [NC] symbol is used as a flag to indicate that no characters should be present in the generated scene images. If you want do that, prepend the "[NC]" at the beginning of the line. For example, to generate a scene of falling leaves without any character, write: "[NC] The leaves are falling."),Currently, support is only using Textual Description</h5>
|
408 |
+
<h5>Tips: Not Ready Now! Just Test! It's better to use prompts to assist in controlling the character's attire. Depending on the limited code integration time, there might be some undiscovered bugs. If you find that a particular generation result is significantly poor, please email me ([email protected]) Thank you very much.</h4>
|
409 |
"""
|
410 |
#################################################
|
411 |
global attn_count, total_count, id_length, total_length,cur_step, cur_model_type
|
|
|
502 |
|
503 |
|
504 |
######### Image Generation ##############
|
505 |
+
@spaces.GPU(duration=90)
|
506 |
def process_generation(_sd_type,_model_type,_upload_images, _num_steps,style_name, _Ip_Adapter_Strength ,_style_strength_ratio, guidance_scale, seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt,prompt_array,G_height,G_width,_comic_type):
|
507 |
_model_type = "Photomaker" if _model_type == "Using Ref Images" else "original"
|
508 |
if _model_type == "Photomaker" and "img" not in general_prompt:
|
|
|
512 |
if len(prompt_array.splitlines()) > 6:
|
513 |
raise gr.Error(f"No more than 6 prompts in huggface demo for Speed! But found {len(prompt_array)} prompts!")
|
514 |
global sa32, sa64,id_length,total_length,attn_procs,unet,cur_model_type,device
|
515 |
+
global num_steps
|
516 |
global write
|
517 |
global cur_step,attn_count
|
518 |
global height,width
|
519 |
height = G_height
|
520 |
width = G_width
|
521 |
+
global pipe2,pipe4
|
522 |
global sd_model_path,models_dict
|
523 |
sd_model_path = models_dict[_sd_type]
|
524 |
+
num_steps =_num_steps
|
525 |
use_safe_tensor = True
|
526 |
if style_name == "(No style)":
|
527 |
sd_model_path = models_dict["RealVision"]
|
|
|
670 |
#sa16_ = gr.Slider(label=" (The degree of Paired Attention at 16 x 16 self-attention layers) ", minimum=0, maximum=1., value=0.3, step=0.1)
|
671 |
sa32_ = gr.Slider(label=" (The degree of Paired Attention at 32 x 32 self-attention layers) ", minimum=0, maximum=1., value=0.7, step=0.1)
|
672 |
sa64_ = gr.Slider(label=" (The degree of Paired Attention at 64 x 64 self-attention layers) ", minimum=0, maximum=1., value=0.7, step=0.1)
|
673 |
+
id_length_ = gr.Slider(label= "Number of id images in total images" , minimum=2, maximum=4, value=3, step=1)
|
674 |
# total_length_ = gr.Slider(label= "Number of total images", minimum=1, maximum=20, value=1, step=1)
|
675 |
seed_ = gr.Slider(label="Seed", minimum=-1, maximum=MAX_SEED, value=0, step=1)
|
676 |
num_steps = gr.Slider(
|
677 |
label="Number of sample steps",
|
678 |
+
minimum=25,
|
679 |
maximum=50,
|
680 |
step=1,
|
681 |
+
value=50,
|
682 |
)
|
683 |
G_height = gr.Slider(
|
684 |
label="height",
|
|
|
689 |
)
|
690 |
G_width = gr.Slider(
|
691 |
label="width",
|
692 |
+
minimum=256,
|
693 |
maximum=1024,
|
694 |
step=32,
|
695 |
value=1024,
|
|
|
736 |
|
737 |
gr.Examples(
|
738 |
examples=[
|
739 |
+
[1,0.5,0.5,3,"a woman img, wearing a white T-shirt, blue loose hair",
|
740 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
741 |
array2string(["wake up in the bed",
|
742 |
"have breakfast",
|
|
|
744 |
"work in the company",
|
745 |
"Take a walk next to the company at noon",
|
746 |
"lying in bed at night"]),
|
747 |
+
"Japanese Anime", "Using Ref Images",get_image_path_list('./examples/taylor'),768,768
|
748 |
],
|
749 |
+
[0,0.5,0.5,3,"a man, wearing black jacket",
|
750 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
751 |
array2string(["wake up in the bed",
|
752 |
"have breakfast",
|
|
|
755 |
"laughing happily",
|
756 |
"lying in bed at night"
|
757 |
]),
|
758 |
+
"Japanese Anime","Only Using Textual Description",get_image_path_list('./examples/taylor'),768,768
|
759 |
],
|
760 |
+
[0,0.3,0.5,3,"a girl, wearing white shirt, black skirt, black tie, yellow hair",
|
761 |
"bad anatomy, bad hands, missing fingers, extra fingers, three hands, three legs, bad arms, missing legs, missing arms, poorly drawn face, bad face, fused face, cloned face, three crus, fused feet, fused thigh, extra crus, ugly fingers, horn, cartoon, cg, 3d, unreal, animate, amputation, disconnected limbs",
|
762 |
array2string([
|
763 |
"at home #at home, began to go to drawing",
|
|
|
770 |
"[NC]The brown squirrel appear.",
|
771 |
"is very happy # She is very happy to see the squirrel again",
|
772 |
"[NC]The brown squirrel takes the cracker and scampers up a tree. # She gives the squirrel cracker"]),
|
773 |
+
"Japanese Anime","Only Using Textual Description",get_image_path_list('./examples/taylor'),768,768
|
774 |
]
|
775 |
],
|
776 |
inputs=[seed_, sa32_, sa64_, id_length_, general_prompt, negative_prompt, prompt_array,style,model_type,files,G_height,G_width],
|