Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,26 +8,23 @@ from accelerate import Accelerator
|
|
8 |
from transformers import pipeline
|
9 |
from diffusers.utils import load_image
|
10 |
from diffusers import KandinskyV22PriorPipeline, KandinskyV22ControlnetPipeline
|
|
|
11 |
|
12 |
accelerator = Accelerator(cpu=True)
|
13 |
-
MAX_SEED = np.iinfo(np.int32).max
|
14 |
-
depth_estimator = accelerator.prepare(pipeline("depth-estimation", model="Intel/dpt-hybrid-midas"))
|
15 |
pipe_prior = accelerator.prepare(KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float32))
|
16 |
pipe_prior = accelerator.prepare(pipe_prior.to("cpu"))
|
17 |
pipe = accelerator.prepare(KandinskyV22ControlnetPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-controlnet-depth", torch_dtype=torch.float32))
|
18 |
pipe = accelerator.prepare(pipe.to("cpu"))
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
image = depth_estimator(image)['depth']
|
24 |
-
image = load_image(image)
|
25 |
-
image.save('./dpt.png', 'PNG')
|
26 |
image = np.array(image)
|
27 |
image = image[:, :, None]
|
28 |
image = np.concatenate([image, image, image], axis=2)
|
29 |
detected_map = torch.from_numpy(image).float() / 255.0
|
30 |
-
hint = detected_map.permute(
|
31 |
return hint
|
32 |
|
33 |
def plex(goof,prompt):
|
@@ -35,8 +32,7 @@ def plex(goof,prompt):
|
|
35 |
goof = load_image(goof)
|
36 |
goof = goof.convert("RGB")
|
37 |
goof.save('./gf.png', 'PNG')
|
38 |
-
|
39 |
-
hint = make_hint(goof, depth_estimator).unsqueeze(0).to("cpu")
|
40 |
negative_prior_prompt = "lowres,text,bad quality,jpeg artifacts,ugly,bad face,extra fingers,blurry,bad anatomy,extra limbs,fused fingers,long neck,watermark,signature"
|
41 |
image_emb, zero_image_emb = pipe_prior(prompt=prompt, negative_prompt=negative_prior_prompt, num_inference_steps=5,generator=generator).to_tuple()
|
42 |
|
|
|
8 |
from transformers import pipeline
|
9 |
from diffusers.utils import load_image
|
10 |
from diffusers import KandinskyV22PriorPipeline, KandinskyV22ControlnetPipeline
|
11 |
+
from gradio_client import Client
|
12 |
|
13 |
accelerator = Accelerator(cpu=True)
|
|
|
|
|
14 |
pipe_prior = accelerator.prepare(KandinskyV22PriorPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float32))
|
15 |
pipe_prior = accelerator.prepare(pipe_prior.to("cpu"))
|
16 |
pipe = accelerator.prepare(KandinskyV22ControlnetPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-controlnet-depth", torch_dtype=torch.float32))
|
17 |
pipe = accelerator.prepare(pipe.to("cpu"))
|
18 |
+
generator = torch.Generator("cpu").manual_seed(random.randint(1, 4867346))
|
19 |
|
20 |
+
def make_hint(image):
|
21 |
+
client = Client("https://nielsr-dpt-depth-estimation.hf.space/")
|
22 |
+
image = client.predict(image,api_name="/predict")
|
|
|
|
|
|
|
23 |
image = np.array(image)
|
24 |
image = image[:, :, None]
|
25 |
image = np.concatenate([image, image, image], axis=2)
|
26 |
detected_map = torch.from_numpy(image).float() / 255.0
|
27 |
+
hint = detected_map.permute(2, 0, 1)
|
28 |
return hint
|
29 |
|
30 |
def plex(goof,prompt):
|
|
|
32 |
goof = load_image(goof)
|
33 |
goof = goof.convert("RGB")
|
34 |
goof.save('./gf.png', 'PNG')
|
35 |
+
hint = make_hint(goof).unsqueeze(0).to("cpu")
|
|
|
36 |
negative_prior_prompt = "lowres,text,bad quality,jpeg artifacts,ugly,bad face,extra fingers,blurry,bad anatomy,extra limbs,fused fingers,long neck,watermark,signature"
|
37 |
image_emb, zero_image_emb = pipe_prior(prompt=prompt, negative_prompt=negative_prior_prompt, num_inference_steps=5,generator=generator).to_tuple()
|
38 |
|