Richard commited on
Commit
8886757
·
1 Parent(s): a43df2a

Add copy to clipboard buttons

Browse files
Files changed (4) hide show
  1. components/__init__.py +1 -0
  2. components/content.py +18 -0
  3. eval_table.py +3 -3
  4. main.py +3 -3
components/__init__.py CHANGED
@@ -2,6 +2,7 @@ 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
6
  from components.dialog import dialog_actions as dialog_actions
7
  from components.header import header as header
 
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
8
  from components.header import header as header
components/content.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import mesop as me
2
+
3
+ from web_components import markedjs_component
4
+ from web_components import copy_to_clipboard_component
5
+
6
+
7
+ @me.component
8
+ def markdown(text: str, has_copy_to_clipboard: bool = False):
9
+ with me.box(style=me.Style(position="relative")):
10
+ if has_copy_to_clipboard:
11
+ with me.box(style=me.Style(position="absolute", right=0)):
12
+ with copy_to_clipboard_component(text=text):
13
+ with me.content_button(
14
+ type="icon",
15
+ style=me.Style(cursor="pointer", background=me.theme_var("surface-container")),
16
+ ):
17
+ me.icon("content_copy")
18
+ markedjs_component(text)
eval_table.py CHANGED
@@ -3,8 +3,8 @@ import hashlib
3
 
4
  import mesop as me
5
 
 
6
  from state import Prompt
7
- from web_components import markedjs_component
8
 
9
 
10
  @me.component
@@ -60,12 +60,12 @@ def prompt_eval_table(
60
  me.text(str(row_index))
61
  elif row["type"] == "variable":
62
  with me.box(style=_MARKDOWN_BOX_STYLE):
63
- markedjs_component(example["variables"][row["variable_name"]])
64
  elif row["type"] == "model_response":
65
  with me.box(style=_MARKDOWN_BOX_STYLE):
66
  prompt_response = response_map[row["prompt"].version].get(response_key)
67
  if prompt_response and prompt_response[0]["output"]:
68
- markedjs_component(prompt_response[0]["output"])
69
  else:
70
  with me.box(
71
  style=me.Style(
 
3
 
4
  import mesop as me
5
 
6
+ import components as mex
7
  from state import Prompt
 
8
 
9
 
10
  @me.component
 
60
  me.text(str(row_index))
61
  elif row["type"] == "variable":
62
  with me.box(style=_MARKDOWN_BOX_STYLE):
63
+ mex.markdown(example["variables"][row["variable_name"]], has_copy_to_clipboard=True)
64
  elif row["type"] == "model_response":
65
  with me.box(style=_MARKDOWN_BOX_STYLE):
66
  prompt_response = response_map[row["prompt"].version].get(response_key)
67
  if prompt_response and prompt_response[0]["output"]:
68
+ mex.markdown(prompt_response[0]["output"], has_copy_to_clipboard=True)
69
  else:
70
  with me.box(
71
  style=me.Style(
main.py CHANGED
@@ -13,7 +13,7 @@ from helpers import find_prompt, parse_variables
13
  from state import State, Prompt
14
  from web_components import AsyncAction
15
  from web_components import async_action_component
16
- from web_components import markedjs_component
17
 
18
  _INSTRUCTIONS = """
19
  - Write your prompt.
@@ -142,10 +142,10 @@ def app():
142
  with me.box(style=me.Style(padding=me.Padding.all(15), overflow_y="scroll")):
143
  if state.response:
144
  with mex.card(title="Response", style=me.Style(overflow_y="hidden")):
145
- markedjs_component(state.response)
146
  else:
147
  with mex.card(title="Prompt Tuner Instructions"):
148
- markedjs_component(_INSTRUCTIONS)
149
  else:
150
  # Render eval page
151
  with me.box(style=me.Style(grid_column="1 / -2", overflow_y="scroll")):
 
13
  from state import State, Prompt
14
  from web_components import AsyncAction
15
  from web_components import async_action_component
16
+
17
 
18
  _INSTRUCTIONS = """
19
  - Write your prompt.
 
142
  with me.box(style=me.Style(padding=me.Padding.all(15), overflow_y="scroll")):
143
  if state.response:
144
  with mex.card(title="Response", style=me.Style(overflow_y="hidden")):
145
+ mex.markdown(state.response, has_copy_to_clipboard=True)
146
  else:
147
  with mex.card(title="Prompt Tuner Instructions"):
148
+ mex.markdown(_INSTRUCTIONS, has_copy_to_clipboard=True)
149
  else:
150
  # Render eval page
151
  with me.box(style=me.Style(grid_column="1 / -2", overflow_y="scroll")):