Spaces:
Runtime error
Runtime error
Commit
·
a728fab
1
Parent(s):
e424e2f
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from diffusers import DiffusionPipeline
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
from PIL import Image
|
@@ -11,10 +11,14 @@ import random
|
|
11 |
start_time = time.time()
|
12 |
current_steps = 25
|
13 |
|
14 |
-
|
|
|
15 |
|
16 |
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
|
17 |
|
|
|
|
|
|
|
18 |
|
19 |
def error_str(error, title="Error"):
|
20 |
return (
|
@@ -71,7 +75,7 @@ def img_to_img(
|
|
71 |
n_images,
|
72 |
neg_prompt,
|
73 |
img,
|
74 |
-
|
75 |
guidance,
|
76 |
steps,
|
77 |
width,
|
@@ -79,11 +83,6 @@ def img_to_img(
|
|
79 |
generator,
|
80 |
seed,
|
81 |
):
|
82 |
-
pipe = PIPE
|
83 |
-
|
84 |
-
if torch.cuda.is_available():
|
85 |
-
pipe = pipe.to("cuda")
|
86 |
-
|
87 |
ratio = min(height / img.height, width / img.width)
|
88 |
img = img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
89 |
|
@@ -93,7 +92,7 @@ def img_to_img(
|
|
93 |
num_images_per_prompt=n_images,
|
94 |
image=img,
|
95 |
num_inference_steps=int(steps),
|
96 |
-
|
97 |
guidance_scale=guidance,
|
98 |
generator=generator,
|
99 |
)
|
@@ -196,12 +195,12 @@ with gr.Blocks(css="style.css") as demo:
|
|
196 |
image = gr.Image(
|
197 |
label="Image", height=256, tool="editor", type="pil"
|
198 |
)
|
199 |
-
|
200 |
-
label="
|
201 |
-
minimum=
|
202 |
-
maximum=
|
203 |
-
step=0.
|
204 |
-
value=
|
205 |
)
|
206 |
|
207 |
inputs = [
|
@@ -213,7 +212,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
213 |
height,
|
214 |
seed,
|
215 |
image,
|
216 |
-
|
217 |
neg_prompt,
|
218 |
]
|
219 |
outputs = [gallery, error_output]
|
|
|
1 |
+
from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
from PIL import Image
|
|
|
11 |
start_time = time.time()
|
12 |
current_steps = 25
|
13 |
|
14 |
+
pipe = DiffusionPipeline.from_pretrained("timbrooks/instruct-pix2pix", torch_dtype=torch.float16, safety_checker=None)
|
15 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
16 |
|
17 |
device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
|
18 |
|
19 |
+
if torch.cuda.is_available():
|
20 |
+
pipe = pipe.to("cuda")
|
21 |
+
|
22 |
|
23 |
def error_str(error, title="Error"):
|
24 |
return (
|
|
|
75 |
n_images,
|
76 |
neg_prompt,
|
77 |
img,
|
78 |
+
image_guidance_scale,
|
79 |
guidance,
|
80 |
steps,
|
81 |
width,
|
|
|
83 |
generator,
|
84 |
seed,
|
85 |
):
|
|
|
|
|
|
|
|
|
|
|
86 |
ratio = min(height / img.height, width / img.width)
|
87 |
img = img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
88 |
|
|
|
92 |
num_images_per_prompt=n_images,
|
93 |
image=img,
|
94 |
num_inference_steps=int(steps),
|
95 |
+
image_guidance_scale=image_guidance_scale,
|
96 |
guidance_scale=guidance,
|
97 |
generator=generator,
|
98 |
)
|
|
|
195 |
image = gr.Image(
|
196 |
label="Image", height=256, tool="editor", type="pil"
|
197 |
)
|
198 |
+
image_guidance_scale = gr.Slider(
|
199 |
+
label="Image Guidance Scale",
|
200 |
+
minimum=1,
|
201 |
+
maximum=10,
|
202 |
+
step=0.2,
|
203 |
+
value=1,
|
204 |
)
|
205 |
|
206 |
inputs = [
|
|
|
212 |
height,
|
213 |
seed,
|
214 |
image,
|
215 |
+
image_guidance_scale,
|
216 |
neg_prompt,
|
217 |
]
|
218 |
outputs = [gallery, error_output]
|