Spaces:
Running
on
Zero
Running
on
Zero
<feat> change output to gallery.
Browse files
app.py
CHANGED
|
@@ -104,6 +104,13 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
| 104 |
# set up the model
|
| 105 |
global pipe, current_task
|
| 106 |
if pipe is None or current_task != task:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
current_task = task
|
| 108 |
|
| 109 |
# insert LoRA
|
|
@@ -264,16 +271,19 @@ def process_image_and_text(condition_image, target_prompt, condition_image_promp
|
|
| 264 |
frame_gap=48,
|
| 265 |
mixup=True,
|
| 266 |
mixup_num_imgs=2,
|
| 267 |
-
enhance_tp=task in ['subject_driven'
|
| 268 |
).frames
|
| 269 |
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
def create_app():
|
| 279 |
with gr.Blocks() as app:
|
|
@@ -312,12 +322,21 @@ def create_app():
|
|
| 312 |
submit_btn = gr.Button("Run", elem_id="submit_btn")
|
| 313 |
|
| 314 |
with gr.Column(variant="panel", elem_classes="outputPanel"):
|
| 315 |
-
output_image = gr.Image(type="pil", elem_id="output")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
submit_btn.click(
|
| 318 |
fn=process_image_and_text,
|
| 319 |
inputs=[condition_image, target_prompt, condition_image_prompt, task, random_seed, inpainting, fill_x1, fill_x2, fill_y1, fill_y2],
|
| 320 |
-
outputs=
|
| 321 |
)
|
| 322 |
|
| 323 |
return app
|
|
|
|
| 104 |
# set up the model
|
| 105 |
global pipe, current_task
|
| 106 |
if pipe is None or current_task != task:
|
| 107 |
+
if current_task is not None:
|
| 108 |
+
transformer.delete_adapters('default')
|
| 109 |
+
for n, m in transformer.named_modules():
|
| 110 |
+
if isinstance(m, peft.tuners.lora.layer.Linear):
|
| 111 |
+
if hasattr(m, 'base_layer'):
|
| 112 |
+
m.forward = m.base_layer.forward.__get__(m, type(m))
|
| 113 |
+
|
| 114 |
current_task = task
|
| 115 |
|
| 116 |
# insert LoRA
|
|
|
|
| 271 |
frame_gap=48,
|
| 272 |
mixup=True,
|
| 273 |
mixup_num_imgs=2,
|
| 274 |
+
enhance_tp=task in ['subject_driven'],
|
| 275 |
).frames
|
| 276 |
|
| 277 |
+
output_images = []
|
| 278 |
+
for i in range(10):
|
| 279 |
+
out = gen_img[:, i:i+1, :, :, :]
|
| 280 |
+
out = out.squeeze(0).squeeze(0).cpu().to(torch.float32).numpy()
|
| 281 |
+
out = np.transpose(out, (1, 2, 0))
|
| 282 |
+
out = (out * 255).astype(np.uint8)
|
| 283 |
+
out = Image.fromarray(out)
|
| 284 |
+
output_images.append(out)
|
| 285 |
+
|
| 286 |
+
return output_images[1:] + [output_images[0]]
|
| 287 |
|
| 288 |
def create_app():
|
| 289 |
with gr.Blocks() as app:
|
|
|
|
| 322 |
submit_btn = gr.Button("Run", elem_id="submit_btn")
|
| 323 |
|
| 324 |
with gr.Column(variant="panel", elem_classes="outputPanel"):
|
| 325 |
+
# output_image = gr.Image(type="pil", elem_id="output")
|
| 326 |
+
output_images = gr.Gallery(
|
| 327 |
+
label="Output Images",
|
| 328 |
+
show_label=True,
|
| 329 |
+
elem_id="output_gallery",
|
| 330 |
+
columns=1,
|
| 331 |
+
rows=10,
|
| 332 |
+
object_fit="contain",
|
| 333 |
+
height="auto",
|
| 334 |
+
)
|
| 335 |
|
| 336 |
submit_btn.click(
|
| 337 |
fn=process_image_and_text,
|
| 338 |
inputs=[condition_image, target_prompt, condition_image_prompt, task, random_seed, inpainting, fill_x1, fill_x2, fill_y1, fill_y2],
|
| 339 |
+
outputs=output_images,
|
| 340 |
)
|
| 341 |
|
| 342 |
return app
|