Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ pipe = ConsistentIDStableDiffusionPipeline.from_pretrained(
|
|
39 |
## BiSenet
|
40 |
bise_net_cp_path = hf_hub_download(repo_id="JackAILab/ConsistentID", filename="face_parsing.pth", local_dir="./checkpoints")
|
41 |
bise_net = BiSeNet(n_classes = 19)
|
42 |
-
bise_net.load_state_dict(torch.load(bise_net_cp_path, map_location="cpu"))
|
43 |
|
44 |
### Load consistentID_model checkpoint
|
45 |
pipe.load_ConsistentID_model(
|
@@ -52,6 +52,27 @@ pipe.load_ConsistentID_model(
|
|
52 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
53 |
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
@spaces.GPU
|
56 |
def process(inputImage,prompt,negative_prompt):
|
57 |
|
@@ -65,14 +86,15 @@ def process(inputImage,prompt,negative_prompt):
|
|
65 |
prompt = "A man, with backpack, in a raining tropical forest, adventuring, holding a flashlight, in mist, seeking animals"
|
66 |
prompt = "A person, in a sowm, wearing santa hat and a scarf, with a cottage behind"
|
67 |
else:
|
68 |
-
prompt=Enhance_prompt(prompt,blank_image)
|
|
|
69 |
print(prompt)
|
70 |
pass
|
71 |
|
72 |
if negative_prompt == "":
|
73 |
negative_prompt = ",monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
74 |
|
75 |
-
#Extend Prompt
|
76 |
prompt = "cinematic photo," + prompt + ", 50mm photograph, half-length portrait, film, bokeh, professional, 4k, highly detailed"
|
77 |
|
78 |
negtive_prompt_group="((((ugly)))), (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))). out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck)))"
|
@@ -103,21 +125,11 @@ def process(inputImage,prompt,negative_prompt):
|
|
103 |
|
104 |
return os.path.join(output_dir, f"{current_date}-{seed}.jpg")
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
gr.Textbox(label="prompt",placeholder="A man, in a forest, adventuring"),
|
112 |
-
gr.Textbox(label="negative prompt",placeholder="monochrome, lowres, bad anatomy, worst quality, low quality, blurry"),
|
113 |
-
],
|
114 |
-
outputs=[
|
115 |
-
gr.Image(label="Output"),
|
116 |
-
],
|
117 |
-
title="ConsistentID Demo",
|
118 |
-
description="Put reference portrait below" ,
|
119 |
-
allow_flagging="never"
|
120 |
-
)
|
121 |
|
122 |
# # Use Blocks Create Gradio
|
123 |
# with gr.Blocks(title="ConsistentID Demo") as demo:
|
@@ -185,6 +197,21 @@ iface = gr.Interface(
|
|
185 |
# btn.click(fn=process, inputs=[selected_template_images,costum_image,prompt,nagetive_prompt,prompt_selected,retouching
|
186 |
# ,model_selected_tab,prompt_selected_tab,width,height,merge_steps], outputs=out)
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
iface.launch() # zero.device
|
189 |
|
190 |
# @spaces.GPU
|
|
|
39 |
## BiSenet
|
40 |
bise_net_cp_path = hf_hub_download(repo_id="JackAILab/ConsistentID", filename="face_parsing.pth", local_dir="./checkpoints")
|
41 |
bise_net = BiSeNet(n_classes = 19)
|
42 |
+
bise_net.load_state_dict(torch.load(bise_net_cp_path, map_location="cpu")).to(device)
|
43 |
|
44 |
### Load consistentID_model checkpoint
|
45 |
pipe.load_ConsistentID_model(
|
|
|
52 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
53 |
|
54 |
|
55 |
+
# @torch.inference_mode()
|
56 |
+
# def Enhance_prompt(prompt,select_images):
|
57 |
+
|
58 |
+
# llva_prompt = f'Please ignore the image. Enhance the following text prompt for me. You can associate more details with the character\'s gesture, environment, and decent clothing:"{prompt}".'
|
59 |
+
# args = type('Args', (), {
|
60 |
+
# "model_path": llva_model_path,
|
61 |
+
# "model_base": None,
|
62 |
+
# "model_name": get_model_name_from_path(llva_model_path),
|
63 |
+
# "query": llva_prompt,
|
64 |
+
# "conv_mode": None,
|
65 |
+
# "image_file": select_images,
|
66 |
+
# "sep": ",",
|
67 |
+
# "temperature": 0,
|
68 |
+
# "top_p": None,
|
69 |
+
# "num_beams": 1,
|
70 |
+
# "max_new_tokens": 512
|
71 |
+
# })()
|
72 |
+
# Enhanced_prompt = eval_model(args, llva_tokenizer, llva_model, llva_image_processor)
|
73 |
+
|
74 |
+
# return Enhanced_prompt
|
75 |
+
|
76 |
@spaces.GPU
|
77 |
def process(inputImage,prompt,negative_prompt):
|
78 |
|
|
|
86 |
prompt = "A man, with backpack, in a raining tropical forest, adventuring, holding a flashlight, in mist, seeking animals"
|
87 |
prompt = "A person, in a sowm, wearing santa hat and a scarf, with a cottage behind"
|
88 |
else:
|
89 |
+
# prompt=Enhance_prompt(prompt,blank_image) # TODO
|
90 |
+
prompt=prompt
|
91 |
print(prompt)
|
92 |
pass
|
93 |
|
94 |
if negative_prompt == "":
|
95 |
negative_prompt = ",monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
96 |
|
97 |
+
# Extend Prompt
|
98 |
prompt = "cinematic photo," + prompt + ", 50mm photograph, half-length portrait, film, bokeh, professional, 4k, highly detailed"
|
99 |
|
100 |
negtive_prompt_group="((((ugly)))), (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))). out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck)))"
|
|
|
125 |
|
126 |
return os.path.join(output_dir, f"{current_date}-{seed}.jpg")
|
127 |
|
128 |
+
# # Gets the templates
|
129 |
+
# script_directory = os.path.dirname(os.path.realpath(__file__))
|
130 |
+
# # preset_template = glob.glob(script_directory+"/images/templates/*.png")
|
131 |
+
# preset_template = glob.glob("./images/templates/*.png")
|
132 |
+
# preset_template = preset_template + glob.glob("./images/templates/*.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# # Use Blocks Create Gradio
|
135 |
# with gr.Blocks(title="ConsistentID Demo") as demo:
|
|
|
197 |
# btn.click(fn=process, inputs=[selected_template_images,costum_image,prompt,nagetive_prompt,prompt_selected,retouching
|
198 |
# ,model_selected_tab,prompt_selected_tab,width,height,merge_steps], outputs=out)
|
199 |
|
200 |
+
iface = gr.Interface(
|
201 |
+
fn=process,
|
202 |
+
inputs=[
|
203 |
+
gr.Image(label="Upload Image"),
|
204 |
+
gr.Textbox(label="prompt",placeholder="A man, in a forest, adventuring"),
|
205 |
+
gr.Textbox(label="negative prompt",placeholder="monochrome, lowres, bad anatomy, worst quality, low quality, blurry"),
|
206 |
+
],
|
207 |
+
outputs=[
|
208 |
+
gr.Image(label="Output"),
|
209 |
+
],
|
210 |
+
title="ConsistentID Demo",
|
211 |
+
description="Put reference portrait below" ,
|
212 |
+
allow_flagging="never"
|
213 |
+
)
|
214 |
+
|
215 |
iface.launch() # zero.device
|
216 |
|
217 |
# @spaces.GPU
|