Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -168,36 +168,33 @@ def process_image(img, width, height):
|
|
| 168 |
return img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
| 169 |
|
| 170 |
|
| 171 |
-
def
|
| 172 |
-
print(f"{datetime.datetime.now()}
|
| 173 |
-
|
| 174 |
-
load_model(model_path, "txt2img")
|
| 175 |
prompt = current_model.prefix + prompt
|
| 176 |
-
|
| 177 |
result = pipe(
|
| 178 |
prompt,
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
num_images_per_prompt=n_images,
|
| 181 |
num_inference_steps=int(steps),
|
| 182 |
guidance_scale=guidance,
|
| 183 |
width=width,
|
| 184 |
height=height,
|
| 185 |
generator=generator,
|
| 186 |
-
|
| 187 |
)
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
|
| 193 |
-
print(f"{datetime.datetime.now()} img_to_img, model: {model_path}")
|
| 194 |
-
|
| 195 |
-
load_model(model_path, "img2img")
|
| 196 |
-
prompt = current_model.prefix + prompt
|
| 197 |
img = process_image(img, width, height)
|
| 198 |
-
|
| 199 |
-
result = pipe(
|
| 200 |
-
prompt,
|
| 201 |
negative_prompt=neg_prompt,
|
| 202 |
num_images_per_prompt=n_images,
|
| 203 |
image=img,
|
|
@@ -205,11 +202,9 @@ def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance
|
|
| 205 |
strength=strength,
|
| 206 |
guidance_scale=guidance,
|
| 207 |
generator=generator,
|
| 208 |
-
|
| 209 |
)
|
| 210 |
|
| 211 |
-
return replace_nsfw_images(result)
|
| 212 |
-
|
| 213 |
def replace_nsfw_images(results):
|
| 214 |
|
| 215 |
if is_colab:
|
|
|
|
| 168 |
return img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
| 169 |
|
| 170 |
|
| 171 |
+
def inference_image(pipe, model_path, prompt, mode, *args, **kwargs):
|
| 172 |
+
print(f"{datetime.datetime.now()} {mode}, model: {model_path}")
|
| 173 |
+
load_model(pipe, model_path, mode)
|
|
|
|
| 174 |
prompt = current_model.prefix + prompt
|
|
|
|
| 175 |
result = pipe(
|
| 176 |
prompt,
|
| 177 |
+
*args,
|
| 178 |
+
**kwargs,
|
| 179 |
+
callback=pipe_callback
|
| 180 |
+
)
|
| 181 |
+
return replace_nsfw_images(result)
|
| 182 |
+
|
| 183 |
+
def txt_to_img(pipe, model_path, prompt, n_images, neg_prompt, guidance, steps, width, height, generator, seed):
|
| 184 |
+
return inference_image(pipe, model_path, prompt, "txt2img",
|
| 185 |
+
negative_prompt=neg_prompt,
|
| 186 |
num_images_per_prompt=n_images,
|
| 187 |
num_inference_steps=int(steps),
|
| 188 |
guidance_scale=guidance,
|
| 189 |
width=width,
|
| 190 |
height=height,
|
| 191 |
generator=generator,
|
| 192 |
+
seed=seed
|
| 193 |
)
|
| 194 |
|
| 195 |
+
def img_to_img(pipe, model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
img = process_image(img, width, height)
|
| 197 |
+
return inference_image(pipe, model_path, prompt, "img2img",
|
|
|
|
|
|
|
| 198 |
negative_prompt=neg_prompt,
|
| 199 |
num_images_per_prompt=n_images,
|
| 200 |
image=img,
|
|
|
|
| 202 |
strength=strength,
|
| 203 |
guidance_scale=guidance,
|
| 204 |
generator=generator,
|
| 205 |
+
seed=seed
|
| 206 |
)
|
| 207 |
|
|
|
|
|
|
|
| 208 |
def replace_nsfw_images(results):
|
| 209 |
|
| 210 |
if is_colab:
|