2022-12-11 13:46:29 +01:00
|
|
|
from pydantic import BaseModel
|
2022-09-02 10:28:36 +02:00
|
|
|
|
2022-12-11 13:46:29 +01:00
|
|
|
from modules.types import GenerateImageRequest
|
|
|
|
|
|
|
|
class TaskData(BaseModel):
|
2022-12-08 06:42:46 +01:00
|
|
|
request_id: str = None
|
2022-09-14 18:59:42 +02:00
|
|
|
session_id: str = "session"
|
2022-09-02 10:28:36 +02:00
|
|
|
save_to_disk_path: str = None
|
|
|
|
turbo: bool = True
|
2022-12-12 09:31:47 +01:00
|
|
|
|
2022-09-09 17:35:24 +02:00
|
|
|
use_face_correction: str = None # or "GFPGANv1.3"
|
|
|
|
use_upscale: str = None # or "RealESRGAN_x4plus" or "RealESRGAN_x4plus_anime_6B"
|
2022-10-06 10:58:02 +02:00
|
|
|
use_stable_diffusion_model: str = "sd-v1-4"
|
2022-10-28 16:36:44 +02:00
|
|
|
use_vae_model: str = None
|
2022-12-07 06:54:16 +01:00
|
|
|
use_hypernetwork_model: str = None
|
2022-12-12 09:31:47 +01:00
|
|
|
|
2022-09-09 17:35:24 +02:00
|
|
|
show_only_filtered_image: bool = False
|
2022-10-06 11:35:34 +02:00
|
|
|
output_format: str = "jpeg" # or "png"
|
2022-12-05 06:32:33 +01:00
|
|
|
output_quality: int = 75
|
2022-12-12 09:31:47 +01:00
|
|
|
metadata_output_format: str = "txt" # or "json"
|
2022-09-14 18:59:42 +02:00
|
|
|
stream_image_progress: bool = False
|
2022-09-14 13:22:03 +02:00
|
|
|
|
2022-09-02 10:28:36 +02:00
|
|
|
class Image:
|
|
|
|
data: str # base64
|
|
|
|
seed: int
|
|
|
|
is_nsfw: bool
|
2022-09-14 06:45:35 +02:00
|
|
|
path_abs: str = None
|
2022-09-02 10:28:36 +02:00
|
|
|
|
|
|
|
def __init__(self, data, seed):
|
|
|
|
self.data = data
|
|
|
|
self.seed = seed
|
|
|
|
|
|
|
|
def json(self):
|
|
|
|
return {
|
|
|
|
"data": self.data,
|
|
|
|
"seed": self.seed,
|
2022-09-14 06:45:35 +02:00
|
|
|
"path_abs": self.path_abs,
|
2022-09-02 10:28:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class Response:
|
2022-12-11 13:46:29 +01:00
|
|
|
render_request: GenerateImageRequest
|
|
|
|
task_data: TaskData
|
2022-09-02 10:28:36 +02:00
|
|
|
images: list
|
|
|
|
|
2022-12-11 13:46:29 +01:00
|
|
|
def __init__(self, render_request: GenerateImageRequest, task_data: TaskData, images: list):
|
|
|
|
self.render_request = render_request
|
|
|
|
self.task_data = task_data
|
2022-12-08 17:09:09 +01:00
|
|
|
self.images = images
|
|
|
|
|
2022-09-02 10:28:36 +02:00
|
|
|
def json(self):
|
|
|
|
res = {
|
|
|
|
"status": 'succeeded',
|
2022-12-11 13:46:29 +01:00
|
|
|
"render_request": self.render_request.dict(),
|
|
|
|
"task_data": self.task_data.dict(),
|
2022-09-02 10:28:36 +02:00
|
|
|
"output": [],
|
|
|
|
}
|
|
|
|
|
|
|
|
for image in self.images:
|
|
|
|
res["output"].append(image.json())
|
|
|
|
|
|
|
|
return res
|
2022-12-08 17:09:09 +01:00
|
|
|
|
|
|
|
class UserInitiatedStop(Exception):
|
|
|
|
pass
|