wolverinn
commited on
Commit
·
4bbe159
1
Parent(s):
27ed9e0
add more params for replicate
Browse files- predict.py +42 -4
predict.py
CHANGED
|
@@ -6,6 +6,7 @@ from cog import BasePredictor, Input, Path
|
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
import signal
|
|
|
|
| 9 |
import re
|
| 10 |
from typing import Dict, List, Any
|
| 11 |
|
|
@@ -75,13 +76,50 @@ def initialize():
|
|
| 75 |
shared.opts.onchange("temp_dir", ui_tempdir.on_tmpdir_changed)
|
| 76 |
|
| 77 |
# make the program just exit at ctrl+c without waiting for anything
|
| 78 |
-
def sigint_handler(sig, frame):
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
-
signal.signal(signal.SIGINT, sigint_handler)
|
| 83 |
|
| 84 |
class Predictor(BasePredictor):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def setup(self):
|
| 86 |
"""Load the model into memory to make running multiple predictions efficient"""
|
| 87 |
initialize()
|
|
|
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
import signal
|
| 9 |
+
import time
|
| 10 |
import re
|
| 11 |
from typing import Dict, List, Any
|
| 12 |
|
|
|
|
| 76 |
shared.opts.onchange("temp_dir", ui_tempdir.on_tmpdir_changed)
|
| 77 |
|
| 78 |
# make the program just exit at ctrl+c without waiting for anything
|
| 79 |
+
# def sigint_handler(sig, frame):
|
| 80 |
+
# print(f'Interrupted with signal {sig} in {frame}')
|
| 81 |
+
# os._exit(0)
|
| 82 |
|
| 83 |
+
# signal.signal(signal.SIGINT, sigint_handler)
|
| 84 |
|
| 85 |
class Predictor(BasePredictor):
|
| 86 |
+
def setup(self):
|
| 87 |
+
"""Load the model into memory to make running multiple predictions efficient"""
|
| 88 |
+
initialize()
|
| 89 |
+
|
| 90 |
+
def predict(
|
| 91 |
+
self,
|
| 92 |
+
prompt: str = Input(description="prompt en", default="lora:koreanDollLikeness_v15:0.66, best quality, ultra high res, (photorealistic:1.4), 1girl, beige sweater, black choker, smile, laughing, bare shoulders, solo focus, ((full body), (brown hair:1), looking at viewer"),
|
| 93 |
+
negative_prompt: str = Input(description="negative prompt", default="paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans, (ugly:1.331), (duplicate:1.331), (morbid:1.21), (mutilated:1.21), (tranny:1.331), mutated hands, (poorly drawn hands:1.331), blurry, 3hands,4fingers,3arms, bad anatomy, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts,poorly drawn face,mutation,deformed"),
|
| 94 |
+
sampler_name: str = Input(description="sampler name", default="DPM++ SDE Karras", choices=["DPM++ SDE Karras", "DPM++ 2M Karras", "DPM++ 2S a Karras", "DPM2 a Karras", "DPM2 Karras", "LMS Karras", "DPM adaptive", "DPM fast", "DPM++ SDE", "DPM++ 2M", "DPM++ 2S a", "DPM2 a", "DPM2", "Heun", "LMS", "Euler", "Euler a"]),
|
| 95 |
+
steps: int = Input(description="steps", default=20),
|
| 96 |
+
cfg_scale: int = Input(description="cfg scale", default=8),
|
| 97 |
+
width: int = Input(description="width", default=512),
|
| 98 |
+
height: int = Input(description="height", default=768),
|
| 99 |
+
seed: int = Input(description="seed", default=-1),
|
| 100 |
+
) -> Path:
|
| 101 |
+
"""Run a single prediction on the model"""
|
| 102 |
+
args = {
|
| 103 |
+
"do_not_save_samples": True,
|
| 104 |
+
"do_not_save_grid": True,
|
| 105 |
+
"outpath_samples": "./output",
|
| 106 |
+
"prompt": prompt,
|
| 107 |
+
"negative_prompt": negative_prompt,
|
| 108 |
+
"sampler_name": sampler_name,
|
| 109 |
+
"steps": steps, # 25
|
| 110 |
+
"cfg_scale": cfg_scale,
|
| 111 |
+
"width": width,
|
| 112 |
+
"height": height,
|
| 113 |
+
"seed": seed,
|
| 114 |
+
}
|
| 115 |
+
p = StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)
|
| 116 |
+
processed = process_images(p)
|
| 117 |
+
filename = str(int(time.time())) + ".png"
|
| 118 |
+
processed.images[0].save(fp=filename, format="PNG")
|
| 119 |
+
# single_image_b64 = encode_pil_to_base64(processed.images[0]).decode('utf-8')
|
| 120 |
+
return Path(filename)
|
| 121 |
+
|
| 122 |
+
class PredictorOld(BasePredictor):
|
| 123 |
def setup(self):
|
| 124 |
"""Load the model into memory to make running multiple predictions efficient"""
|
| 125 |
initialize()
|