-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathcomplex_showcase.py
101 lines (90 loc) · 3.1 KB
/
complex_showcase.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import datetime
from enum import Enum
from typing import Dict, List, Literal, Set
import streamlit as st
from pydantic import Base64UrlBytes, BaseModel, Field, SecretStr
import streamlit_pydantic as sp
class SelectionValue(str, Enum):
FOO = "foo"
BAR = "bar"
class OtherData(BaseModel):
text: str
integer: int
class ShowcaseModel(BaseModel):
short_text: str = Field(..., max_length=60, description="Short text property")
password: SecretStr = Field(..., description="Password text property")
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. Optional because of default value.",
)
positive_integer: int = Field(
..., ge=0, multiple_of=10, description="Positive integer with step count of 10."
)
float_number: float = Field(0.001)
date: datetime.date = Field(
datetime.date.today(),
description="Date property. Optional because of default value.",
)
time: datetime.time = Field(
datetime.datetime.now().time(),
description="Time property. Optional because of default value.",
)
boolean: bool = Field(
False,
description="Boolean property. Optional because of default value.",
)
read_only_text: str = Field(
"Lorem ipsum dolor sit amet",
description="This is a ready only text.",
readOnly=True,
)
file_list: List[Base64UrlBytes] = Field(
[],
description="A list of files. Optional property.",
)
single_file: Base64UrlBytes = Field(
b"",
description="A single file. Optional property.",
)
single_selection: SelectionValue = Field(
..., description="Only select a single item from a set."
)
single_selection_with_literal: Literal["foo", "bar"] = Field(
"foo", description="Only select a single item from a set."
)
multi_selection: Set[SelectionValue] = Field(
..., description="Allows multiple items from a set."
)
multi_selection_with_literal: Set[Literal["foo", "bar"]] = Field(
["foo", "bar"], description="Allows multiple items from a set."
)
single_object: OtherData = Field(
...,
description="Another object embedded into this model.",
)
string_list: List[str] = Field(
..., max_items=20, description="List of string values"
)
int_list: List[int] = Field(..., description="List of int values")
string_dict: Dict[str, str] = Field(
..., description="Dict property with string values"
)
float_dict: Dict[str, float] = Field(
..., description="Dict property with float values"
)
object_list: List[OtherData] = Field(
...,
description="A list of objects embedded into this model.",
)
data = sp.pydantic_input(
key="my_showcase_input", model=ShowcaseModel, group_optional_fields="sidebar"
)
if data:
with st.expander("Current Input State", expanded=False):
st.json(data)