Spaces:
Runtime error
Runtime error
Refactor and improved logging
Browse files
app.py
CHANGED
@@ -34,23 +34,25 @@ def generate(
|
|
34 |
progress((step_index + 1, pipe.num_timesteps))
|
35 |
return callback_kwargs
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
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 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
return images[0]
|
55 |
|
56 |
|
|
|
34 |
progress((step_index + 1, pipe.num_timesteps))
|
35 |
return callback_kwargs
|
36 |
|
37 |
+
pipeline_type = (
|
38 |
+
StableDiffusionInstructPix2PixPipeline
|
39 |
+
if model == "timbrooks/instruct-pix2pix"
|
40 |
+
else AutoPipelineForImage2Image
|
41 |
+
)
|
42 |
|
43 |
+
logger.debug(f"Loading pipeline: {dict(model=model)}")
|
44 |
+
pipe = pipeline_type.from_pretrained(model).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
logger.debug(f"Generating image: {dict(prompt=prompt)}")
|
47 |
+
additional_args = (
|
48 |
+
{} if model == "timbrooks/instruct-pix2pix" else dict(strength=strength)
|
49 |
+
)
|
50 |
+
images = pipe(
|
51 |
+
prompt=prompt,
|
52 |
+
image=init_image,
|
53 |
+
callback_on_step_end=progress_callback,
|
54 |
+
**additional_args,
|
55 |
+
).images
|
56 |
return images[0]
|
57 |
|
58 |
|