Update app.py
Browse files
app.py
CHANGED
@@ -120,10 +120,6 @@ def estimate_depth(pil_image: Image.Image) ->Image.Image:
|
|
120 |
def generate_image_for_gradio(
|
121 |
prompt: str,
|
122 |
input_image_for_depth: Image.Image,
|
123 |
-
num_inference_steps: int = 25,
|
124 |
-
guidance_scale: float = 8.0,
|
125 |
-
seed: int = None,
|
126 |
-
resolution: int = 512
|
127 |
) -> Image.Image:
|
128 |
|
129 |
global pipeline
|
@@ -140,24 +136,34 @@ def generate_image_for_gradio(
|
|
140 |
|
141 |
print(f"Generating image for prompt: '{prompt}'")
|
142 |
|
143 |
-
|
144 |
control_image = depth_map_pil.convert("RGB")
|
145 |
-
control_image = control_image.resize((
|
146 |
|
147 |
input_image_for_pipeline = [control_image]
|
148 |
|
149 |
generator = None
|
150 |
-
if seed is None:
|
151 |
-
|
152 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
153 |
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
with torch.no_grad():
|
156 |
generated_images = pipeline(
|
157 |
prompt,
|
|
|
158 |
image=input_image_for_pipeline,
|
159 |
-
num_inference_steps=
|
160 |
-
guidance_scale=
|
161 |
generator=generator,
|
162 |
).images
|
163 |
|
@@ -166,15 +172,28 @@ def generate_image_for_gradio(
|
|
166 |
|
167 |
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
iface = gr.Interface(
|
170 |
fn=generate_image_for_gradio,
|
171 |
inputs=[
|
172 |
-
gr.Textbox(label="Prompt", value="a high-quality photo of a modern interior design"),
|
173 |
gr.Image(type="pil", label="Input Image (for Depth Estimation)"),
|
174 |
-
gr.
|
175 |
-
gr.Slider(minimum=1.0, maximum=20.0, value=8.0, step=0.5, label="Guidance Scale"),
|
176 |
-
gr.Number(label="Seed (optional, leave blank for random)", value=None),
|
177 |
-
gr.Number(label="Resolution", value=512, interactive=False)
|
178 |
],
|
179 |
outputs=gr.Image(type="pil", label="Generated Image"),
|
180 |
title="Stable Diffusion ControlNet Depth Demo (with Depth Estimation)",
|
|
|
120 |
def generate_image_for_gradio(
|
121 |
prompt: str,
|
122 |
input_image_for_depth: Image.Image,
|
|
|
|
|
|
|
|
|
123 |
) -> Image.Image:
|
124 |
|
125 |
global pipeline
|
|
|
136 |
|
137 |
print(f"Generating image for prompt: '{prompt}'")
|
138 |
|
139 |
+
negative_prompt = "lowres, watermark, banner, logo, watermark, contactinfo, text, deformed, blurry, blur, out of focus, out of frame, surreal, ugly"
|
140 |
control_image = depth_map_pil.convert("RGB")
|
141 |
+
control_image = control_image.resize((512, 512), Image.LANCZOS)
|
142 |
|
143 |
input_image_for_pipeline = [control_image]
|
144 |
|
145 |
generator = None
|
146 |
+
# if seed is None:
|
147 |
+
seed = random.randint(0, 100000)
|
148 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
149 |
|
150 |
|
151 |
+
# with torch.no_grad():
|
152 |
+
# generated_images = pipeline(
|
153 |
+
# prompt,
|
154 |
+
# image=input_image_for_pipeline,
|
155 |
+
# num_inference_steps=num_inference_steps,
|
156 |
+
# guidance_scale=guidance_scale,
|
157 |
+
# generator=generator,
|
158 |
+
# ).images
|
159 |
+
|
160 |
with torch.no_grad():
|
161 |
generated_images = pipeline(
|
162 |
prompt,
|
163 |
+
negative_prompt=negative_prompt, # Pass negative prompt
|
164 |
image=input_image_for_pipeline,
|
165 |
+
num_inference_steps=50,
|
166 |
+
guidance_scale=0.85,
|
167 |
generator=generator,
|
168 |
).images
|
169 |
|
|
|
172 |
|
173 |
|
174 |
|
175 |
+
# iface = gr.Interface(
|
176 |
+
# fn=generate_image_for_gradio,
|
177 |
+
# inputs=[
|
178 |
+
# gr.Textbox(label="Prompt", value="a high-quality photo of a modern interior design"),
|
179 |
+
# gr.Image(type="pil", label="Input Image (for Depth Estimation)"),
|
180 |
+
# gr.Slider(minimum=10, maximum=100, value=25, step=1, label="Inference Steps"),
|
181 |
+
# gr.Slider(minimum=1.0, maximum=20.0, value=8.0, step=0.5, label="Guidance Scale"),
|
182 |
+
# gr.Number(label="Seed (optional, leave blank for random)", value=None),
|
183 |
+
# gr.Number(label="Resolution", value=512, interactive=False)
|
184 |
+
# ],
|
185 |
+
# outputs=gr.Image(type="pil", label="Generated Image"),
|
186 |
+
# title="Stable Diffusion ControlNet Depth Demo (with Depth Estimation)",
|
187 |
+
# description="Upload an input image, and the app will estimate its depth map, then use it with your prompt to generate a new image. This allows for structural guidance from your input photo.",
|
188 |
+
# allow_flagging="never",
|
189 |
+
# live=False,
|
190 |
+
# theme=Soft(),
|
191 |
+
|
192 |
iface = gr.Interface(
|
193 |
fn=generate_image_for_gradio,
|
194 |
inputs=[
|
|
|
195 |
gr.Image(type="pil", label="Input Image (for Depth Estimation)"),
|
196 |
+
gr.Textbox(label="Prompt", value="a high-quality photo of a modern interior design"),
|
|
|
|
|
|
|
197 |
],
|
198 |
outputs=gr.Image(type="pil", label="Generated Image"),
|
199 |
title="Stable Diffusion ControlNet Depth Demo (with Depth Estimation)",
|