Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,42 +18,47 @@ print(zero.device) # <-- 'cpu' 🤔
|
|
18 |
script_directory = os.path.dirname(os.path.realpath(__file__))
|
19 |
|
20 |
# download ConsistentID checkpoint to cache
|
|
|
21 |
consistentID_path = hf_hub_download(repo_id="JackAILab/ConsistentID", filename="ConsistentID-v1.bin", repo_type="model")
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
@spaces.GPU
|
24 |
def process(inputImage,prompt,negative_prompt):
|
25 |
|
26 |
device = zero.device # "cuda"
|
27 |
-
|
28 |
-
|
29 |
-
### Load base model
|
30 |
-
pipe = ConsistentIDStableDiffusionPipeline.from_pretrained(
|
31 |
-
base_model_path,
|
32 |
-
torch_dtype=torch.float16,
|
33 |
-
use_safetensors=True,
|
34 |
-
variant="fp16"
|
35 |
-
).to(device)
|
36 |
-
|
37 |
-
### Load consistentID_model checkpoint
|
38 |
-
pipe.load_ConsistentID_model(
|
39 |
-
os.path.dirname(consistentID_path),
|
40 |
-
subfolder="",
|
41 |
-
weight_name=os.path.basename(consistentID_path),
|
42 |
-
trigger_word="img",
|
43 |
-
)
|
44 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
45 |
-
|
46 |
# hyper-parameter
|
47 |
select_images = load_image(Image.fromarray(inputImage))
|
48 |
num_steps = 50
|
49 |
merge_steps = 30
|
50 |
|
51 |
-
|
52 |
if prompt == "":
|
53 |
-
prompt = "A man, in a forest
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
if negative_prompt == "":
|
56 |
-
negative_prompt = "monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
57 |
|
58 |
#Extend Prompt
|
59 |
prompt = "cinematic photo," + prompt + ", 50mm photograph, half-length portrait, film, bokeh, professional, 4k, highly detailed"
|
@@ -67,7 +72,7 @@ def process(inputImage,prompt,negative_prompt):
|
|
67 |
images = pipe(
|
68 |
prompt=prompt,
|
69 |
width=512,
|
70 |
-
height=
|
71 |
input_id_images=select_images,
|
72 |
negative_prompt=negative_prompt,
|
73 |
num_images_per_prompt=1,
|
@@ -98,9 +103,76 @@ iface = gr.Interface(
|
|
98 |
gr.Image(label="Output"),
|
99 |
],
|
100 |
title="ConsistentID Demo",
|
101 |
-
description="Put reference portrait below"
|
|
|
102 |
)
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
iface.launch() # zero.device
|
105 |
|
106 |
# @spaces.GPU
|
|
|
18 |
script_directory = os.path.dirname(os.path.realpath(__file__))
|
19 |
|
20 |
# download ConsistentID checkpoint to cache
|
21 |
+
base_model_path = hf_hub_download(repo_id="SG161222/Realistic_Vision_V6.0_B1_noVAE", filename="ConsistentID-v1.bin", repo_type="model")
|
22 |
consistentID_path = hf_hub_download(repo_id="JackAILab/ConsistentID", filename="ConsistentID-v1.bin", repo_type="model")
|
23 |
|
24 |
+
### Load base model
|
25 |
+
pipe = ConsistentIDStableDiffusionPipeline.from_pretrained(
|
26 |
+
base_model_path,
|
27 |
+
torch_dtype=torch.float16,
|
28 |
+
use_safetensors=True,
|
29 |
+
variant="fp16"
|
30 |
+
).to(device)
|
31 |
+
|
32 |
+
### Load consistentID_model checkpoint
|
33 |
+
pipe.load_ConsistentID_model(
|
34 |
+
os.path.dirname(consistentID_path),
|
35 |
+
subfolder="",
|
36 |
+
weight_name=os.path.basename(consistentID_path),
|
37 |
+
trigger_word="img",
|
38 |
+
)
|
39 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
40 |
+
|
41 |
@spaces.GPU
|
42 |
def process(inputImage,prompt,negative_prompt):
|
43 |
|
44 |
device = zero.device # "cuda"
|
45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# hyper-parameter
|
47 |
select_images = load_image(Image.fromarray(inputImage))
|
48 |
num_steps = 50
|
49 |
merge_steps = 30
|
50 |
|
|
|
51 |
if prompt == "":
|
52 |
+
prompt = "A man, in a forest"
|
53 |
+
prompt = "A man, with backpack, in a raining tropical forest, adventuring, holding a flashlight, in mist, seeking animals"
|
54 |
+
prompt = "A person, in a sowm, wearing santa hat and a scarf, with a cottage behind"
|
55 |
+
else:
|
56 |
+
prompt=Enhance_prompt(prompt,blank_image)
|
57 |
+
print(prompt)
|
58 |
+
pass
|
59 |
+
|
60 |
if negative_prompt == "":
|
61 |
+
negative_prompt = ",monochrome, lowres, bad anatomy, worst quality, low quality, blurry"
|
62 |
|
63 |
#Extend Prompt
|
64 |
prompt = "cinematic photo," + prompt + ", 50mm photograph, half-length portrait, film, bokeh, professional, 4k, highly detailed"
|
|
|
72 |
images = pipe(
|
73 |
prompt=prompt,
|
74 |
width=512,
|
75 |
+
height=768,
|
76 |
input_id_images=select_images,
|
77 |
negative_prompt=negative_prompt,
|
78 |
num_images_per_prompt=1,
|
|
|
103 |
gr.Image(label="Output"),
|
104 |
],
|
105 |
title="ConsistentID Demo",
|
106 |
+
description="Put reference portrait below" ,
|
107 |
+
allow_flagging="never"
|
108 |
)
|
109 |
|
110 |
+
# # Use Blocks Create Gradio
|
111 |
+
# with gr.Blocks(title="ConsistentID Demo") as demo:
|
112 |
+
# gr.Markdown("# ConsistentID Demo")
|
113 |
+
# gr.Markdown("\
|
114 |
+
# Put the reference figure to be redrawn into the box below (There is a small probability of referensing failure. You can submit it repeatedly)")
|
115 |
+
# gr.Markdown("\
|
116 |
+
# If you find our work interesting, please leave a star in GitHub for us!<br>\
|
117 |
+
# https://github.com/JackAILab/ConsistentID")
|
118 |
+
# with gr.Row():
|
119 |
+
# with gr.Column():
|
120 |
+
# model_selected_tab = gr.State(0)
|
121 |
+
# with gr.TabItem("template images") as template_images_tab:
|
122 |
+
# template_gallery_list = [(i, i) for i in preset_template]
|
123 |
+
# gallery = gr.Gallery(template_gallery_list,columns=[4], rows=[2], object_fit="contain", height="auto",show_label=False)
|
124 |
+
|
125 |
+
# def select_function(evt: gr.SelectData):
|
126 |
+
# return preset_template[evt.index]
|
127 |
+
|
128 |
+
# selected_template_images = gr.Text(show_label=False, visible=False, placeholder="Selected")
|
129 |
+
# gallery.select(select_function, None, selected_template_images)
|
130 |
+
# with gr.TabItem("Upload Image") as upload_image_tab:
|
131 |
+
# costum_image = gr.Image(label="Upload Image")
|
132 |
+
|
133 |
+
# model_selected_tabs = [template_images_tab, upload_image_tab]
|
134 |
+
# for i, tab in enumerate(model_selected_tabs):
|
135 |
+
# tab.select(fn=lambda tabnum=i: tabnum, inputs=[], outputs=[model_selected_tab])
|
136 |
+
|
137 |
+
# with gr.Column():
|
138 |
+
# prompt_selected_tab = gr.State(0)
|
139 |
+
# with gr.TabItem("template prompts") as template_prompts_tab:
|
140 |
+
# prompt_selected = gr.Dropdown(value="A person, police officer, half body shot", elem_id='dropdown', choices=[
|
141 |
+
# "A woman in a wedding dress",
|
142 |
+
# "A woman, queen, in a gorgeous palace",
|
143 |
+
# "A man sitting at the beach with sunset",
|
144 |
+
# "A person, police officer, half body shot",
|
145 |
+
# "A man, sailor, in a boat above ocean",
|
146 |
+
# "A women wearing headphone, listening music",
|
147 |
+
# "A man, firefighter, half body shot"], label=f"prepared prompts")
|
148 |
+
|
149 |
+
# with gr.TabItem("custom prompt") as custom_prompt_tab:
|
150 |
+
# prompt = gr.Textbox(label="prompt",placeholder="A man/woman wearing a santa hat")
|
151 |
+
# nagetive_prompt = gr.Textbox(label="negative prompt",placeholder="monochrome, lowres, bad anatomy, worst quality, low quality, blurry")
|
152 |
+
|
153 |
+
# prompt_selected_tabs = [template_prompts_tab, custom_prompt_tab]
|
154 |
+
# for i, tab in enumerate(prompt_selected_tabs):
|
155 |
+
# tab.select(fn=lambda tabnum=i: tabnum, inputs=[], outputs=[prompt_selected_tab])
|
156 |
+
|
157 |
+
# retouching = gr.Checkbox(label="face retouching",value=False)
|
158 |
+
# width = gr.Slider(label="image width",minimum=256,maximum=768,value=512,step=8)
|
159 |
+
# height = gr.Slider(label="image height",minimum=256,maximum=768,value=768,step=8)
|
160 |
+
# width.release(lambda x,y: min(1280-x,y), inputs=[width,height], outputs=[height])
|
161 |
+
# height.release(lambda x,y: min(1280-y,x), inputs=[width,height], outputs=[width])
|
162 |
+
# merge_steps = gr.Slider(label="step starting to merge facial details(30 is recommended)",minimum=10,maximum=50,value=30,step=1)
|
163 |
+
|
164 |
+
# btn = gr.Button("Run")
|
165 |
+
# with gr.Column():
|
166 |
+
# out = gr.Image(label="Output")
|
167 |
+
# gr.Markdown('''
|
168 |
+
# N.B.:<br/>
|
169 |
+
# - If the proportion of face in the image is too small, the probability of an error will be slightly higher, and the similarity will also significantly decrease.)
|
170 |
+
# - At the same time, use prompt with \"man\" or \"woman\" instead of \"person\" as much as possible, as that may cause the model to be confused whether the protagonist is male or female.
|
171 |
+
# - Due to insufficient graphics memory on the demo server, there is an upper limit on the resolution for generating samples. We will support the generation of SDXL as soon as possible<br/><br/>
|
172 |
+
# ''')
|
173 |
+
# btn.click(fn=process, inputs=[selected_template_images,costum_image,prompt,nagetive_prompt,prompt_selected,retouching
|
174 |
+
# ,model_selected_tab,prompt_selected_tab,width,height,merge_steps], outputs=out)
|
175 |
+
|
176 |
iface.launch() # zero.device
|
177 |
|
178 |
# @spaces.GPU
|