Spaces:
Runtime error
Runtime error
Support for StableDiffusionInstructPix2PixPipeline
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
-
from diffusers import AutoPipelineForImage2Image
|
4 |
from loguru import logger
|
5 |
from PIL import Image
|
6 |
|
@@ -24,8 +24,6 @@ def generate(
|
|
24 |
f"Starting image generation: {dict(model=model, prompt=prompt, image=init_image, strength=strength)}"
|
25 |
)
|
26 |
|
27 |
-
pipe = AutoPipelineForImage2Image.from_pretrained(model).to("cuda")
|
28 |
-
|
29 |
# Downscale the image
|
30 |
init_image.thumbnail((1024, 1024))
|
31 |
|
@@ -36,12 +34,23 @@ def generate(
|
|
36 |
progress((step_index + 1, pipe.num_timesteps))
|
37 |
return callback_kwargs
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
return images[0]
|
46 |
|
47 |
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
+
from diffusers import AutoPipelineForImage2Image, StableDiffusionInstructPix2PixPipeline
|
4 |
from loguru import logger
|
5 |
from PIL import Image
|
6 |
|
|
|
24 |
f"Starting image generation: {dict(model=model, prompt=prompt, image=init_image, strength=strength)}"
|
25 |
)
|
26 |
|
|
|
|
|
27 |
# Downscale the image
|
28 |
init_image.thumbnail((1024, 1024))
|
29 |
|
|
|
34 |
progress((step_index + 1, pipe.num_timesteps))
|
35 |
return callback_kwargs
|
36 |
|
37 |
+
if model == "timbrooks/instruct-pix2pix":
|
38 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model).to("cuda")
|
39 |
+
|
40 |
+
images = pipe(
|
41 |
+
prompt=prompt,
|
42 |
+
image=init_image,
|
43 |
+
callback_on_step_end=progress_callback,
|
44 |
+
).images
|
45 |
+
else:
|
46 |
+
pipe = AutoPipelineForImage2Image.from_pretrained(model).to("cuda")
|
47 |
+
|
48 |
+
images = pipe(
|
49 |
+
prompt=prompt,
|
50 |
+
image=init_image,
|
51 |
+
strength=strength,
|
52 |
+
callback_on_step_end=progress_callback,
|
53 |
+
).images
|
54 |
return images[0]
|
55 |
|
56 |
|