Update handler.py
Browse files- handler.py +22 -3
handler.py
CHANGED
|
@@ -37,6 +37,28 @@ class EndpointHandler():
|
|
| 37 |
self.generator = torch.Generator(device="cpu").manual_seed(3)
|
| 38 |
|
| 39 |
def __call__(self, data: Any) -> Dict[str, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Extract parameters from the payload
|
| 41 |
prompt = data.get("prompt", None)
|
| 42 |
negative_prompt = data.get("negative_prompt", None)
|
|
@@ -45,8 +67,6 @@ class EndpointHandler():
|
|
| 45 |
num_inference_steps = data.get("steps", 30)
|
| 46 |
guidance_scale = data.get("cfg_scale", 7)
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
# Extract controlnet configuration from payload
|
| 51 |
controlnet_config = data.get("alwayson_scripts", {}).get("controlnet", {}).get("args", [{}])[0]
|
| 52 |
|
|
@@ -61,7 +81,6 @@ class EndpointHandler():
|
|
| 61 |
width=width,
|
| 62 |
controlnet_conditioning_scale=1.0,
|
| 63 |
generator=self.generator,
|
| 64 |
-
|
| 65 |
)
|
| 66 |
|
| 67 |
# Get the generated image
|
|
|
|
| 37 |
self.generator = torch.Generator(device="cpu").manual_seed(3)
|
| 38 |
|
| 39 |
def __call__(self, data: Any) -> Dict[str, str]:
|
| 40 |
+
# Example JSON payload for testing
|
| 41 |
+
example_payload = {
|
| 42 |
+
"prompt": "a beautiful landscape",
|
| 43 |
+
"negative_prompt": "blur",
|
| 44 |
+
"width": 1024,
|
| 45 |
+
"height": 1024,
|
| 46 |
+
"steps": 30,
|
| 47 |
+
"cfg_scale": 7,
|
| 48 |
+
"alwayson_scripts": {
|
| 49 |
+
"controlnet": {
|
| 50 |
+
"args": [
|
| 51 |
+
{
|
| 52 |
+
"enabled": True,
|
| 53 |
+
"input_image": "image in base64",
|
| 54 |
+
"model": "control_sd15_depth [fef5e48e]",
|
| 55 |
+
"control_mode": "Balanced"
|
| 56 |
+
}
|
| 57 |
+
]
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
# Extract parameters from the payload
|
| 63 |
prompt = data.get("prompt", None)
|
| 64 |
negative_prompt = data.get("negative_prompt", None)
|
|
|
|
| 67 |
num_inference_steps = data.get("steps", 30)
|
| 68 |
guidance_scale = data.get("cfg_scale", 7)
|
| 69 |
|
|
|
|
|
|
|
| 70 |
# Extract controlnet configuration from payload
|
| 71 |
controlnet_config = data.get("alwayson_scripts", {}).get("controlnet", {}).get("args", [{}])[0]
|
| 72 |
|
|
|
|
| 81 |
width=width,
|
| 82 |
controlnet_conditioning_scale=1.0,
|
| 83 |
generator=self.generator,
|
|
|
|
| 84 |
)
|
| 85 |
|
| 86 |
# Get the generated image
|