This commit is contained in:
jordan 2022-12-10 22:32:57 +11:00
parent 8a3c228f92
commit 7c6d64bb0f

View File

@ -41,7 +41,7 @@ class DiffuseAPI():
return False
except:
return False
def set_styles(self, styles):
if type(styles) == list:
self.styles = styles
@ -65,20 +65,20 @@ class DiffuseAPI():
return True
case _:
return False
def get_orientation(self):
if self.width == 512 and self.height == 512:
return ("square", self.width, self.height)
elif self.width == 1024:
return ("landscape", self.width, self.height)
return ("portrait", self.width, self.height)
def set_nsfw_filter(self, filter_state):
if type(filter_state) == bool:
self.nsfw_enabled = filter_state
return True
return False
def get_nsfw_filter(self):
return self.nsfw_enabled
@ -87,7 +87,7 @@ class DiffuseAPI():
"prompt": prompt,
"styles": self.styles,
"steps": self.num_steps,
"seed": self.ai_seed,
"seed": self.seed,
"n_iter": 1,
"height": self.height,
"width": self.width,
@ -112,17 +112,20 @@ class DiffuseAPI():
alive.close()
await sess.close()
return None
request = await sess.post("/sdapi/v1/txt2img", json=payload)
try:
req_json = await request.json()
request.close()
await sess.close()
return req_json["images", [0]]
except:
return None
async with aiohttp.ClientSession(self.url) as session:
async with session.head('/') as alive:
if alive.status != 200:
return None
async with session.post("/sdapi/v1/txt2img", json=payload) as image_json:
image_data = await image_json.json()
return image_data["images"][0]
# try:
# req_json = await request.json()
# request.close()
# await sess.close()
# return req_json["images"][0]
# except:
# return None