FastUI icon indicating copy to clipboard operation
FastUI copied to clipboard

accessing the solve UI from pydantic model functionality in FastUI

Open jgunstone opened this issue 1 year ago • 0 comments

Hi there, I develop https://github.com/maxfordham/ipyautoui which uses pydantic to create user input forms from ipywidgets (jupyter widgets).

ipyautoui

FastUI has the logic for interpreting a pydantic model and then mapping this to the appropriate widgets to build a form.

It would be cool if ipyautoui could use this logic to solve what UI element to present, I could then deprecate this (which uses the jsonschema to pick a widget for a given item), but map the result to an appropriate ipywidget instead of React widget provided by FastUI...

do you think this is possible / could it be possible? crudely, maybe something like:

from pydantic import BaseModel
from pydantic_extra_types import Color
from enum import Enum

class ColorEnum(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

class MyForm(BaseModel):
    a: str
    b: int
    c: ColorEnum
    d: Color

from fastui import solve_ui
solve_ui(MyForm)
>>> {"a": "Text", "b": "Integer", "c": "Dropdown", "d": "ColorPicker"}

jgunstone avatar Feb 16 '24 10:02 jgunstone