lllyasviel / stable-diffusion-webui-forge

GNU Affero General Public License v3.0
8.07k stars 790 forks source link

pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'> #2133

Open vaskers5 opened 20 hours ago

vaskers5 commented 20 hours ago

Here is code example:

import requests

gen_conf = {'enable_hr': False, 'denoising_strength': 1,
            'firstphase_width': 0, 'firstphase_height': 0,
            'hr_scale': 2, 'hr_upscaler': 'string', 'hr_second_pass_steps': 0,
            'hr_resize_x': 0, 'hr_resize_y': 0,
            'hr_sampler_name': 'string',
            'hr_prompt': '', 'hr_negative_prompt': '',
            'styles': ['string'], 'seed': -1, 'subseed': -1, 'subseed_strength': 0,
            'seed_resize_from_h': -1, 'seed_resize_from_w': -1, 'batch_size': 1,
            'n_iter': 1, 'restore_faces': False, 'tiling': False, 'do_not_save_samples': False,
            'do_not_save_grid': False, 'eta': 0, 's_min_uncond': 5, 's_churn': 0, 's_tmax': None, 's_tmin': 0,
            's_noise': 1, 'override_settings_restore_afterwards': True, 'script_args': [], 'send_images': True, 'save_images': False, 'alwayson_scripts': {},
            'prompt': 'photo, closeup face portrait, female, (__lovescape-european__:1.4) , (Average:1.2) body BREAK female, (Blond:1.1) hair, (Straight:1.1) hairstyle BREAK female, (24 yo, young:1). (__lovescape-lips-2__:1), (__lovescape-noses-2__:1) nose, (__lovescape-faces-2__:1), (__lovescape-eyes-2__:1), (__lovescape-jaw-2__:1) jaw, (__lovescape-brows-2__:1) brows , (Fitness coach:1) occupation, ({tall|medium|short}:1) body height',
            'negative_prompt': 'nude, naked, topless', 'steps': 6, 'cfg_scale': 3, 'width': 768, 'height': 1024,
            'override_settings': {'sd_model_checkpoint': 'dreamshaperXL_v21TurboDPMSDE.safetensors', 'CLIP_stop_at_last_layers': 2},
            'sampler_index': 'DPM++ SDE', 'scheduler': 'Karras'}

url = "http://0.0.0.0:7862/sdapi/v1/txt2img"

from PIL import Image
import base64
import io

gen_conf_1 = gen_conf.copy()
gen_conf_1['override_settings']['sd_model_checkpoint'] = 'colorfulxl_v70'

response = requests.post(
                    url=url,
                    headers={"accept": "application/json"},
                    json=gen_conf,
                )
img = response.json()["images"][0].split(",", 1)[0]

# Decode the base64 string
img_data = base64.b64decode(img)

# Create a BytesIO object from the decoded data
img_buffer = io.BytesIO(img_data) 

# Create a PIL image from the BytesIO object
image = Image.open(img_buffer)

# Display the image
image.show()

here is error log:

`{ "name": "JSONDecodeError", "message": "Expecting value: line 1 column 1 (char 0)", "stack": "--------------------------------------------------------------------------- JSONDecodeError Traceback (most recent call last) File ~/anaconda3/envs/work/lib/python3.10/site-packages/requests/models.py:974, in Response.json(self, kwargs) 973 try: --> 974 return complexjson.loads(self.text, kwargs) 975 except JSONDecodeError as e: 976 # Catch JSON-related errors and raise as requests.JSONDecodeError 977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~/anaconda3/envs/work/lib/python3.10/json/init.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 343 if (cls is None and object_hook is None and 344 parse_int is None and parse_float is None and 345 parse_constant is None and object_pairs_hook is None and not kw): --> 346 return _default_decoder.decode(s) 347 if cls is None:

File ~/anaconda3/envs/work/lib/python3.10/json/decoder.py:337, in JSONDecoder.decode(self, s, _w) 333 \"\"\"Return the Python representation of s (a str instance 334 containing a JSON document). 335 336 \"\"\" --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end()

File ~/anaconda3/envs/work/lib/python3.10/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError(\"Expecting value\", s, err.value) from None 356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last) Cell In[7], line 14 7 gen_conf_1['override_settings']['sd_model_checkpoint'] = 'colorfulxl_v70' 9 response = requests.post( 10 url=url, 11 headers={\"accept\": \"application/json\"}, 12 json=gen_conf, 13 ) ---> 14 img = response.json()[\"images\"][0].split(\",\", 1)[0] 16 # Decode the base64 string 17 img_data = base64.b64decode(img)

File ~/anaconda3/envs/work/lib/python3.10/site-packages/requests/models.py:978, in Response.json(self, kwargs) 974 return complexjson.loads(self.text, kwargs) 975 except JSONDecodeError as e: 976 # Catch JSON-related errors and raise as requests.JSONDecodeError 977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError --> 978 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)" } `

