Spaces:
Build error
Build error
test lists
Browse files- temp_showcase_model.py +93 -0
temp_showcase_model.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
from enum import Enum
|
3 |
+
from typing import Dict, List, Literal, Optional, Set
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
from pydantic import BaseModel, Field, SecretStr
|
7 |
+
|
8 |
+
import streamlit_pydantic as sp
|
9 |
+
from streamlit_pydantic.types import FileContent
|
10 |
+
|
11 |
+
|
12 |
+
class SelectionValue(str, Enum):
|
13 |
+
FOO = "foo"
|
14 |
+
BAR = "bar"
|
15 |
+
|
16 |
+
|
17 |
+
class OtherData(BaseModel):
|
18 |
+
text: str
|
19 |
+
integer: int
|
20 |
+
|
21 |
+
|
22 |
+
class ShowcaseModel(BaseModel):
|
23 |
+
short_text: str = Field(..., max_length=60, description="Short text property")
|
24 |
+
password: SecretStr = Field(..., description="Password text property")
|
25 |
+
long_text: str = Field(
|
26 |
+
..., format="multi-line", description="Unlimited text property"
|
27 |
+
)
|
28 |
+
integer_in_range: int = Field(
|
29 |
+
20,
|
30 |
+
ge=10,
|
31 |
+
le=30,
|
32 |
+
multiple_of=2,
|
33 |
+
description="Number property with a limited range. Optional because of default value.",
|
34 |
+
)
|
35 |
+
positive_integer: int = Field(
|
36 |
+
..., ge=0, multiple_of=10, description="Positive integer with step count of 10."
|
37 |
+
)
|
38 |
+
float_number: float = Field(0.001)
|
39 |
+
date: Optional[datetime.date] = Field(
|
40 |
+
datetime.date.today(),
|
41 |
+
description="Date property. Optional because of default value.",
|
42 |
+
)
|
43 |
+
time: Optional[datetime.time] = Field(
|
44 |
+
datetime.datetime.now().time(),
|
45 |
+
description="Time property. Optional because of default value.",
|
46 |
+
)
|
47 |
+
boolean: bool = Field(
|
48 |
+
False,
|
49 |
+
description="Boolean property. Optional because of default value.",
|
50 |
+
)
|
51 |
+
read_only_text: str = Field(
|
52 |
+
"Lorem ipsum dolor sit amet",
|
53 |
+
description="This is a ready only text.",
|
54 |
+
readOnly=True,
|
55 |
+
)
|
56 |
+
file_list: Optional[List[FileContent]] = Field(
|
57 |
+
None,
|
58 |
+
description="A list of files. Optional property.",
|
59 |
+
)
|
60 |
+
single_file: Optional[FileContent] = Field(
|
61 |
+
None,
|
62 |
+
description="A single file. Optional property.",
|
63 |
+
)
|
64 |
+
single_selection: SelectionValue = Field(
|
65 |
+
..., description="Only select a single item from a set."
|
66 |
+
)
|
67 |
+
single_selection_with_literal: Literal["foo", "bar"] = Field(
|
68 |
+
"foo", description="Only select a single item from a set."
|
69 |
+
)
|
70 |
+
multi_selection: Set[SelectionValue] = Field(
|
71 |
+
..., description="Allows multiple items from a set."
|
72 |
+
)
|
73 |
+
multi_selection_with_literal: Set[Literal["foo", "bar"]] = Field(
|
74 |
+
["foo", "bar"], description="Allows multiple items from a set."
|
75 |
+
)
|
76 |
+
single_object: OtherData = Field(
|
77 |
+
...,
|
78 |
+
description="Another object embedded into this model.",
|
79 |
+
)
|
80 |
+
string_list: List[str] = Field(
|
81 |
+
..., max_items=20, description="List of string values"
|
82 |
+
)
|
83 |
+
int_list: List[int] = Field(..., description="List of int values")
|
84 |
+
string_dict: Dict[str, str] = Field(
|
85 |
+
..., description="Dict property with string values"
|
86 |
+
)
|
87 |
+
float_dict: Dict[str, float] = Field(
|
88 |
+
..., description="Dict property with float values"
|
89 |
+
)
|
90 |
+
object_list: List[OtherData] = Field(
|
91 |
+
...,
|
92 |
+
description="A list of objects embedded into this model.",
|
93 |
+
)
|