Spaces:
Running
Running
Richard
commited on
Commit
·
6ff3d12
1
Parent(s):
1372971
Add custom button wrapper
Browse filesMainly avoiding having to set adjusted rounded corners everywhere
- components/__init__.py +1 -0
- components/button.py +27 -1
- dialogs/add_comparisons.py +1 -2
- dialogs/add_row.py +4 -5
- dialogs/generate_prompt.py +2 -4
- dialogs/load_prompt.py +2 -3
- dialogs/model_settings.py +1 -2
- dialogs/prompt_variables.py +3 -4
- dialogs/prompt_version_history.py +1 -2
- dialogs/update_title.py +2 -4
- main.py +3 -4
components/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from components.button import button_toggle as button_toggle
|
|
|
2 |
from components.card import card as card
|
3 |
from components.card import expanable_card as expanable_card
|
4 |
from components.dialog import dialog as dialog
|
|
|
1 |
from components.button import button_toggle as button_toggle
|
2 |
+
from components.button import button as button
|
3 |
from components.card import card as card
|
4 |
from components.card import expanable_card as expanable_card
|
5 |
from components.dialog import dialog as dialog
|
components/button.py
CHANGED
@@ -1,7 +1,33 @@
|
|
1 |
-
from typing import Callable
|
2 |
|
3 |
import mesop as me
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
@me.component()
|
7 |
def button_toggle(
|
|
|
1 |
+
from typing import Callable, Literal, Any
|
2 |
|
3 |
import mesop as me
|
4 |
|
5 |
+
from components import helpers
|
6 |
+
|
7 |
+
|
8 |
+
@me.component()
|
9 |
+
def button(
|
10 |
+
label: str | None = None,
|
11 |
+
*,
|
12 |
+
on_click: Callable[[me.ClickEvent], Any] | None = None,
|
13 |
+
type: Literal["raised", "flat", "stroked"] | None = None,
|
14 |
+
color: Literal["primary", "accent", "warn"] | None = None,
|
15 |
+
disable_ripple: bool = False,
|
16 |
+
disabled: bool = False,
|
17 |
+
style: me.Style | None = None,
|
18 |
+
key: str | None = None,
|
19 |
+
) -> None:
|
20 |
+
me.button(
|
21 |
+
label=label,
|
22 |
+
on_click=on_click,
|
23 |
+
type=type,
|
24 |
+
color=color,
|
25 |
+
disable_ripple=disable_ripple,
|
26 |
+
disabled=disabled,
|
27 |
+
key=key,
|
28 |
+
style=helpers.merge_styles(me.Style(border_radius=10), style),
|
29 |
+
)
|
30 |
+
|
31 |
|
32 |
@me.component()
|
33 |
def button_toggle(
|
dialogs/add_comparisons.py
CHANGED
@@ -25,11 +25,10 @@ def add_comparisons():
|
|
25 |
on_selection_change=on_select_comparison,
|
26 |
)
|
27 |
with mex.dialog_actions():
|
28 |
-
|
29 |
"Close",
|
30 |
key="dialog_show_add_comparison",
|
31 |
on_click=handlers.on_close_dialog,
|
32 |
-
style=me.Style(border_radius="10"),
|
33 |
)
|
34 |
|
35 |
|
|
|
25 |
on_selection_change=on_select_comparison,
|
26 |
)
|
27 |
with mex.dialog_actions():
|
28 |
+
mex.button(
|
29 |
"Close",
|
30 |
key="dialog_show_add_comparison",
|
31 |
on_click=handlers.on_close_dialog,
|
|
|
32 |
)
|
33 |
|
34 |
|
dialogs/add_row.py
CHANGED
@@ -22,10 +22,10 @@ def add_row():
|
|
22 |
with me.box(
|
23 |
style=me.Style(display="flex", justify_content="end", margin=me.Margin(bottom=15))
|
24 |
):
|
25 |
-
|
26 |
"Generate",
|
27 |
on_click=on_click_generate_variables,
|
28 |
-
style=me.Style(background="#EBF1FD"
|
29 |
)
|
30 |
variable_names = set(parse_variables(state.prompt))
|
31 |
with me.box(style=me.Style(display="flex", flex_direction="column")):
|
@@ -41,13 +41,12 @@ def add_row():
|
|
41 |
)
|
42 |
|
43 |
with mex.dialog_actions():
|
44 |
-
|
45 |
"Close",
|
46 |
on_click=on_close_dialog,
|
47 |
key="dialog_show_add_row",
|
48 |
-
style=me.Style(border_radius="10"),
|
49 |
)
|
50 |
-
|
51 |
|
52 |
|
53 |
def on_close_dialog(e: me.ClickEvent):
|
|
|
22 |
with me.box(
|
23 |
style=me.Style(display="flex", justify_content="end", margin=me.Margin(bottom=15))
|
24 |
):
|
25 |
+
mex.button(
|
26 |
"Generate",
|
27 |
on_click=on_click_generate_variables,
|
28 |
+
style=me.Style(background="#EBF1FD"),
|
29 |
)
|
30 |
variable_names = set(parse_variables(state.prompt))
|
31 |
with me.box(style=me.Style(display="flex", flex_direction="column")):
|
|
|
41 |
)
|
42 |
|
43 |
with mex.dialog_actions():
|
44 |
+
mex.button(
|
45 |
"Close",
|
46 |
on_click=on_close_dialog,
|
47 |
key="dialog_show_add_row",
|
|
|
48 |
)
|
49 |
+
mex.button("Add", type="flat", on_click=on_click_add_row)
|
50 |
|
51 |
|
52 |
def on_close_dialog(e: me.ClickEvent):
|
dialogs/generate_prompt.py
CHANGED
@@ -21,17 +21,15 @@ def generate_prompt():
|
|
21 |
style=me.Style(width=DIALOG_INPUT_WIDTH),
|
22 |
)
|
23 |
with mex.dialog_actions():
|
24 |
-
|
25 |
"Close",
|
26 |
key="dialog_show_generate_prompt",
|
27 |
on_click=handlers.on_close_dialog,
|
28 |
-
style=me.Style(border_radius="10"),
|
29 |
)
|
30 |
-
|
31 |
"Generate",
|
32 |
type="flat",
|
33 |
on_click=on_click_generate_prompt,
|
34 |
-
style=me.Style(border_radius="10"),
|
35 |
)
|
36 |
|
37 |
|
|
|
21 |
style=me.Style(width=DIALOG_INPUT_WIDTH),
|
22 |
)
|
23 |
with mex.dialog_actions():
|
24 |
+
mex.button(
|
25 |
"Close",
|
26 |
key="dialog_show_generate_prompt",
|
27 |
on_click=handlers.on_close_dialog,
|
|
|
28 |
)
|
29 |
+
mex.button(
|
30 |
"Generate",
|
31 |
type="flat",
|
32 |
on_click=on_click_generate_prompt,
|
|
|
33 |
)
|
34 |
|
35 |
|
dialogs/load_prompt.py
CHANGED
@@ -21,14 +21,13 @@ def load_prompt():
|
|
21 |
type="flat",
|
22 |
color="primary",
|
23 |
on_upload=on_upload_prompt,
|
24 |
-
style=me.Style(
|
25 |
)
|
26 |
with mex.dialog_actions():
|
27 |
-
|
28 |
"Close",
|
29 |
key="dialog_show_load",
|
30 |
on_click=handlers.on_close_dialog,
|
31 |
-
style=me.Style(border_radius="10"),
|
32 |
)
|
33 |
|
34 |
|
|
|
21 |
type="flat",
|
22 |
color="primary",
|
23 |
on_upload=on_upload_prompt,
|
24 |
+
style=me.Style(border_radius=10),
|
25 |
)
|
26 |
with mex.dialog_actions():
|
27 |
+
mex.button(
|
28 |
"Close",
|
29 |
key="dialog_show_load",
|
30 |
on_click=handlers.on_close_dialog,
|
|
|
31 |
)
|
32 |
|
33 |
|
dialogs/model_settings.py
CHANGED
@@ -43,11 +43,10 @@ def model_settings():
|
|
43 |
)
|
44 |
|
45 |
with mex.dialog_actions():
|
46 |
-
|
47 |
"Close",
|
48 |
key="dialog_show_model_settings",
|
49 |
on_click=handlers.on_close_dialog,
|
50 |
-
style=me.Style(border_radius="10"),
|
51 |
)
|
52 |
|
53 |
|
|
|
43 |
)
|
44 |
|
45 |
with mex.dialog_actions():
|
46 |
+
mex.button(
|
47 |
"Close",
|
48 |
key="dialog_show_model_settings",
|
49 |
on_click=handlers.on_close_dialog,
|
|
|
50 |
)
|
51 |
|
52 |
|
dialogs/prompt_variables.py
CHANGED
@@ -20,10 +20,10 @@ def prompt_variables():
|
|
20 |
with me.box(
|
21 |
style=me.Style(display="flex", justify_content="end", margin=me.Margin(bottom=15))
|
22 |
):
|
23 |
-
|
24 |
"Generate",
|
25 |
on_click=on_click_generate_variables,
|
26 |
-
style=me.Style(background="#EBF1FD"
|
27 |
)
|
28 |
variable_names = set(parse_variables(state.prompt))
|
29 |
with me.box(style=me.Style(display="flex", flex_direction="column")):
|
@@ -39,11 +39,10 @@ def prompt_variables():
|
|
39 |
)
|
40 |
|
41 |
with mex.dialog_actions():
|
42 |
-
|
43 |
"Close",
|
44 |
on_click=handlers.on_close_dialog,
|
45 |
key="dialog_show_prompt_variables",
|
46 |
-
style=me.Style(border_radius="10"),
|
47 |
)
|
48 |
|
49 |
|
|
|
20 |
with me.box(
|
21 |
style=me.Style(display="flex", justify_content="end", margin=me.Margin(bottom=15))
|
22 |
):
|
23 |
+
mex.button(
|
24 |
"Generate",
|
25 |
on_click=on_click_generate_variables,
|
26 |
+
style=me.Style(background="#EBF1FD"),
|
27 |
)
|
28 |
variable_names = set(parse_variables(state.prompt))
|
29 |
with me.box(style=me.Style(display="flex", flex_direction="column")):
|
|
|
39 |
)
|
40 |
|
41 |
with mex.dialog_actions():
|
42 |
+
mex.button(
|
43 |
"Close",
|
44 |
on_click=handlers.on_close_dialog,
|
45 |
key="dialog_show_prompt_variables",
|
|
|
46 |
)
|
47 |
|
48 |
|
dialogs/prompt_version_history.py
CHANGED
@@ -23,11 +23,10 @@ def prompt_version_history():
|
|
23 |
on_selection_change=on_select_version,
|
24 |
)
|
25 |
with mex.dialog_actions():
|
26 |
-
|
27 |
"Close",
|
28 |
key="dialog_show_version_history",
|
29 |
on_click=handlers.on_close_dialog,
|
30 |
-
style=me.Style(border_radius="10"),
|
31 |
)
|
32 |
|
33 |
|
|
|
23 |
on_selection_change=on_select_version,
|
24 |
)
|
25 |
with mex.dialog_actions():
|
26 |
+
mex.button(
|
27 |
"Close",
|
28 |
key="dialog_show_version_history",
|
29 |
on_click=handlers.on_close_dialog,
|
|
|
30 |
)
|
31 |
|
32 |
|
dialogs/update_title.py
CHANGED
@@ -19,18 +19,16 @@ def update_title():
|
|
19 |
style=me.Style(width=DIALOG_INPUT_WIDTH),
|
20 |
)
|
21 |
with mex.dialog_actions():
|
22 |
-
|
23 |
"Cancel",
|
24 |
on_click=handlers.on_close_dialog,
|
25 |
key="dialog_show_title",
|
26 |
-
style=me.Style(border_radius="10"),
|
27 |
)
|
28 |
-
|
29 |
"Save",
|
30 |
type="flat",
|
31 |
disabled=not state.temp_title.strip(),
|
32 |
on_click=on_save_title,
|
33 |
-
style=me.Style(border_radius="10"),
|
34 |
)
|
35 |
|
36 |
|
|
|
19 |
style=me.Style(width=DIALOG_INPUT_WIDTH),
|
20 |
)
|
21 |
with mex.dialog_actions():
|
22 |
+
mex.button(
|
23 |
"Cancel",
|
24 |
on_click=handlers.on_close_dialog,
|
25 |
key="dialog_show_title",
|
|
|
26 |
)
|
27 |
+
mex.button(
|
28 |
"Save",
|
29 |
type="flat",
|
30 |
disabled=not state.temp_title.strip(),
|
31 |
on_click=on_save_title,
|
|
|
32 |
)
|
33 |
|
34 |
|
main.py
CHANGED
@@ -108,10 +108,10 @@ def app():
|
|
108 |
):
|
109 |
with me.tooltip(message="Run prompt"):
|
110 |
me.icon("play_arrow")
|
111 |
-
|
112 |
"Generate prompt",
|
113 |
disabled=bool(state.prompt),
|
114 |
-
style=me.Style(background="#EBF1FD"
|
115 |
on_click=handlers.on_open_dialog,
|
116 |
key="dialog_show_generate_prompt",
|
117 |
)
|
@@ -137,12 +137,11 @@ def app():
|
|
137 |
on_select_rating=on_select_rating,
|
138 |
on_click_run=on_click_eval_run,
|
139 |
)
|
140 |
-
|
141 |
label="Add row",
|
142 |
type="flat",
|
143 |
style=me.Style(
|
144 |
margin=me.Margin(top=10),
|
145 |
-
border_radius="10",
|
146 |
),
|
147 |
key="dialog_show_add_row",
|
148 |
on_click=handlers.on_open_dialog,
|
|
|
108 |
):
|
109 |
with me.tooltip(message="Run prompt"):
|
110 |
me.icon("play_arrow")
|
111 |
+
mex.button(
|
112 |
"Generate prompt",
|
113 |
disabled=bool(state.prompt),
|
114 |
+
style=me.Style(background="#EBF1FD"),
|
115 |
on_click=handlers.on_open_dialog,
|
116 |
key="dialog_show_generate_prompt",
|
117 |
)
|
|
|
137 |
on_select_rating=on_select_rating,
|
138 |
on_click_run=on_click_eval_run,
|
139 |
)
|
140 |
+
mex.button(
|
141 |
label="Add row",
|
142 |
type="flat",
|
143 |
style=me.Style(
|
144 |
margin=me.Margin(top=10),
|
|
|
145 |
),
|
146 |
key="dialog_show_add_row",
|
147 |
on_click=handlers.on_open_dialog,
|