Spaces:
Build error
Build error
Added Function
Browse files- .idea/workspace.xml +2 -2
- app.py +10 -91
.idea/workspace.xml
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="3cb50146-66c1-4999-864a-398a7d42ffa4" name="Changes" comment="">
|
| 8 |
-
<change afterPath="$PROJECT_DIR
|
| 9 |
</list>
|
| 10 |
<option name="SHOW_DIALOG" value="false" />
|
| 11 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -46,7 +46,7 @@
|
|
| 46 |
<option name="number" value="Default" />
|
| 47 |
<option name="presentableId" value="Default" />
|
| 48 |
<updated>1677222707113</updated>
|
| 49 |
-
<workItem from="1677222708286" duration="
|
| 50 |
</task>
|
| 51 |
<servers />
|
| 52 |
</component>
|
|
|
|
| 5 |
</component>
|
| 6 |
<component name="ChangeListManager">
|
| 7 |
<list default="true" id="3cb50146-66c1-4999-864a-398a7d42ffa4" name="Changes" comment="">
|
| 8 |
+
<change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
|
| 9 |
</list>
|
| 10 |
<option name="SHOW_DIALOG" value="false" />
|
| 11 |
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
|
|
| 46 |
<option name="number" value="Default" />
|
| 47 |
<option name="presentableId" value="Default" />
|
| 48 |
<updated>1677222707113</updated>
|
| 49 |
+
<workItem from="1677222708286" duration="2503000" />
|
| 50 |
</task>
|
| 51 |
<servers />
|
| 52 |
</component>
|
app.py
CHANGED
|
@@ -42,54 +42,17 @@ ddim_sampler_scribble = DDIMSampler(scribble_model)
|
|
| 42 |
|
| 43 |
save_memory = False
|
| 44 |
|
| 45 |
-
def process(input_image, prompt, input_control,
|
| 46 |
-
# TODO:
|
| 47 |
-
if input_control == "Scribble":
|
| 48 |
-
return process_scribble(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta)
|
| 49 |
-
elif input_control == "Pose":
|
| 50 |
-
return process_pose(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, image_resolution, ddim_steps, scale, seed, eta)
|
| 51 |
-
|
| 52 |
-
return process_canny(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold)
|
| 53 |
-
|
| 54 |
-
def process_canny(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold):
|
| 55 |
-
with torch.no_grad():
|
| 56 |
-
img = resize_image(HWC3(input_image), image_resolution)
|
| 57 |
-
H, W, C = img.shape
|
| 58 |
-
|
| 59 |
-
detected_map = apply_canny(img, low_threshold, high_threshold)
|
| 60 |
-
detected_map = HWC3(detected_map)
|
| 61 |
-
|
| 62 |
-
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 63 |
-
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 64 |
-
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 65 |
-
|
| 66 |
-
seed_everything(seed)
|
| 67 |
-
|
| 68 |
-
if save_memory:
|
| 69 |
-
canny_model.low_vram_shift(is_diffusing=False)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
shape = (4, H // 8, W // 8)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
canny_model.low_vram_shift(is_diffusing=False)
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
unconditional_guidance_scale=scale,
|
| 81 |
-
unconditional_conditioning=un_cond)
|
| 82 |
|
| 83 |
-
if save_memory:
|
| 84 |
-
canny_model.low_vram_shift(is_diffusing=False)
|
| 85 |
-
|
| 86 |
-
x_samples = canny_model.decode_first_stage(samples)
|
| 87 |
-
x_samples = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 88 |
-
|
| 89 |
-
results = [x_samples[i] for i in range(num_samples)]
|
| 90 |
-
return [255 - detected_map] + results
|
| 91 |
-
|
| 92 |
-
def process_scribble(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta):
|
| 93 |
with torch.no_grad():
|
| 94 |
img = resize_image(HWC3(input_image), image_resolution)
|
| 95 |
H, W, C = img.shape
|
|
@@ -127,48 +90,6 @@ def process_scribble(input_image, prompt, a_prompt, n_prompt, num_samples, image
|
|
| 127 |
results = [x_samples[i] for i in range(num_samples)]
|
| 128 |
return [255 - detected_map] + results
|
| 129 |
|
| 130 |
-
def process_pose(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, detect_resolution, ddim_steps, scale, seed, eta):
|
| 131 |
-
with torch.no_grad():
|
| 132 |
-
input_image = HWC3(input_image)
|
| 133 |
-
detected_map, _ = apply_openpose(resize_image(input_image, detect_resolution))
|
| 134 |
-
detected_map = HWC3(detected_map)
|
| 135 |
-
img = resize_image(input_image, image_resolution)
|
| 136 |
-
H, W, C = img.shape
|
| 137 |
-
|
| 138 |
-
detected_map = cv2.resize(detected_map, (W, H), interpolation=cv2.INTER_NEAREST)
|
| 139 |
-
|
| 140 |
-
control = torch.from_numpy(detected_map.copy()).float().cuda() / 255.0
|
| 141 |
-
control = torch.stack([control for _ in range(num_samples)], dim=0)
|
| 142 |
-
control = einops.rearrange(control, 'b h w c -> b c h w').clone()
|
| 143 |
-
|
| 144 |
-
if seed == -1:
|
| 145 |
-
seed = random.randint(0, 65535)
|
| 146 |
-
seed_everything(seed)
|
| 147 |
-
|
| 148 |
-
if save_memory:
|
| 149 |
-
pose_model.low_vram_shift(is_diffusing=False)
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
cond = {"c_concat": [control], "c_crossattn": [pose_model.get_learned_conditioning([prompt + ', ' + a_prompt] * num_samples)]}
|
| 153 |
-
un_cond = {"c_concat": [control], "c_crossattn": [pose_model.get_learned_conditioning([n_prompt] * num_samples)]}
|
| 154 |
-
shape = (4, H // 8, W // 8)
|
| 155 |
-
|
| 156 |
-
if save_memory:
|
| 157 |
-
pose_model.low_vram_shift(is_diffusing=False)
|
| 158 |
-
|
| 159 |
-
samples, intermediates = ddim_sampler_pose.sample(ddim_steps, num_samples,
|
| 160 |
-
shape, cond, verbose=False, eta=eta,
|
| 161 |
-
unconditional_guidance_scale=scale,
|
| 162 |
-
unconditional_conditioning=un_cond)
|
| 163 |
-
|
| 164 |
-
if save_memory:
|
| 165 |
-
pose_model.low_vram_shift(is_diffusing=False)
|
| 166 |
-
|
| 167 |
-
x_samples = pose_model.decode_first_stage(samples)
|
| 168 |
-
x_samples = (einops.rearrange(x_samples, 'b c h w -> b h w c') * 127.5 + 127.5).cpu().numpy().clip(0, 255).astype(np.uint8)
|
| 169 |
-
|
| 170 |
-
results = [x_samples[i] for i in range(num_samples)]
|
| 171 |
-
return [detected_map] + results
|
| 172 |
|
| 173 |
def create_canvas(w, h):
|
| 174 |
new_control_options = ["Interactive Scribble"]
|
|
@@ -191,8 +112,8 @@ with block:
|
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column():
|
| 193 |
input_image = gr.Image(source='upload', type="numpy")
|
| 194 |
-
input_control = gr.Dropdown(control_task_list, value="Scribble", label="
|
| 195 |
-
prompt = gr.Textbox(label="
|
| 196 |
run_button = gr.Button(label="Run")
|
| 197 |
|
| 198 |
with gr.Accordion("Advanced options", open=False):
|
|
@@ -204,9 +125,7 @@ with block:
|
|
| 204 |
scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=30.0, value=9.0, step=0.1)
|
| 205 |
seed = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True)
|
| 206 |
eta = gr.Slider(label="eta (DDIM)", minimum=0.0,maximum =1.0, value=0.0, step=0.1)
|
| 207 |
-
|
| 208 |
-
n_prompt = gr.Textbox(label="Negative Prompt",
|
| 209 |
-
value='longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair,extra digit, fewer digits, cropped, worst quality, low quality')
|
| 210 |
with gr.Column():
|
| 211 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery").style(grid=2, height='auto')
|
| 212 |
ips = [input_image, prompt, input_control, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold]
|
|
|
|
| 42 |
|
| 43 |
save_memory = False
|
| 44 |
|
| 45 |
+
def process(input_image, prompt, input_control, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold):
|
| 46 |
+
# TODO: Clean Function for single Task
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
if input_control == "Scribble":
|
| 49 |
+
return process_scribble(input_image, prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta)
|
|
|
|
| 50 |
|
| 51 |
+
def process_scribble(input_image, prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta):
|
|
|
|
| 52 |
|
| 53 |
+
a_prompt = 'best quality, extremely detailed, architecture render, photorealistic, hyper realistic, surreal, dali, 3d rendering, render, 8k, 16k, extremely detailed, unreal engine, octane, maya'
|
| 54 |
+
n_prompt = 'longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair,extra digit, fewer digits, cropped, worst quality, low quality'
|
|
|
|
|
|
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
with torch.no_grad():
|
| 57 |
img = resize_image(HWC3(input_image), image_resolution)
|
| 58 |
H, W, C = img.shape
|
|
|
|
| 90 |
results = [x_samples[i] for i in range(num_samples)]
|
| 91 |
return [255 - detected_map] + results
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
def create_canvas(w, h):
|
| 95 |
new_control_options = ["Interactive Scribble"]
|
|
|
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Column():
|
| 114 |
input_image = gr.Image(source='upload', type="numpy")
|
| 115 |
+
input_control = gr.Dropdown(control_task_list, value="Scribble", label="Task")
|
| 116 |
+
prompt = gr.Textbox(label="Architectural Style")
|
| 117 |
run_button = gr.Button(label="Run")
|
| 118 |
|
| 119 |
with gr.Accordion("Advanced options", open=False):
|
|
|
|
| 125 |
scale = gr.Slider(label="Guidance Scale", minimum=0.1, maximum=30.0, value=9.0, step=0.1)
|
| 126 |
seed = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, randomize=True)
|
| 127 |
eta = gr.Slider(label="eta (DDIM)", minimum=0.0,maximum =1.0, value=0.0, step=0.1)
|
| 128 |
+
|
|
|
|
|
|
|
| 129 |
with gr.Column():
|
| 130 |
result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery").style(grid=2, height='auto')
|
| 131 |
ips = [input_image, prompt, input_control, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, scale, seed, eta, low_threshold, high_threshold]
|