Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -123,54 +123,59 @@ def inference(
|
|
123 |
use_qr_code_as_init_image = True,
|
124 |
sampler = "DPM++ Karras SDE",
|
125 |
):
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
|
130 |
-
raise gr.Error("QR Code Image or QR Code Content is required")
|
131 |
|
132 |
-
|
133 |
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
)
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
else:
|
150 |
-
print("Using QR Code Image")
|
151 |
-
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
152 |
-
|
153 |
-
# hack due to gradio examples
|
154 |
-
init_image = qrcode_image
|
155 |
-
|
156 |
-
out = pipe(
|
157 |
-
prompt=prompt,
|
158 |
-
negative_prompt=negative_prompt,
|
159 |
-
image=qrcode_image,
|
160 |
-
control_image=qrcode_image, # type: ignore
|
161 |
-
width=768, # type: ignore
|
162 |
-
height=768, # type: ignore
|
163 |
-
guidance_scale=float(guidance_scale),
|
164 |
-
controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
|
165 |
-
generator=generator,
|
166 |
-
strength=float(strength),
|
167 |
-
num_inference_steps=50,
|
168 |
-
)
|
169 |
-
return out.images[0] # type: ignore
|
170 |
|
171 |
|
172 |
|
173 |
-
with gr.Blocks(theme=
|
174 |
gr.Markdown(
|
175 |
"""
|
176 |

|
|
|
123 |
use_qr_code_as_init_image = True,
|
124 |
sampler = "DPM++ Karras SDE",
|
125 |
):
|
126 |
+
try:
|
127 |
+
if prompt is None or prompt == "":
|
128 |
+
raise gr.Error("Prompt is required")
|
129 |
+
|
130 |
+
if qrcode_image is None and qr_code_content == "":
|
131 |
+
raise gr.Error("QR Code Image or QR Code Content is required")
|
132 |
|
133 |
+
pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
|
|
|
134 |
|
135 |
+
generator = torch.manual_seed(seed) if seed != -1 else torch.Generator()
|
136 |
|
137 |
+
if qr_code_content != "" or qrcode_image.size == (1, 1):
|
138 |
+
print("Generating QR Code from content")
|
139 |
+
qr = qrcode.QRCode(
|
140 |
+
version=1,
|
141 |
+
error_correction=qrcode.constants.ERROR_CORRECT_H,
|
142 |
+
box_size=10,
|
143 |
+
border=4,
|
144 |
+
)
|
145 |
+
qr.add_data(qr_code_content)
|
146 |
+
qr.make(fit=True)
|
147 |
|
148 |
+
qrcode_image = qr.make_image(fill_color="black", back_color="white")
|
149 |
+
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
150 |
+
else:
|
151 |
+
print("Using QR Code Image")
|
152 |
+
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
153 |
+
|
154 |
+
# hack due to gradio examples
|
155 |
+
init_image = qrcode_image
|
156 |
+
|
157 |
+
out = pipe(
|
158 |
+
prompt=prompt,
|
159 |
+
negative_prompt=negative_prompt,
|
160 |
+
image=qrcode_image,
|
161 |
+
control_image=qrcode_image, # type: ignore
|
162 |
+
width=768, # type: ignore
|
163 |
+
height=768, # type: ignore
|
164 |
+
guidance_scale=float(guidance_scale),
|
165 |
+
controlnet_conditioning_scale=float(controlnet_conditioning_scale), # type: ignore
|
166 |
+
generator=generator,
|
167 |
+
strength=float(strength),
|
168 |
+
num_inference_steps=50,
|
169 |
)
|
170 |
+
return out.images[0] # type: ignore
|
171 |
+
except Exception as e:
|
172 |
+
print(f"Error in inference: {str(e)}")
|
173 |
+
# Return a blank image in case of an error
|
174 |
+
return Image.new('RGB', (768, 768), color='white')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
|
176 |
|
177 |
|
178 |
+
with gr.Blocks(theme='Hev832/Applio'()) as blocks:
|
179 |
gr.Markdown(
|
180 |
"""
|
181 |

|