We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When passing an object based on the Pydantic BaseModel to gr.State during initalization of the gr.State the object gets serialized into a dictionary.
This doesn't happen for a regular class object.
Interestingly, when passing a Pydantic object into an already initialized gr.State the serialization does not occur (at least in a certain scenario).
import gradio as gr from pydantic import BaseModel class TestRegular: def __init__(self, name): self.name = name class TestPydantic(BaseModel): name: str t_reg = TestRegular("hey there") t_pyd = TestPydantic(name="wassup") state_reg = gr.State(t_reg) state_pyd = gr.State(t_pyd) print("== regular class remains unchanged ==") print(f"{t_reg=}") print(f"{state_reg.value=}") print("== pydantic is serialized ==") print(f"{t_pyd=}") print(f"{state_pyd.value=}")
The output of running the above code snippet.
No response
Gradio Environment Information: ------------------------------ Operating System: Linux gradio version: 5.6.0 gradio_client version: 1.4.3 ------------------------------------------------ gradio dependencies in your environment: aiofiles: 23.2.1 anyio: 4.4.0 audioop-lts is not installed. fastapi: 0.115.5 ffmpy: 0.4.0 gradio-client==1.4.3 is not installed. httpx: 0.27.2 huggingface-hub: 0.25.2 jinja2: 3.1.4 markupsafe: 2.1.3 numpy: 1.26.4 orjson: 3.10.7 packaging: 24.1 pandas: 2.2.2 pillow: 10.4.0 pydantic: 2.10.1 pydub: 0.25.1 python-multipart==0.0.12 is not installed. pyyaml: 6.0.2 ruff: 0.6.7 safehttpx: 0.1.1 semantic-version: 2.10.0 starlette: 0.41.3 tomlkit==0.12.0 is not installed. typer: 0.12.5 typing-extensions: 4.12.2 urllib3: 2.2.2 uvicorn: 0.30.6 authlib; extra == 'oauth' is not installed. itsdangerous; extra == 'oauth' is not installed. gradio_client dependencies in your environment: fsspec: 2024.5.0 httpx: 0.27.2 huggingface-hub: 0.25.2 packaging: 24.1 typing-extensions: 4.12.2 websockets: 12.0
I can work around it
The text was updated successfully, but these errors were encountered:
freddyaboulton
Successfully merging a pull request may close this issue.
Describe the bug
When passing an object based on the Pydantic BaseModel to gr.State during initalization of the gr.State the object gets serialized into a dictionary.
This doesn't happen for a regular class object.
Interestingly, when passing a Pydantic object into an already initialized gr.State the serialization does not occur (at least in a certain scenario).
Have you searched existing issues? 🔎
Reproduction
Screenshot
The output of running the above code snippet.
Logs
No response
System Info
Severity
I can work around it
The text was updated successfully, but these errors were encountered: