-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fa1b8b
commit 7c9b02a
Showing
7 changed files
with
334 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from handlers.basehandler import BaseHandler | ||
import random | ||
import time | ||
|
||
|
||
""" | ||
Handler classes are generally bound to a specific workflow file. | ||
To modify values we have to be confident in the json structure. | ||
One exception - RawWorkflow will send payload['workflow_json'] to the ComfyUI API - TODO | ||
""" | ||
|
||
class Image2Image(BaseHandler): | ||
|
||
WORKFLOW_JSON = "/opt/serverless/workflows/image2image.json" | ||
|
||
def __init__(self, payload): | ||
super().__init__(payload, self.WORKFLOW_JSON) | ||
self.apply_modifiers() | ||
|
||
|
||
def apply_modifiers(self): | ||
timestr = time.strftime("%Y%m%d-%H%M%S") | ||
self.prompt["prompt"]["3"]["inputs"]["seed"] = self.get_value( | ||
"seed", | ||
random.randint(0,2**32)) | ||
self.prompt["prompt"]["3"]["inputs"]["steps"] = self.get_value( | ||
"steps", | ||
20) | ||
self.prompt["prompt"]["3"]["inputs"]["sampler_name"] = self.get_value( | ||
"sampler_name", | ||
"dpmpp_2m") | ||
self.prompt["prompt"]["3"]["inputs"]["scheduler"] = self.get_value( | ||
"scheduler", | ||
"normal") | ||
self.prompt["prompt"]["3"]["inputs"]["denoise"] = self.get_value( | ||
"denoise", | ||
0.8700000000000001) | ||
self.prompt["prompt"]["6"]["inputs"]["text"] = self.get_value( | ||
"include_text", | ||
"") | ||
self.prompt["prompt"]["7"]["inputs"]["text"] = self.get_value( | ||
"exclude_text", | ||
"") | ||
self.prompt["prompt"]["9"]["inputs"]["filename_prefix"] = f"{self.request_id}/img-{timestr}" | ||
self.prompt["prompt"]["10"]["inputs"]["image"] = self.get_value( | ||
"input_image", | ||
"") | ||
self.prompt["prompt"]["14"]["inputs"]["ckpt_name"] = self.get_value( | ||
"ckpt_name", | ||
"v1-5-pruned-emaonly.ckpt") | ||
|
||
|
||
""" | ||
Example Request Body: | ||
{ | ||
"input": { | ||
"handler": "Image2Image", | ||
"aws_bucket_name": "ai-dock", | ||
"ckpt_name": "v1-5-pruned-emaonly.ckpt", | ||
"include_text": "photograph of a victorian woman, arms outstretched with angel wings. cloudy sky, meadow grass", | ||
"exclude_text": "watermark, text", | ||
"denoise": 0.87, | ||
"input_image": "https://raw.githubusercontent.com/comfyanonymous/ComfyUI/master/input/example.png" | ||
} | ||
} | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from handlers.basehandler import BaseHandler | ||
import random | ||
|
||
|
||
""" | ||
Handler classes are generally bound to a specific workflow file. | ||
To modify values we have to be confident in the json structure. | ||
One exception - RawWorkflow will send payload['workflow_json'] to the ComfyUI API - TODO | ||
""" | ||
|
||
class RawWorkflow(BaseHandler): | ||
|
||
WORKFLOW_JSON = None | ||
|
||
def __init__(self, payload): | ||
super().__init__(payload, self.WORKFLOW_JSON) | ||
self.apply_modifiers() | ||
|
||
|
||
def apply_modifiers(self): | ||
# TODO - Parse the workflow for image URLs, download and update the prompt | ||
pass | ||
|
||
|
||
|
||
""" | ||
Example Request Body: | ||
{ | ||
"input": { | ||
"handler": "RawWorkflow", | ||
"aws_bucket_name": "ai-dock", | ||
"workflow_json": { | ||
"3": { | ||
"inputs": { | ||
"seed": 12345, | ||
"steps": 20, | ||
"cfg": 8, | ||
"sampler_name": "euler", | ||
"scheduler": "normal", | ||
"denoise": 1, | ||
"model": [ | ||
"4", | ||
0 | ||
], | ||
"positive": [ | ||
"6", | ||
0 | ||
], | ||
"negative": [ | ||
"7", | ||
0 | ||
], | ||
"latent_image": [ | ||
"5", | ||
0 | ||
] | ||
}, | ||
"class_type": "KSampler" | ||
}, | ||
"4": { | ||
"inputs": { | ||
"ckpt_name": "v1-5-pruned-emaonly.ckpt" | ||
}, | ||
"class_type": "CheckpointLoaderSimple" | ||
}, | ||
"5": { | ||
"inputs": { | ||
"width": 1024, | ||
"height": 1024, | ||
"batch_size": 1 | ||
}, | ||
"class_type": "EmptyLatentImage" | ||
}, | ||
"6": { | ||
"inputs": { | ||
"text": "a penguin chasing a polar bear", | ||
"clip": [ | ||
"4", | ||
1 | ||
] | ||
}, | ||
"class_type": "CLIPTextEncode" | ||
}, | ||
"7": { | ||
"inputs": { | ||
"text": "text, watermark", | ||
"clip": [ | ||
"4", | ||
1 | ||
] | ||
}, | ||
"class_type": "CLIPTextEncode" | ||
}, | ||
"8": { | ||
"inputs": { | ||
"samples": [ | ||
"3", | ||
0 | ||
], | ||
"vae": [ | ||
"4", | ||
2 | ||
] | ||
}, | ||
"class_type": "VAEDecode" | ||
}, | ||
"9": { | ||
"inputs": { | ||
"filename_prefix": "image", | ||
"images": [ | ||
"8", | ||
0 | ||
] | ||
}, | ||
"class_type": "SaveImage" | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"3": { | ||
"inputs": { | ||
"seed": 12345, | ||
"steps": 20, | ||
"cfg": 8, | ||
"sampler_name": "dpmpp_2m", | ||
"scheduler": "normal", | ||
"denoise": 0.8700000000000001, | ||
"model": [ | ||
"14", | ||
0 | ||
], | ||
"positive": [ | ||
"6", | ||
0 | ||
], | ||
"negative": [ | ||
"7", | ||
0 | ||
], | ||
"latent_image": [ | ||
"12", | ||
0 | ||
] | ||
}, | ||
"class_type": "KSampler" | ||
}, | ||
"6": { | ||
"inputs": { | ||
"text": "pos prompt", | ||
"clip": [ | ||
"14", | ||
1 | ||
] | ||
}, | ||
"class_type": "CLIPTextEncode" | ||
}, | ||
"7": { | ||
"inputs": { | ||
"text": "neg prompt", | ||
"clip": [ | ||
"14", | ||
1 | ||
] | ||
}, | ||
"class_type": "CLIPTextEncode" | ||
}, | ||
"8": { | ||
"inputs": { | ||
"samples": [ | ||
"3", | ||
0 | ||
], | ||
"vae": [ | ||
"14", | ||
2 | ||
] | ||
}, | ||
"class_type": "VAEDecode" | ||
}, | ||
"9": { | ||
"inputs": { | ||
"filename_prefix": "image", | ||
"images": [ | ||
"8", | ||
0 | ||
] | ||
}, | ||
"class_type": "SaveImage" | ||
}, | ||
"10": { | ||
"inputs": { | ||
"image": "example.png", | ||
"choose file to upload": "image" | ||
}, | ||
"class_type": "LoadImage" | ||
}, | ||
"12": { | ||
"inputs": { | ||
"pixels": [ | ||
"10", | ||
0 | ||
], | ||
"vae": [ | ||
"14", | ||
2 | ||
] | ||
}, | ||
"class_type": "VAEEncode" | ||
}, | ||
"14": { | ||
"inputs": { | ||
"ckpt_name": "v1-5-pruned-emaonly.ckpt" | ||
}, | ||
"class_type": "CheckpointLoaderSimple" | ||
} | ||
} |