vaskers5 commented 20 hours ago

working on fix, looks like simple pydantic bug

rockiecxh commented 18 hours ago

encountered the same issue

dermesut commented 13 hours ago

same here. txt2img via api is broken now. img2img works.

altoiddealer commented 13 hours ago

Here to report the same issue.

Traceback (most recent call last):
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\route_utils.py", line 724, in __call__
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__
    raise e
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\routing.py", line 292, in app
    content = await serialize_response(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\routing.py", line 160, in serialize_response    return field.serialize(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\_compat.py", line 147, in serialize
    return self._type_adapter.dump_python(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\type_adapter.py", line 142, in wrapped
    return func(self, *args, **kwargs)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\type_adapter.py", line 458, in dump_python
    return self.serializer.to_python(
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'>
hwoitke commented 10 hours ago

Same issue. (calling the API via typescript client).

vaskers5 commented 9 hours ago

https://github.com/lllyasviel/stable-diffusion-webui-forge/pull/2138

I fixed it here, just a simple bug

KINGOAL commented 2 hours ago

Similar issue when call from web:

ERROR: Exception in ASGI application████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:05<00:00, 6.52it/s] Traceback (most recent call last): File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 404, in run_asgi result = await app( # type: ignore[func-returns-value] File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in call return await self.app(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi\applications.py", line 1106, in call await super().call(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\middleware\errors.py", line 184, in call raise exc File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\middleware\errors.py", line 162, in call await self.app(scope, receive, _send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\gradio\route_utils.py", line 730, in call await self.simple_response(scope, receive, send, request_headers=headers) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\gradio\route_utils.py", line 746, in simple_response await self.app(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\middleware\exceptions.py", line 79, in call raise exc File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\middleware\exceptions.py", line 68, in call await self.app(scope, receive, sender) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in call raise e File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in call await self.app(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\routing.py", line 718, in call await route.handle(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\routing.py", line 276, in handle await self.app(scope, receive, send) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\starlette\routing.py", line 66, in app response = await func(request) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi\routing.py", line 292, in app content = await serialize_response( File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi\routing.py", line 160, in serialize_response return field.serialize( File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\fastapi_compat.py", line 147, in serialize return self._type_adapter.dump_python( File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\pydantic\type_adapter.py", line 142, in wrapped return func(self, *args, **kwargs) File "E:\webui_forge_cu121_torch21\system\python\lib\site-packages\pydantic\type_adapter.py", line 458, in dump_python return self.serializer.to_python( pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'>

dermesut commented 39 minutes ago

2138

I fixed it here, just a simple bug

doesn't work for me. results in: " File "E:\ai_gh_repos\webui_forge_cu121_torch231_EXP\webui\modules\api\api.py", line 475, in text2imgapi with closing(StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, **args)) as p: File "", line 58, in init TypeError: 'NoneType' object is not callable "

vaskers5 commented 1 minute ago

I'm not sure but is not connected with pydantic

2138

I fixed it here, just a simple bug

doesn't work for me. results in: " File "E:\ai_gh_repos\webui_forge_cu121_torch231_EXP\webui\modules\api\api.py", line 475, in text2imgapi with closing(StableDiffusionProcessingTxt2Img(sd_model=shared.sd_model, args)) as p: File "", line 58, in init** TypeError: 'NoneType' object is not callable "