sim04ful
commited on
Commit
•
7427e59
1
Parent(s):
9d33879
moved to new arible statefulschema
Browse files- handler.py +20 -6
handler.py
CHANGED
@@ -52,12 +52,12 @@ def load_models():
|
|
52 |
"lllyasviel/control_v11f1e_sd15_tile",
|
53 |
torch_dtype=torch.float16,
|
54 |
)
|
55 |
-
|
56 |
controlnet_brightness = ControlNetModel.from_pretrained(
|
57 |
"ioclab/control_v1p_sd15_brightness",
|
58 |
torch_dtype=torch.float16,
|
59 |
)
|
60 |
-
|
61 |
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
62 |
MODEL_ID,
|
63 |
controlnet=[
|
@@ -68,12 +68,12 @@ def load_models():
|
|
68 |
cache_dir="cache",
|
69 |
# local_files_only=True,
|
70 |
)
|
71 |
-
|
72 |
pipe.to("cuda")
|
73 |
|
74 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
75 |
pipe.enable_vae_slicing()
|
76 |
-
|
77 |
return pipe
|
78 |
|
79 |
|
@@ -130,7 +130,20 @@ def generate_image_with_conditioning_scale(**inputs):
|
|
130 |
image=[qr_image] * 2,
|
131 |
).images
|
132 |
|
133 |
-
return [{"data": image_to_base64(image), "format": "png"} for image in images]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
|
136 |
def generate_image(pipe, inputs):
|
@@ -161,6 +174,7 @@ class EndpointHandler:
|
|
161 |
def __init__(self, path=""):
|
162 |
self._model = load_models()
|
163 |
|
164 |
-
def __call__(self, model_input: Dict[str, Any])
|
165 |
images = generate_image(self._model, model_input)
|
|
|
166 |
return images
|
|
|
52 |
"lllyasviel/control_v11f1e_sd15_tile",
|
53 |
torch_dtype=torch.float16,
|
54 |
)
|
55 |
+
|
56 |
controlnet_brightness = ControlNetModel.from_pretrained(
|
57 |
"ioclab/control_v1p_sd15_brightness",
|
58 |
torch_dtype=torch.float16,
|
59 |
)
|
60 |
+
|
61 |
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
62 |
MODEL_ID,
|
63 |
controlnet=[
|
|
|
68 |
cache_dir="cache",
|
69 |
# local_files_only=True,
|
70 |
)
|
71 |
+
|
72 |
pipe.to("cuda")
|
73 |
|
74 |
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
75 |
pipe.enable_vae_slicing()
|
76 |
+
|
77 |
return pipe
|
78 |
|
79 |
|
|
|
130 |
image=[qr_image] * 2,
|
131 |
).images
|
132 |
|
133 |
+
# return [{"data": image_to_base64(image), "format": "png"} for image in images]
|
134 |
+
|
135 |
+
return {
|
136 |
+
"fields": [
|
137 |
+
{
|
138 |
+
"name": "output",
|
139 |
+
"type": "Image",
|
140 |
+
"value": [
|
141 |
+
f"data:image/png;base64,{image_to_base64(image)}"
|
142 |
+
for image in images
|
143 |
+
],
|
144 |
+
}
|
145 |
+
]
|
146 |
+
}
|
147 |
|
148 |
|
149 |
def generate_image(pipe, inputs):
|
|
|
174 |
def __init__(self, path=""):
|
175 |
self._model = load_models()
|
176 |
|
177 |
+
def __call__(self, model_input: Dict[str, Any]):
|
178 |
images = generate_image(self._model, model_input)
|
179 |
+
yield {"fields": [{"name": "progress", "type": "Progress"}]}
|
180 |
return images
|