streamlit-nightly 1.37.2.dev20240810__py2.py3-none-any.whl → 1.37.2.dev20240813__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit/connections/sql_connection.py +6 -1
- streamlit/dataframe_util.py +63 -4
- streamlit/delta_generator.py +3 -158
- streamlit/elements/arrow.py +146 -2
- streamlit/elements/deck_gl_json_chart.py +2 -2
- streamlit/elements/image.py +12 -7
- streamlit/elements/lib/built_in_chart_utils.py +12 -5
- streamlit/elements/lib/column_config_utils.py +8 -0
- streamlit/elements/lib/dialog.py +6 -3
- streamlit/elements/lib/mutable_status_container.py +3 -2
- streamlit/elements/media.py +11 -9
- streamlit/elements/metric.py +2 -2
- streamlit/elements/widgets/number_input.py +80 -34
- streamlit/elements/widgets/selectbox.py +37 -1
- streamlit/elements/widgets/slider.py +179 -19
- streamlit/external/langchain/streamlit_callback_handler.py +7 -2
- streamlit/runtime/caching/hashing.py +16 -5
- streamlit/runtime/scriptrunner/__init__.py +2 -0
- streamlit/runtime/scriptrunner/exec_code.py +1 -1
- streamlit/runtime/scriptrunner/script_run_context.py +18 -6
- streamlit/source_util.py +2 -7
- streamlit/static/asset-manifest.json +2 -2
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{main.80efcd23.js → main.d1c1e1f9.js} +2 -2
- streamlit/testing/v1/element_tree.py +12 -13
- streamlit/type_util.py +5 -0
- streamlit/web/bootstrap.py +2 -2
- {streamlit_nightly-1.37.2.dev20240810.dist-info → streamlit_nightly-1.37.2.dev20240813.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.37.2.dev20240810.dist-info → streamlit_nightly-1.37.2.dev20240813.dist-info}/RECORD +34 -34
- {streamlit_nightly-1.37.2.dev20240810.dist-info → streamlit_nightly-1.37.2.dev20240813.dist-info}/WHEEL +1 -1
- /streamlit/static/static/js/{main.80efcd23.js.LICENSE.txt → main.d1c1e1f9.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.37.2.dev20240810.data → streamlit_nightly-1.37.2.dev20240813.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.37.2.dev20240810.dist-info → streamlit_nightly-1.37.2.dev20240813.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.37.2.dev20240810.dist-info → streamlit_nightly-1.37.2.dev20240813.dist-info}/top_level.txt +0 -0
@@ -667,10 +667,15 @@ def _get_offset_encoding(
|
|
667
667
|
x_offset = alt.XOffset()
|
668
668
|
y_offset = alt.YOffset()
|
669
669
|
|
670
|
+
# our merge gate does not find the alt.UndefinedType type for some reason
|
671
|
+
_color_column: str | alt.UndefinedType = ( # type: ignore[name-defined]
|
672
|
+
color_column if color_column is not None else alt.utils.Undefined
|
673
|
+
)
|
674
|
+
|
670
675
|
if chart_type is ChartType.VERTICAL_BAR:
|
671
|
-
x_offset = alt.XOffset(field=
|
676
|
+
x_offset = alt.XOffset(field=_color_column)
|
672
677
|
elif chart_type is ChartType.HORIZONTAL_BAR:
|
673
|
-
y_offset = alt.YOffset(field=
|
678
|
+
y_offset = alt.YOffset(field=_color_column)
|
674
679
|
|
675
680
|
return x_offset, y_offset
|
676
681
|
|
@@ -912,11 +917,13 @@ def _get_color_encoding(
|
|
912
917
|
if len(color_values) != len(y_column_list):
|
913
918
|
raise StreamlitColorLengthError(color_values, y_column_list)
|
914
919
|
|
915
|
-
if len(
|
920
|
+
if len(color_values) == 1:
|
916
921
|
return alt.ColorValue(to_css_color(cast(Any, color_value[0])))
|
917
922
|
else:
|
918
923
|
return alt.Color(
|
919
|
-
field=color_column
|
924
|
+
field=color_column
|
925
|
+
if color_column is not None
|
926
|
+
else alt.utils.Undefined,
|
920
927
|
scale=alt.Scale(range=[to_css_color(c) for c in color_values]),
|
921
928
|
legend=_COLOR_LEGEND_SETTINGS,
|
922
929
|
type="nominal",
|
@@ -926,7 +933,7 @@ def _get_color_encoding(
|
|
926
933
|
raise StreamlitInvalidColorError(df, color_from_user)
|
927
934
|
|
928
935
|
elif color_column is not None:
|
929
|
-
column_type:
|
936
|
+
column_type: VegaLiteType
|
930
937
|
|
931
938
|
if color_column == _MELTED_COLOR_COLUMN_NAME:
|
932
939
|
column_type = "nominal"
|
@@ -494,6 +494,14 @@ def apply_data_specific_configs(
|
|
494
494
|
DataFormat.LIST_OF_RECORDS,
|
495
495
|
DataFormat.LIST_OF_ROWS,
|
496
496
|
DataFormat.COLUMN_VALUE_MAPPING,
|
497
|
+
# Dataframe-like objects that don't have an index:
|
498
|
+
DataFormat.PANDAS_ARRAY,
|
499
|
+
DataFormat.PANDAS_INDEX,
|
500
|
+
DataFormat.POLARS_DATAFRAME,
|
501
|
+
DataFormat.POLARS_SERIES,
|
502
|
+
DataFormat.POLARS_LAZYFRAME,
|
503
|
+
DataFormat.PYARROW_ARRAY,
|
504
|
+
DataFormat.RAY_DATASET,
|
497
505
|
]:
|
498
506
|
update_column_config(columns_config, INDEX_IDENTIFIER, {"hidden": True})
|
499
507
|
|
streamlit/elements/lib/dialog.py
CHANGED
@@ -19,11 +19,14 @@ from typing import TYPE_CHECKING, Literal, cast
|
|
19
19
|
|
20
20
|
from typing_extensions import Self, TypeAlias
|
21
21
|
|
22
|
-
from streamlit.delta_generator import DeltaGenerator
|
22
|
+
from streamlit.delta_generator import DeltaGenerator
|
23
23
|
from streamlit.errors import StreamlitAPIException
|
24
24
|
from streamlit.proto.Block_pb2 import Block as BlockProto
|
25
25
|
from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
|
26
|
-
from streamlit.runtime.scriptrunner import
|
26
|
+
from streamlit.runtime.scriptrunner.script_run_context import (
|
27
|
+
enqueue_message,
|
28
|
+
get_script_run_ctx,
|
29
|
+
)
|
27
30
|
|
28
31
|
if TYPE_CHECKING:
|
29
32
|
from types import TracebackType
|
@@ -127,7 +130,7 @@ class Dialog(DeltaGenerator):
|
|
127
130
|
# We add a sleep here to give the web app time to react to the update. Otherwise,
|
128
131
|
# we might run into issues where the dialog cannot be opened again after closing
|
129
132
|
time.sleep(0.05)
|
130
|
-
|
133
|
+
enqueue_message(msg)
|
131
134
|
|
132
135
|
def open(self) -> None:
|
133
136
|
self._update(True)
|
@@ -19,10 +19,11 @@ from typing import TYPE_CHECKING, Literal, cast
|
|
19
19
|
|
20
20
|
from typing_extensions import Self, TypeAlias
|
21
21
|
|
22
|
-
from streamlit.delta_generator import DeltaGenerator
|
22
|
+
from streamlit.delta_generator import DeltaGenerator
|
23
23
|
from streamlit.errors import StreamlitAPIException
|
24
24
|
from streamlit.proto.Block_pb2 import Block as BlockProto
|
25
25
|
from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
|
26
|
+
from streamlit.runtime.scriptrunner.script_run_context import enqueue_message
|
26
27
|
|
27
28
|
if TYPE_CHECKING:
|
28
29
|
from types import TracebackType
|
@@ -150,7 +151,7 @@ class StatusContainer(DeltaGenerator):
|
|
150
151
|
self._current_state = state
|
151
152
|
|
152
153
|
self._current_proto = msg.delta.add_block
|
153
|
-
|
154
|
+
enqueue_message(msg)
|
154
155
|
|
155
156
|
def __enter__(self) -> Self: # type: ignore[override]
|
156
157
|
# This is a little dubious: we're returning a different type than
|
streamlit/elements/media.py
CHANGED
@@ -33,6 +33,7 @@ from streamlit.runtime.metrics_util import gather_metrics
|
|
33
33
|
from streamlit.runtime.scriptrunner import get_script_run_ctx
|
34
34
|
from streamlit.runtime.state.common import compute_widget_id
|
35
35
|
from streamlit.time_util import time_to_seconds
|
36
|
+
from streamlit.type_util import NumpyShape
|
36
37
|
|
37
38
|
if TYPE_CHECKING:
|
38
39
|
from typing import Any
|
@@ -41,6 +42,7 @@ if TYPE_CHECKING:
|
|
41
42
|
|
42
43
|
from streamlit.delta_generator import DeltaGenerator
|
43
44
|
|
45
|
+
|
44
46
|
MediaData: TypeAlias = Union[
|
45
47
|
str, bytes, io.BytesIO, io.RawIOBase, io.BufferedReader, "npt.NDArray[Any]", None
|
46
48
|
]
|
@@ -633,29 +635,29 @@ def _validate_and_normalize(data: npt.NDArray[Any]) -> tuple[bytes, int]:
|
|
633
635
|
# to st.audio data)
|
634
636
|
import numpy as np
|
635
637
|
|
636
|
-
|
638
|
+
transformed_data: npt.NDArray[Any] = np.array(data, dtype=float)
|
637
639
|
|
638
|
-
if len(
|
640
|
+
if len(cast(NumpyShape, transformed_data.shape)) == 1:
|
639
641
|
nchan = 1
|
640
|
-
elif len(
|
642
|
+
elif len(transformed_data.shape) == 2:
|
641
643
|
# In wave files,channels are interleaved. E.g.,
|
642
644
|
# "L1R1L2R2..." for stereo. See
|
643
645
|
# http://msdn.microsoft.com/en-us/library/windows/hardware/dn653308(v=vs.85).aspx
|
644
646
|
# for channel ordering
|
645
|
-
nchan =
|
646
|
-
|
647
|
+
nchan = transformed_data.shape[0]
|
648
|
+
transformed_data = transformed_data.T.ravel()
|
647
649
|
else:
|
648
650
|
raise StreamlitAPIException("Numpy array audio input must be a 1D or 2D array.")
|
649
651
|
|
650
|
-
if
|
651
|
-
return
|
652
|
+
if transformed_data.size == 0:
|
653
|
+
return transformed_data.astype(np.int16).tobytes(), nchan
|
652
654
|
|
653
|
-
max_abs_value = np.max(np.abs(
|
655
|
+
max_abs_value = np.max(np.abs(transformed_data))
|
654
656
|
# 16-bit samples are stored as 2's-complement signed integers,
|
655
657
|
# ranging from -32768 to 32767.
|
656
658
|
# scaled_data is PCM 16 bit numpy array, that's why we multiply [-1, 1] float
|
657
659
|
# values to 32_767 == 2 ** 15 - 1.
|
658
|
-
np_array = (
|
660
|
+
np_array = (transformed_data / max_abs_value) * 32767
|
659
661
|
scaled_data = np_array.astype(np.int16)
|
660
662
|
return scaled_data.tobytes(), nchan
|
661
663
|
|
streamlit/elements/metric.py
CHANGED
@@ -16,7 +16,7 @@ from __future__ import annotations
|
|
16
16
|
|
17
17
|
from dataclasses import dataclass
|
18
18
|
from textwrap import dedent
|
19
|
-
from typing import TYPE_CHECKING, Literal, Union, cast
|
19
|
+
from typing import TYPE_CHECKING, Any, Literal, Union, cast
|
20
20
|
|
21
21
|
from typing_extensions import TypeAlias
|
22
22
|
|
@@ -36,7 +36,7 @@ if TYPE_CHECKING:
|
|
36
36
|
from streamlit.delta_generator import DeltaGenerator
|
37
37
|
|
38
38
|
|
39
|
-
Value: TypeAlias = Union["np.integer", "np.floating", float, int, str, None]
|
39
|
+
Value: TypeAlias = Union["np.integer[Any]", "np.floating[Any]", float, int, str, None]
|
40
40
|
Delta: TypeAlias = Union[float, int, str, None]
|
41
41
|
DeltaColor: TypeAlias = Literal["normal", "inverse", "off"]
|
42
42
|
|
@@ -17,7 +17,7 @@ from __future__ import annotations
|
|
17
17
|
import numbers
|
18
18
|
from dataclasses import dataclass
|
19
19
|
from textwrap import dedent
|
20
|
-
from typing import TYPE_CHECKING, Literal, Union, cast, overload
|
20
|
+
from typing import TYPE_CHECKING, Literal, TypeVar, Union, cast, overload
|
21
21
|
|
22
22
|
from typing_extensions import TypeAlias
|
23
23
|
|
@@ -51,6 +51,8 @@ if TYPE_CHECKING:
|
|
51
51
|
|
52
52
|
|
53
53
|
Number: TypeAlias = Union[int, float]
|
54
|
+
IntOrNone = TypeVar("IntOrNone", int, None)
|
55
|
+
FloatOrNone = TypeVar("FloatOrNone", float, None)
|
54
56
|
|
55
57
|
|
56
58
|
@dataclass
|
@@ -73,47 +75,91 @@ class NumberInputSerde:
|
|
73
75
|
|
74
76
|
|
75
77
|
class NumberInputMixin:
|
78
|
+
# For easier readability, all the arguments with un-changing types across these overload signatures have been
|
79
|
+
# collapsed onto a single line.
|
80
|
+
|
81
|
+
# fmt: off
|
82
|
+
# If "min_value: int" is given and all other numerical inputs are
|
83
|
+
# "int"s or not provided (value optionally being "min"), return "int"
|
84
|
+
# If "min_value: int, value: None" is given and all other numerical inputs
|
85
|
+
# are "int"s or not provided, return "int | None"
|
76
86
|
@overload
|
77
87
|
def number_input(
|
78
88
|
self,
|
79
89
|
label: str,
|
80
|
-
min_value:
|
81
|
-
max_value:
|
82
|
-
value:
|
83
|
-
step:
|
84
|
-
format: str | None = None,
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
disabled: bool = False,
|
93
|
-
label_visibility: LabelVisibility = "visible",
|
94
|
-
) -> Number:
|
95
|
-
pass
|
96
|
-
|
90
|
+
min_value: int,
|
91
|
+
max_value: int | None = None,
|
92
|
+
value: IntOrNone | Literal["min"] = "min",
|
93
|
+
step: int | None = None,
|
94
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, placeholder: str | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
95
|
+
) -> int | IntOrNone:
|
96
|
+
...
|
97
|
+
|
98
|
+
# If "max_value: int" is given and all other numerical inputs are
|
99
|
+
# "int"s or not provided (value optionally being "min"), return "int"
|
100
|
+
# If "max_value: int, value=None" is given and all other numerical inputs
|
101
|
+
# are "int"s or not provided, return "int | None"
|
97
102
|
@overload
|
98
103
|
def number_input(
|
99
104
|
self,
|
100
105
|
label: str,
|
101
|
-
min_value:
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
key: Key | None = None,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
106
|
+
min_value: int | None = None,
|
107
|
+
*,
|
108
|
+
max_value: int,
|
109
|
+
value: IntOrNone | Literal["min"] = "min",
|
110
|
+
step: int | None = None,
|
111
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, placeholder: str | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
112
|
+
) -> int | IntOrNone:
|
113
|
+
...
|
114
|
+
|
115
|
+
# If "value=int" is given and all other numerical inputs are "int"s
|
116
|
+
# or not provided, return "int"
|
117
|
+
@overload
|
118
|
+
def number_input(
|
119
|
+
self,
|
120
|
+
label: str,
|
121
|
+
min_value: int | None = None,
|
122
|
+
max_value: int | None = None,
|
123
|
+
*,
|
124
|
+
value: int,
|
125
|
+
step: int | None = None,
|
126
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, placeholder: str | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
127
|
+
) -> int:
|
128
|
+
...
|
129
|
+
|
130
|
+
# If "step=int" is given and all other numerical inputs are "int"s
|
131
|
+
# or not provided (value optionally being "min"), return "int"
|
132
|
+
# If "step=int, value=None" is given and all other numerical inputs
|
133
|
+
# are "int"s or not provided, return "int | None"
|
134
|
+
@overload
|
135
|
+
def number_input(
|
136
|
+
self,
|
137
|
+
label: str,
|
138
|
+
min_value: int | None = None,
|
139
|
+
max_value: int | None = None,
|
140
|
+
value: IntOrNone | Literal["min"] = "min",
|
141
|
+
*,
|
142
|
+
step: int,
|
143
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, placeholder: str | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
144
|
+
) -> int | IntOrNone:
|
145
|
+
...
|
146
|
+
|
147
|
+
# If all numerical inputs are floats (with value optionally being "min")
|
148
|
+
# or are not provided, return "float"
|
149
|
+
# If only "value=None" is given and none of the other numerical inputs
|
150
|
+
# are "int"s, return "float | None"
|
151
|
+
@overload
|
152
|
+
def number_input(
|
153
|
+
self,
|
154
|
+
label: str,
|
155
|
+
min_value: float | None = None,
|
156
|
+
max_value: float | None = None,
|
157
|
+
value: FloatOrNone | Literal["min"] = "min",
|
158
|
+
step: float | None = None,
|
159
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, placeholder: str | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
160
|
+
) -> float | FloatOrNone:
|
161
|
+
...
|
162
|
+
# # fmt: on
|
117
163
|
|
118
164
|
@gather_metrics("number_input")
|
119
165
|
def number_input(
|
@@ -15,7 +15,7 @@ from __future__ import annotations
|
|
15
15
|
|
16
16
|
from dataclasses import dataclass
|
17
17
|
from textwrap import dedent
|
18
|
-
from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast
|
18
|
+
from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast, overload
|
19
19
|
|
20
20
|
from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
|
21
21
|
from streamlit.elements.form import current_form_id
|
@@ -74,6 +74,42 @@ class SelectboxSerde(Generic[T]):
|
|
74
74
|
|
75
75
|
|
76
76
|
class SelectboxMixin:
|
77
|
+
@overload
|
78
|
+
def selectbox(
|
79
|
+
self,
|
80
|
+
label: str,
|
81
|
+
options: OptionSequence[T],
|
82
|
+
index: int = 0,
|
83
|
+
format_func: Callable[[Any], Any] = str,
|
84
|
+
key: Key | None = None,
|
85
|
+
help: str | None = None,
|
86
|
+
on_change: WidgetCallback | None = None,
|
87
|
+
args: WidgetArgs | None = None,
|
88
|
+
kwargs: WidgetKwargs | None = None,
|
89
|
+
*, # keyword-only arguments:
|
90
|
+
placeholder: str = "Choose an option",
|
91
|
+
disabled: bool = False,
|
92
|
+
label_visibility: LabelVisibility = "visible",
|
93
|
+
) -> T: ...
|
94
|
+
|
95
|
+
@overload
|
96
|
+
def selectbox(
|
97
|
+
self,
|
98
|
+
label: str,
|
99
|
+
options: OptionSequence[T],
|
100
|
+
index: None,
|
101
|
+
format_func: Callable[[Any], Any] = str,
|
102
|
+
key: Key | None = None,
|
103
|
+
help: str | None = None,
|
104
|
+
on_change: WidgetCallback | None = None,
|
105
|
+
args: WidgetArgs | None = None,
|
106
|
+
kwargs: WidgetKwargs | None = None,
|
107
|
+
*, # keyword-only arguments:
|
108
|
+
placeholder: str = "Choose an option",
|
109
|
+
disabled: bool = False,
|
110
|
+
label_visibility: LabelVisibility = "visible",
|
111
|
+
) -> T | None: ...
|
112
|
+
|
77
113
|
@gather_metrics("selectbox")
|
78
114
|
def selectbox(
|
79
115
|
self,
|
@@ -18,7 +18,18 @@ from dataclasses import dataclass
|
|
18
18
|
from datetime import date, datetime, time, timedelta, timezone, tzinfo
|
19
19
|
from numbers import Integral, Real
|
20
20
|
from textwrap import dedent
|
21
|
-
from typing import
|
21
|
+
from typing import (
|
22
|
+
TYPE_CHECKING,
|
23
|
+
Any,
|
24
|
+
Final,
|
25
|
+
List,
|
26
|
+
Sequence,
|
27
|
+
Tuple,
|
28
|
+
TypeVar,
|
29
|
+
Union,
|
30
|
+
cast,
|
31
|
+
overload,
|
32
|
+
)
|
22
33
|
|
23
34
|
from typing_extensions import TypeAlias
|
24
35
|
|
@@ -50,14 +61,31 @@ from streamlit.runtime.state.common import compute_widget_id
|
|
50
61
|
if TYPE_CHECKING:
|
51
62
|
from streamlit.delta_generator import DeltaGenerator
|
52
63
|
|
53
|
-
|
64
|
+
SliderNumericT = TypeVar("SliderNumericT", int, float)
|
65
|
+
SliderDatelikeT = TypeVar("SliderDatelikeT", date, time, datetime)
|
54
66
|
|
55
|
-
|
56
|
-
|
67
|
+
SliderNumericSpanT: TypeAlias = Union[
|
68
|
+
List[SliderNumericT],
|
69
|
+
Tuple[()],
|
70
|
+
Tuple[SliderNumericT],
|
71
|
+
Tuple[SliderNumericT, SliderNumericT],
|
72
|
+
]
|
73
|
+
SliderDatelikeSpanT: TypeAlias = Union[
|
74
|
+
List[SliderDatelikeT],
|
75
|
+
Tuple[()],
|
76
|
+
Tuple[SliderDatelikeT],
|
77
|
+
Tuple[SliderDatelikeT, SliderDatelikeT],
|
78
|
+
]
|
57
79
|
|
80
|
+
StepNumericT: TypeAlias = SliderNumericT
|
81
|
+
StepDatelikeT: TypeAlias = timedelta
|
82
|
+
|
83
|
+
SliderStep = Union[int, float, timedelta]
|
84
|
+
SliderScalar = Union[int, float, date, time, datetime]
|
85
|
+
SliderValueT = TypeVar("SliderValueT", int, float, date, time, datetime)
|
58
86
|
SliderValueGeneric: TypeAlias = Union[
|
59
|
-
|
60
|
-
Sequence[
|
87
|
+
SliderValueT,
|
88
|
+
Sequence[SliderValueT],
|
61
89
|
]
|
62
90
|
SliderValue: TypeAlias = Union[
|
63
91
|
SliderValueGeneric[int],
|
@@ -66,11 +94,10 @@ SliderValue: TypeAlias = Union[
|
|
66
94
|
SliderValueGeneric[time],
|
67
95
|
SliderValueGeneric[datetime],
|
68
96
|
]
|
69
|
-
|
70
97
|
SliderReturnGeneric: TypeAlias = Union[
|
71
|
-
|
72
|
-
Tuple[
|
73
|
-
Tuple[
|
98
|
+
SliderValueT,
|
99
|
+
Tuple[SliderValueT],
|
100
|
+
Tuple[SliderValueT, SliderValueT],
|
74
101
|
]
|
75
102
|
SliderReturn: TypeAlias = Union[
|
76
103
|
SliderReturnGeneric[int],
|
@@ -166,14 +193,152 @@ class SliderSerde:
|
|
166
193
|
|
167
194
|
|
168
195
|
class SliderMixin:
|
169
|
-
|
196
|
+
# For easier readability, all the arguments with un-changing types across these overload signatures have been
|
197
|
+
# collapsed onto a single line.
|
198
|
+
|
199
|
+
# fmt: off
|
200
|
+
# If min/max/value/step are not provided, then we return an int.
|
201
|
+
# if ONLY step is provided, then it must be an int and we return an int.
|
202
|
+
@overload
|
203
|
+
def slider(
|
204
|
+
self,
|
205
|
+
label: str,
|
206
|
+
min_value: None = None,
|
207
|
+
max_value: None = None,
|
208
|
+
value: None = None,
|
209
|
+
step: int | None = None,
|
210
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
211
|
+
) -> int:
|
212
|
+
...
|
213
|
+
|
214
|
+
# If min-value or max_value is provided and a numeric type, and value (if provided)
|
215
|
+
# is a singular numeric, return the same numeric type.
|
216
|
+
@overload
|
217
|
+
def slider(
|
218
|
+
self,
|
219
|
+
label: str,
|
220
|
+
min_value: SliderNumericT | None = None,
|
221
|
+
max_value: SliderNumericT | None = None,
|
222
|
+
value: SliderNumericT | None = None,
|
223
|
+
step: StepNumericT[SliderNumericT] | None = None,
|
224
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
225
|
+
) -> SliderNumericT:
|
226
|
+
...
|
227
|
+
|
228
|
+
# If value is provided and a sequence of numeric type,
|
229
|
+
# return a tuple of the same numeric type.
|
230
|
+
@overload
|
231
|
+
def slider(
|
232
|
+
self,
|
233
|
+
label: str,
|
234
|
+
min_value: SliderNumericT | None = None,
|
235
|
+
max_value: SliderNumericT | None = None,
|
236
|
+
*,
|
237
|
+
value: SliderNumericSpanT[SliderNumericT],
|
238
|
+
step: StepNumericT[SliderNumericT] | None = None,
|
239
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
240
|
+
) -> tuple[SliderNumericT, SliderNumericT]:
|
241
|
+
...
|
242
|
+
|
243
|
+
# If value is provided positionally and a sequence of numeric type,
|
244
|
+
# return a tuple of the same numeric type.
|
245
|
+
@overload
|
246
|
+
def slider(
|
247
|
+
self,
|
248
|
+
label: str,
|
249
|
+
min_value: SliderNumericT,
|
250
|
+
max_value: SliderNumericT,
|
251
|
+
value: SliderNumericSpanT[SliderNumericT],
|
252
|
+
/,
|
253
|
+
step: StepNumericT[SliderNumericT] | None = None,
|
254
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
255
|
+
) -> tuple[SliderNumericT, SliderNumericT]:
|
256
|
+
...
|
257
|
+
|
258
|
+
# If min-value is provided and a datelike type, and value (if provided)
|
259
|
+
# is a singular datelike, return the same datelike type.
|
260
|
+
@overload
|
261
|
+
def slider(
|
262
|
+
self,
|
263
|
+
label: str,
|
264
|
+
min_value: SliderDatelikeT,
|
265
|
+
max_value: SliderDatelikeT | None = None,
|
266
|
+
value: SliderDatelikeT | None = None,
|
267
|
+
step: StepDatelikeT | None = None,
|
268
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
269
|
+
) -> SliderDatelikeT:
|
270
|
+
...
|
271
|
+
|
272
|
+
# If max-value is provided and a datelike type, and value (if provided)
|
273
|
+
# is a singular datelike, return the same datelike type.
|
274
|
+
@overload
|
275
|
+
def slider(
|
276
|
+
self,
|
277
|
+
label: str,
|
278
|
+
min_value: SliderDatelikeT | None = None,
|
279
|
+
*,
|
280
|
+
max_value: SliderDatelikeT,
|
281
|
+
value: SliderDatelikeT | None = None,
|
282
|
+
step: StepDatelikeT | None = None,
|
283
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
284
|
+
) -> SliderDatelikeT:
|
285
|
+
...
|
286
|
+
|
287
|
+
# If value is provided and a datelike type, return the same datelike type.
|
288
|
+
@overload
|
289
|
+
def slider(
|
290
|
+
self,
|
291
|
+
label: str,
|
292
|
+
min_value: SliderDatelikeT | None = None,
|
293
|
+
max_value: SliderDatelikeT | None = None,
|
294
|
+
*,
|
295
|
+
value: SliderDatelikeT,
|
296
|
+
step: StepDatelikeT | None = None,
|
297
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
298
|
+
) -> SliderDatelikeT:
|
299
|
+
...
|
300
|
+
|
301
|
+
# If value is provided and a sequence of datelike type,
|
302
|
+
# return a tuple of the same datelike type.
|
303
|
+
@overload
|
304
|
+
def slider(
|
305
|
+
self,
|
306
|
+
label: str,
|
307
|
+
min_value: SliderDatelikeT | None = None,
|
308
|
+
max_value: SliderDatelikeT | None = None,
|
309
|
+
*,
|
310
|
+
value: SliderDatelikeSpanT[SliderDatelikeT],
|
311
|
+
step: StepDatelikeT | None = None,
|
312
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
313
|
+
) -> tuple[SliderDatelikeT, SliderDatelikeT]:
|
314
|
+
...
|
315
|
+
|
316
|
+
# If value is provided positionally and a sequence of datelike type,
|
317
|
+
# return a tuple of the same datelike type.
|
318
|
+
@overload
|
319
|
+
def slider(
|
320
|
+
self,
|
321
|
+
label: str,
|
322
|
+
min_value: SliderDatelikeT,
|
323
|
+
max_value: SliderDatelikeT,
|
324
|
+
value: SliderDatelikeSpanT[SliderDatelikeT],
|
325
|
+
/,
|
326
|
+
step: StepDatelikeT | None = None,
|
327
|
+
format: str | None = None, key: Key | None = None, help: str | None = None, on_change: WidgetCallback | None = None, args: WidgetArgs | None = None, kwargs: WidgetKwargs | None = None, *, disabled: bool = False, label_visibility: LabelVisibility = "visible"
|
328
|
+
) -> tuple[SliderDatelikeT, SliderDatelikeT]:
|
329
|
+
...
|
330
|
+
|
331
|
+
# fmt: on
|
332
|
+
|
333
|
+
# https://github.com/python/mypy/issues/17614
|
334
|
+
@gather_metrics("slider") # type: ignore[misc]
|
170
335
|
def slider(
|
171
336
|
self,
|
172
337
|
label: str,
|
173
338
|
min_value: SliderScalar | None = None,
|
174
339
|
max_value: SliderScalar | None = None,
|
175
340
|
value: SliderValue | None = None,
|
176
|
-
step:
|
341
|
+
step: SliderStep | None = None,
|
177
342
|
format: str | None = None,
|
178
343
|
key: Key | None = None,
|
179
344
|
help: str | None = None,
|
@@ -183,11 +348,6 @@ class SliderMixin:
|
|
183
348
|
*, # keyword-only arguments:
|
184
349
|
disabled: bool = False,
|
185
350
|
label_visibility: LabelVisibility = "visible",
|
186
|
-
# TODO(harahu): Add overload definitions. The return type is
|
187
|
-
# `SliderReturn`, in reality, but the return type is left as `Any`
|
188
|
-
# until we have proper overload definitions in place. Otherwise the
|
189
|
-
# user would have to cast the return value more often than not, which
|
190
|
-
# can be annoying.
|
191
351
|
) -> Any:
|
192
352
|
r"""Display a slider widget.
|
193
353
|
|
@@ -360,7 +520,7 @@ class SliderMixin:
|
|
360
520
|
min_value=None,
|
361
521
|
max_value=None,
|
362
522
|
value=None,
|
363
|
-
step
|
523
|
+
step=None,
|
364
524
|
format: str | None = None,
|
365
525
|
key: Key | None = None,
|
366
526
|
help: str | None = None,
|
@@ -509,7 +669,7 @@ class SliderMixin:
|
|
509
669
|
if max_value is None:
|
510
670
|
max_value = DEFAULTS[data_type]["max_value"]
|
511
671
|
if step is None:
|
512
|
-
step =
|
672
|
+
step = DEFAULTS[data_type]["step"]
|
513
673
|
if data_type in (
|
514
674
|
SliderProto.DATETIME,
|
515
675
|
SliderProto.DATE,
|
@@ -31,20 +31,25 @@ the API *from LangChain itself*.
|
|
31
31
|
This module is lazy-loaded.
|
32
32
|
"""
|
33
33
|
|
34
|
+
# NOTE: We ignore all mypy import-not-found errors as top-level since
|
35
|
+
# this module is optional and the langchain dependency is not installed
|
36
|
+
# by default.
|
37
|
+
# mypy: disable-error-code="import-not-found, unused-ignore, misc"
|
38
|
+
|
34
39
|
from __future__ import annotations
|
35
40
|
|
36
41
|
import time
|
37
42
|
from enum import Enum
|
38
43
|
from typing import TYPE_CHECKING, Any, NamedTuple
|
39
44
|
|
40
|
-
from langchain.callbacks.base import (
|
45
|
+
from langchain.callbacks.base import (
|
41
46
|
BaseCallbackHandler,
|
42
47
|
)
|
43
48
|
|
44
49
|
from streamlit.runtime.metrics_util import gather_metrics
|
45
50
|
|
46
51
|
if TYPE_CHECKING:
|
47
|
-
from langchain.schema import (
|
52
|
+
from langchain.schema import (
|
48
53
|
AgentAction,
|
49
54
|
AgentFinish,
|
50
55
|
LLMResult,
|