-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathsimple_form.py
More file actions
31 lines (23 loc) · 745 Bytes
/
simple_form.py
File metadata and controls
31 lines (23 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from pydantic import BaseModel
import streamlit_pydantic as sp
class ExampleModel(BaseModel):
some_text: str
some_number: int
some_boolean: bool
from_model_tab, from_instance_tab = st.tabs(
["Form inputs from model", "Form inputs from instance"]
)
with from_model_tab:
data = sp.pydantic_form(key="my_sample_form", model=ExampleModel)
if data:
st.json(data.model_dump())
with from_instance_tab:
instance = ExampleModel(
some_number=999, some_boolean=True, some_text="instance text"
)
instance_input_data = sp.pydantic_form(
key="my_sample_form_instance", model=instance
)
if instance_input_data:
st.json(instance_input_data.model_dump())