Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
added a bunch of controls, let's try if everything works
  • Loading branch information
jacquesfeng123 committed Apr 23, 2023
1 parent 5da0f15 commit 9639fca
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions modules/api/api.py
Expand Up @@ -210,7 +210,7 @@ def __init__(self, app: FastAPI, queue_lock: Lock):
self.add_api_route("/sdapi/v1/unload-checkpoint", self.unloadapi, methods=["POST"])
self.add_api_route("/sdapi/v1/reload-checkpoint", self.reloadapi, methods=["POST"])
self.add_api_route("/sdapi/v1/scripts", self.get_scripts_list, methods=["GET"], response_model=ScriptsList)
self.add_api_route("/invocations", self.invocations, methods=["POST"], response_model=Union[TextToImageResponse, ImageToImageResponse, ExtrasSingleImageResponse, ExtrasBatchImagesResponse, InvocationsErrorResponse])
self.add_api_route("/invocations", self.invocations, methods=["POST"], response_model=Union[TextToImageResponse, ImageToImageResponse, ExtrasSingleImageResponse, ExtrasBatchImagesResponse,MemoryResponse,List[SDModelItem],List[UpscalerItem],OptionsModel,List[SamplerItem],FlagsModel,ProgressResponse])
self.add_api_route("/ping", self.ping, methods=["GET"], response_model=PingResponse)

self.default_script_arg_txt2img = []
Expand Down Expand Up @@ -523,6 +523,9 @@ def get_config(self):
options.update({key: shared.opts.data.get(key, None)})

return options

def get_all_config(self):
return shared.opts.data

def set_config(self, req: Dict[str, Any]):
for k, v in req.items():
Expand Down Expand Up @@ -762,9 +765,11 @@ def invocations(self, req: InvocationsRequest):
shared.reload_hypernetworks()

if req.options != None:
options = json.loads(req.options)
#here I changed json.loads(req.options) into no need of json.loads()
options = req.options
for key in options:
shared.opts.data[key] = options[key]
print(shared.opts.data)

if req.task == 'text-to-image':
if embeddings_s3uri != '':
Expand All @@ -788,6 +793,41 @@ def invocations(self, req: InvocationsRequest):
response = self.extras_batch_images_api(req.extras_batch_payload)
response.images = self.post_invocations(response.images, quality)
return response
elif req.task == 'set-options':
self.set_config(req.post_options_payload)
print(req.post_options_payload)
print("————————————settings updated———————————")
return
elif req.task == 'get-options':
response = self.get_config()
return response
elif req.task == 'get-SDmodels':
response = self.get_sd_models()
return response
elif req.task == 'get-upscalers':
response = self.get_upscalers()
return response
elif req.task == 'get-samplers':
response = self.get_samplers()
return response
elif req.task == 'interrogate':
response = self.interrogateapi(req.interrogate_payload)
return response
elif req.task == 'get-memory':
response = self.get_memory()
return response
elif req.task == 'get-cmd-flags':
response = self.get_cmd_flags()
return response
elif req.task == 'get-progress':
response = self.progressapi(req.progress_payload)
return response
elif req.task == 'get-all-config':
response = self.get_all_config()
return response
elif req.task == 'do-nothing':
print("nothing has happened")
return
else:
return InvocationsErrorResponse(error = f'Invalid task - {req.task}')

Expand Down

0 comments on commit 9639fca

Please sign in to comment.