forked from lukasmasuch/streamlit-pydantic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplex_nested_model.py
50 lines (40 loc) · 1.16 KB
/
complex_nested_model.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from enum import Enum
from typing import Set
import streamlit as st
from pydantic import BaseModel, Field
import streamlit_pydantic as sp
class OtherData(BaseModel):
text: str
integer: int
class SelectionValue(str, Enum):
FOO = "foo"
BAR = "bar"
class ExampleModel(BaseModel):
long_text: str = Field(
..., format="multi-line", description="Unlimited text property"
)
integer_in_range: int = Field(
20,
ge=10,
le=30,
multiple_of=2,
description="Number property with a limited range.",
)
single_selection: SelectionValue = Field(
..., description="Only select a single item from a set."
)
multi_selection: Set[SelectionValue] = Field(
..., description="Allows multiple items from a set."
)
read_only_text: str = Field(
"Lorem ipsum dolor sit amet",
description="This is a ready only text.",
readOnly=True,
)
single_object: OtherData = Field(
...,
description="Another object embedded into this model.",
)
data = sp.pydantic_form(key="my_form", model=ExampleModel)
if data:
st.json(data.model_dump_json())