Spaces:
Runtime error
Runtime error
pablo
commited on
Commit
·
d70699a
1
Parent(s):
c013629
directamente
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from share_btn import community_icon_html, loading_icon_html, share_js
|
|
| 7 |
from diffuserslocal.src.diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_ldm3d_inpaint import StableDiffusionLDM3DInpaintPipeline
|
| 8 |
from PIL import Image
|
| 9 |
import numpy as np
|
|
|
|
| 10 |
|
| 11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
|
|
@@ -35,7 +36,6 @@ else:
|
|
| 35 |
|
| 36 |
def estimate_depth(image):
|
| 37 |
|
| 38 |
-
image = np.array(image)
|
| 39 |
input_batch = transform(image).to(device)
|
| 40 |
|
| 41 |
with torch.no_grad():
|
|
@@ -68,17 +68,17 @@ def predict(dict, depth, prompt="", negative_prompt="", guidance_scale=7.5, step
|
|
| 68 |
negative_prompt = None
|
| 69 |
scheduler_class_name = scheduler.split("-")[0]
|
| 70 |
|
| 71 |
-
init_image = dict["image"]
|
| 72 |
|
| 73 |
if (depth == None):
|
| 74 |
depth_image = estimate_depth(init_image)
|
| 75 |
else:
|
| 76 |
-
depth_image = depth
|
| 77 |
|
| 78 |
scheduler = getattr(diffusers, scheduler_class_name)
|
| 79 |
pipe.scheduler = scheduler.from_pretrained("Intel/ldm3d-4c", subfolder="scheduler")
|
| 80 |
|
| 81 |
-
mask = dict["mask"]
|
| 82 |
depth_image = depth_image.resize((512, 512))
|
| 83 |
|
| 84 |
output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, depth_image=depth_image, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
|
|
@@ -128,10 +128,8 @@ with image_blocks as demo:
|
|
| 128 |
gr.HTML(read_content("header.html"))
|
| 129 |
with gr.Row():
|
| 130 |
with gr.Column():
|
| 131 |
-
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="
|
| 132 |
-
depth = gr.Image(source='upload', elem_id="depth_upload", type="
|
| 133 |
-
|
| 134 |
-
print(depth)
|
| 135 |
|
| 136 |
with gr.Row(elem_id="prompt-container", mobile_collapse=False, equal_height=True):
|
| 137 |
with gr.Row():
|
|
|
|
| 7 |
from diffuserslocal.src.diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_ldm3d_inpaint import StableDiffusionLDM3DInpaintPipeline
|
| 8 |
from PIL import Image
|
| 9 |
import numpy as np
|
| 10 |
+
import cv2
|
| 11 |
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
|
|
|
|
| 36 |
|
| 37 |
def estimate_depth(image):
|
| 38 |
|
|
|
|
| 39 |
input_batch = transform(image).to(device)
|
| 40 |
|
| 41 |
with torch.no_grad():
|
|
|
|
| 68 |
negative_prompt = None
|
| 69 |
scheduler_class_name = scheduler.split("-")[0]
|
| 70 |
|
| 71 |
+
init_image = cv2.resize(dict["image"], (512, 512))
|
| 72 |
|
| 73 |
if (depth == None):
|
| 74 |
depth_image = estimate_depth(init_image)
|
| 75 |
else:
|
| 76 |
+
depth_image = depth
|
| 77 |
|
| 78 |
scheduler = getattr(diffusers, scheduler_class_name)
|
| 79 |
pipe.scheduler = scheduler.from_pretrained("Intel/ldm3d-4c", subfolder="scheduler")
|
| 80 |
|
| 81 |
+
mask = cv2.resize(dict["mask"], (512, 512))
|
| 82 |
depth_image = depth_image.resize((512, 512))
|
| 83 |
|
| 84 |
output = pipe(prompt = prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask, depth_image=depth_image, guidance_scale=guidance_scale, num_inference_steps=int(steps), strength=strength)
|
|
|
|
| 128 |
gr.HTML(read_content("header.html"))
|
| 129 |
with gr.Row():
|
| 130 |
with gr.Column():
|
| 131 |
+
image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="numpy", label="Upload",height=400)
|
| 132 |
+
depth = gr.Image(source='upload', elem_id="depth_upload", type="numpy", label="Upload",height=400)
|
|
|
|
|
|
|
| 133 |
|
| 134 |
with gr.Row(elem_id="prompt-container", mobile_collapse=False, equal_height=True):
|
| 135 |
with gr.Row():
|