Spaces:
Running
Running
Richard
commited on
Commit
·
e535042
1
Parent(s):
5434dbf
Update Mesop version + use new components
Browse files- components/__init__.py +0 -3
- components/button.py +0 -74
- components/card.py +0 -72
- main.py +39 -33
- requirements.txt +1 -1
components/__init__.py
CHANGED
@@ -1,7 +1,4 @@
|
|
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.content import markdown as markdown
|
6 |
from components.dialog import dialog as dialog
|
7 |
from components.dialog import dialog_actions as dialog_actions
|
|
|
|
|
1 |
from components.button import button as button
|
|
|
|
|
2 |
from components.content import markdown as markdown
|
3 |
from components.dialog import dialog as dialog
|
4 |
from components.dialog import dialog_actions as dialog_actions
|
components/button.py
CHANGED
@@ -28,78 +28,4 @@ def button(
|
|
28 |
style=helpers.merge_styles(me.Style(border_radius=10), style),
|
29 |
)
|
30 |
|
31 |
-
|
32 |
-
@me.component()
|
33 |
-
def button_toggle(
|
34 |
-
labels: list[str],
|
35 |
-
selected: str = "",
|
36 |
-
on_click: Callable | None = None,
|
37 |
-
key: str = "",
|
38 |
-
):
|
39 |
-
"""Simple version of Angular Component Button toggle.
|
40 |
-
|
41 |
-
Only supports single selection for now.
|
42 |
-
|
43 |
-
Args:
|
44 |
-
labels: Text labels for buttons
|
45 |
-
selected: Selected label
|
46 |
-
on_click: Event to handle button clicks on the button toggle
|
47 |
-
key: The key will be used as as prefix along with the selected label
|
48 |
-
"""
|
49 |
-
with me.box(style=me.Style(display="flex", font_weight="bold", font_size=14)):
|
50 |
-
last_index = len(labels) - 1
|
51 |
-
|
52 |
-
for index, label in enumerate(labels):
|
53 |
-
if index == 0:
|
54 |
-
element = "first"
|
55 |
-
elif index == last_index:
|
56 |
-
element = "last"
|
57 |
-
else:
|
58 |
-
element = "default"
|
59 |
-
|
60 |
-
with me.box(
|
61 |
-
key=key + "_" + label,
|
62 |
-
on_click=on_click,
|
63 |
-
style=me.Style(
|
64 |
-
align_items="center",
|
65 |
-
display="flex",
|
66 |
-
# Handle selected case
|
67 |
-
background=_SELECTED_BG
|
68 |
-
if label == selected
|
69 |
-
else me.theme_var("surface-container-lowest"),
|
70 |
-
padding=_SELECTED_PADDING if label == selected else _PADDING,
|
71 |
-
cursor="default" if label == selected else "pointer",
|
72 |
-
# Handle single button case (should just use a button in this case)
|
73 |
-
border=_LAST_BORDER if last_index == 0 else _BORDER_MAP[element],
|
74 |
-
border_radius=_BORDER_RADIUS if last_index == 0 else _BORDER_RADIUS_MAP[element],
|
75 |
-
),
|
76 |
-
):
|
77 |
-
if label in selected:
|
78 |
-
me.icon("check")
|
79 |
-
me.text(label)
|
80 |
-
|
81 |
-
|
82 |
-
_SELECTED_BG = me.theme_var("primary-container")
|
83 |
-
|
84 |
-
_PADDING = me.Padding(left=15, right=15, top=10, bottom=10)
|
85 |
-
_SELECTED_PADDING = me.Padding(left=15, right=15, top=5, bottom=5)
|
86 |
-
|
87 |
-
_BORDER_RADIUS = "20px"
|
88 |
-
|
89 |
_DEFAULT_BORDER_STYLE = me.BorderSide(width=1, color=me.theme_var("outline"), style="solid")
|
90 |
-
_BORDER = me.Border(
|
91 |
-
left=_DEFAULT_BORDER_STYLE, top=_DEFAULT_BORDER_STYLE, bottom=_DEFAULT_BORDER_STYLE
|
92 |
-
)
|
93 |
-
_LAST_BORDER = me.Border.all(_DEFAULT_BORDER_STYLE)
|
94 |
-
|
95 |
-
_BORDER_MAP = {
|
96 |
-
"first": _BORDER,
|
97 |
-
"last": _LAST_BORDER,
|
98 |
-
"default": _BORDER,
|
99 |
-
}
|
100 |
-
|
101 |
-
_BORDER_RADIUS_MAP = {
|
102 |
-
"first": "20px 0 0 20px",
|
103 |
-
"last": "0px 20px 20px 0",
|
104 |
-
"default": "0",
|
105 |
-
}
|
|
|
28 |
style=helpers.merge_styles(me.Style(border_radius=10), style),
|
29 |
)
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
_DEFAULT_BORDER_STYLE = me.BorderSide(width=1, color=me.theme_var("outline"), style="solid")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
components/card.py
DELETED
@@ -1,72 +0,0 @@
|
|
1 |
-
from components.helpers import merge_styles
|
2 |
-
|
3 |
-
from typing import Callable
|
4 |
-
|
5 |
-
import mesop as me
|
6 |
-
|
7 |
-
|
8 |
-
@me.content_component
|
9 |
-
def card(*, title: str = "", style: me.Style | None = None, key: str = ""):
|
10 |
-
"""Creates a simple card component similar to Angular Component.
|
11 |
-
|
12 |
-
Args:
|
13 |
-
title: If empty, not title will be shown
|
14 |
-
style: Override the default styles of the card box
|
15 |
-
key: Not really useful here
|
16 |
-
"""
|
17 |
-
with me.box(key=key, style=merge_styles(_DEFAULT_CARD_STYLE, style)):
|
18 |
-
if title:
|
19 |
-
me.text(
|
20 |
-
title,
|
21 |
-
style=me.Style(font_size=16, font_weight="bold", margin=me.Margin(bottom=15)),
|
22 |
-
)
|
23 |
-
|
24 |
-
me.slot()
|
25 |
-
|
26 |
-
|
27 |
-
@me.content_component
|
28 |
-
def expanable_card(
|
29 |
-
*,
|
30 |
-
title: str = "",
|
31 |
-
expanded: bool = False,
|
32 |
-
on_click_header: Callable | None = None,
|
33 |
-
style: me.Style | None = None,
|
34 |
-
key: str = "",
|
35 |
-
):
|
36 |
-
"""Creates a simple card component that is expandable.
|
37 |
-
|
38 |
-
Args:
|
39 |
-
title: If empty, no title will be shown but the expander will still be shown
|
40 |
-
expanded: Whether the card is expanded or not
|
41 |
-
on_click_header: Click handler for expanding card
|
42 |
-
style: Override the default styles of the card box
|
43 |
-
key: Key for the component
|
44 |
-
"""
|
45 |
-
with me.box(key=key, style=merge_styles(_DEFAULT_CARD_STYLE, style)):
|
46 |
-
with me.box(
|
47 |
-
on_click=on_click_header,
|
48 |
-
style=me.Style(
|
49 |
-
align_items="center",
|
50 |
-
display="flex",
|
51 |
-
justify_content="space-between",
|
52 |
-
),
|
53 |
-
):
|
54 |
-
me.text(
|
55 |
-
title,
|
56 |
-
style=me.Style(font_size=16, font_weight="bold"),
|
57 |
-
)
|
58 |
-
me.icon("keyboard_arrow_up" if expanded else "keyboard_arrow_down")
|
59 |
-
|
60 |
-
with me.box(style=me.Style(margin=me.Margin(top=15), display="block" if expanded else "none")):
|
61 |
-
me.slot()
|
62 |
-
|
63 |
-
|
64 |
-
_DEFAULT_CARD_STYLE = me.Style(
|
65 |
-
background=me.theme_var("surface-container-lowest"),
|
66 |
-
border_radius=10,
|
67 |
-
border=me.Border.all(
|
68 |
-
me.BorderSide(width=1, color=me.theme_var("outline-variant"), style="solid")
|
69 |
-
),
|
70 |
-
padding=me.Padding.all(15),
|
71 |
-
margin=me.Margin(bottom=15),
|
72 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
@@ -82,8 +82,13 @@ def app():
|
|
82 |
me.text(f"v{state.version}")
|
83 |
|
84 |
with mex.header_section():
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
87 |
)
|
88 |
|
89 |
if state.mode == "Prompt":
|
@@ -91,34 +96,31 @@ def app():
|
|
91 |
with me.box(
|
92 |
style=me.Style(padding=me.Padding(left=15, top=15, bottom=15), overflow_y="scroll")
|
93 |
):
|
94 |
-
with
|
95 |
-
title="System Instructions",
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
style=_STYLE_INVISIBLE_TEXTAREA,
|
106 |
-
key="system_instructions",
|
107 |
-
)
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
with me.box(
|
121 |
-
style=me.Style(align_items="center", display="flex", justify_content="space-between")
|
122 |
):
|
123 |
with me.content_button(
|
124 |
type="flat",
|
@@ -141,11 +143,15 @@ def app():
|
|
141 |
|
142 |
with me.box(style=me.Style(padding=me.Padding.all(15), overflow_y="scroll")):
|
143 |
if state.response:
|
144 |
-
with
|
145 |
-
|
|
|
|
|
146 |
else:
|
147 |
-
with
|
148 |
-
|
|
|
|
|
149 |
else:
|
150 |
# Render eval page
|
151 |
with me.box(style=me.Style(grid_column="1 / -2", overflow_y="scroll")):
|
@@ -276,10 +282,10 @@ def on_update_prompt(e: me.InputBlurEvent):
|
|
276 |
state.prompt_variables[variable_name] = ""
|
277 |
|
278 |
|
279 |
-
def
|
280 |
"""Toggle between Prompt and Eval modes."""
|
281 |
state = me.state(State)
|
282 |
-
state.mode =
|
283 |
|
284 |
|
285 |
def on_select_rating(e: me.SelectSelectionChangeEvent):
|
|
|
82 |
me.text(f"v{state.version}")
|
83 |
|
84 |
with mex.header_section():
|
85 |
+
me.button_toggle(
|
86 |
+
value=state.mode,
|
87 |
+
buttons=[
|
88 |
+
me.ButtonToggleButton(label="Prompt", value="Prompt"),
|
89 |
+
me.ButtonToggleButton(label="Eval", value="Eval"),
|
90 |
+
],
|
91 |
+
on_change=on_mode_toggle,
|
92 |
)
|
93 |
|
94 |
if state.mode == "Prompt":
|
|
|
96 |
with me.box(
|
97 |
style=me.Style(padding=me.Padding(left=15, top=15, bottom=15), overflow_y="scroll")
|
98 |
):
|
99 |
+
with me.accordion():
|
100 |
+
with me.expansion_panel(title="System Instructions", style=me.Style(background=me.theme_var('surface-container-lowest'))):
|
101 |
+
me.native_textarea(
|
102 |
+
autosize=True,
|
103 |
+
min_rows=2,
|
104 |
+
placeholder="Optional tone and style instructions for the model",
|
105 |
+
value=state.system_instructions,
|
106 |
+
on_blur=handlers.on_update_input,
|
107 |
+
style=_STYLE_INVISIBLE_TEXTAREA,
|
108 |
+
key="system_instructions",
|
109 |
+
)
|
|
|
|
|
|
|
110 |
|
111 |
+
with me.expansion_panel(title="Prompt", expanded=True, style=me.Style(background=me.theme_var('surface-container-lowest'))):
|
112 |
+
me.native_textarea(
|
113 |
+
autosize=True,
|
114 |
+
min_rows=2,
|
115 |
+
placeholder="Enter your prompt",
|
116 |
+
value=state.prompt,
|
117 |
+
on_blur=on_update_prompt,
|
118 |
+
style=_STYLE_INVISIBLE_TEXTAREA,
|
119 |
+
key="prompt",
|
120 |
+
)
|
121 |
|
122 |
with me.box(
|
123 |
+
style=me.Style(align_items="center", display="flex", justify_content="space-between", margin=me.Margin(top=15))
|
124 |
):
|
125 |
with me.content_button(
|
126 |
type="flat",
|
|
|
143 |
|
144 |
with me.box(style=me.Style(padding=me.Padding.all(15), overflow_y="scroll")):
|
145 |
if state.response:
|
146 |
+
with me.card(appearance="raised", style=me.Style(background=me.theme_var('surface-container-lowest'))):
|
147 |
+
me.card_header(title="Response")
|
148 |
+
with me.card_content():
|
149 |
+
mex.markdown(state.response, has_copy_to_clipboard=True)
|
150 |
else:
|
151 |
+
with me.card(appearance="raised", style=me.Style(background=me.theme_var('surface-container-lowest'))):
|
152 |
+
me.card_header(title="Prompt Tuner Instructions")
|
153 |
+
with me.card_content():
|
154 |
+
mex.markdown(_INSTRUCTIONS, has_copy_to_clipboard=True)
|
155 |
else:
|
156 |
# Render eval page
|
157 |
with me.box(style=me.Style(grid_column="1 / -2", overflow_y="scroll")):
|
|
|
282 |
state.prompt_variables[variable_name] = ""
|
283 |
|
284 |
|
285 |
+
def on_mode_toggle(e: me.ButtonToggleChangeEvent):
|
286 |
"""Toggle between Prompt and Eval modes."""
|
287 |
state = me.state(State)
|
288 |
+
state.mode = e.value
|
289 |
|
290 |
|
291 |
def on_select_rating(e: me.SelectSelectionChangeEvent):
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
gunicorn
|
2 |
-
mesop==0.12.
|
3 |
google-generativeai
|
|
|
1 |
gunicorn
|
2 |
+
mesop==0.12.9
|
3 |
google-generativeai
|