Generalized Functions into Forms!

Generalize Function to Streamlit Form

Check it out live for full explanation / guide to python inspect.signature

st_func_form

Powered by Streamlit-Pydantic shoutout to the work on that library

Utilizes inspect.signature to build a form input class from a function definition.

Streamlit-Pydantic gives us creation of UI form from Pydantic BaseModel or standard lib dataclass.

So we just have to get from function parameters to dataclass or BaseModel and we’re golden!

What’s the point?

Even more rapid development!

Take any CLI or other functional API and create an input form for it!

Add function arguments to get new UI inputs for free!

Memo-ize your form inputs / outputs without the mental overhead of managing the form and the processing function!

Encourage library developers to write accurate type hints :wink:

Next Steps?

I figured out this could work when hacking the Darts library to make a model playground (see Interactive Timeseries Forecasting with Darts!)

I’ve avoided having to initialize Python objects safely (i.e. without raw eval), but that limits functionality

Parse out well formed argument docstrings to pass as tooltip hints. (Or just dump the whole __doc__ of your function at the top of the form)

Turn it into some QA tool akin to Swagger / Postman for python API’s not written to those specs.

Destroy this monstrosity and stick to CLI tools like click

2 Likes

Fab work! I thought there was some magic in Pydantic after seeing the success of FastAPI.

1 Like

Wow, inspect signature to Pydantic dynamic model to Streamlit UI, that is sooo interesting :heart_eyes: also your Streamlit app describing the process is really cool :wink:

Thanks for sharing!

1 Like

Thanks y’all, cheers!

FastAPI was first place I saw it too. Was pleasantly surprised someone had already put some work into a streamlit adaptation. Also love the autocomplete help as a bonus :heart_eyes: