yaleh commited on
Commit
8274eff
·
1 Parent(s): bcbe6a9

Updated UI.

Browse files
app/gradio_meta_prompt.py CHANGED
@@ -36,20 +36,28 @@ with gr.Blocks(title='Meta Prompt') as demo:
36
  input_dataframe = gr.DataFrame(
37
  label="Input Examples",
38
  headers=["Input", "Output"],
 
39
  datatype=["str", "str"],
40
  column_widths=["50%", "50%"],
41
  row_count=(1, "dynamic"),
42
  col_count=(2, "fixed"),
43
- interactive=False,
44
  wrap=True
45
  )
46
  with gr.Column(scale=1, min_width=100):
47
  with gr.Group():
 
48
  json_file_object = gr.File(
49
  label="Import/Export JSON", file_types=[".json"], type="filepath",
50
  min_width=80
51
  )
52
  export_button = gr.Button("Export to JSON")
 
 
 
 
 
 
53
 
54
  with gr.Row():
55
  with gr.Column(scale=3):
@@ -83,89 +91,83 @@ with gr.Blocks(title='Meta Prompt') as demo:
83
  outputs=[selected_example_output],
84
  )
85
 
86
- @gr.render(
87
- inputs=[
88
- selected_group_mode,
89
- selected_group_index,
90
- selected_group_input,
91
- selected_group_output,
92
- ],
93
- triggers=[selected_group_mode.change],
94
- )
95
- def selected_group(mode, index, input, output):
96
- if mode is None:
97
- return
98
- with gr.Group():
99
- if mode == "update":
100
- with gr.Row():
101
- selected_row_index = gr.Number(
102
- label="Selected Row Index", value=index, precision=0, interactive=False
103
- )
104
- update_row_button = gr.Button(
105
- "Update Selected Row", variant="secondary"
106
- )
107
- delete_row_button = gr.Button(
108
- "Delete Selected Row", variant="secondary"
109
- )
110
- # close_button = gr.Button("Close", variant="secondary")
111
-
112
- update_row_button.click(
113
- fn=update_selected_dataframe_row,
114
- inputs=[
115
- selected_example_input,
116
- selected_example_output,
117
- selected_row_index,
118
- input_dataframe,
119
- ],
120
- outputs=[
121
- input_dataframe,
122
- selected_group_mode,
123
- selected_group_index,
124
- selected_group_input,
125
- selected_group_output,
126
- ],
127
- )
128
 
129
- delete_row_button.click(
130
- fn=delete_selected_dataframe_row,
131
- inputs=[selected_row_index, input_dataframe],
132
- outputs=[
133
- input_dataframe,
134
- selected_group_mode,
135
- selected_group_index,
136
- selected_group_input,
137
- selected_group_output,
138
- ],
139
- )
140
 
141
- elif mode == "append":
142
- with gr.Row():
143
- append_example_button = gr.Button(
144
- "Append to Input Examples", variant="secondary"
145
- )
146
- # close_button = gr.Button("Close", variant="secondary")
147
-
148
- append_example_button.click(
149
- fn=append_example_to_input_dataframe,
150
- inputs=[
151
- selected_example_input,
152
- selected_example_output,
153
- input_dataframe,
154
- ],
155
- outputs=[
156
- input_dataframe,
157
- selected_group_mode,
158
- selected_group_index,
159
- selected_group_input,
160
- selected_group_output,
161
- ],
162
- )
163
 
164
- # close_button.click(
165
- # fn=lambda: None,
166
- # inputs=[],
167
- # outputs=[selected_group_mode],
168
- # )
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  with gr.Tabs() as tabs:
171
 
@@ -175,9 +177,8 @@ with gr.Blocks(title='Meta Prompt') as demo:
175
  scope_submit_button = gr.Button("Generate", variant="primary", interactive=False)
176
  scope_clear_button = gr.ClearButton(
177
  [
178
- input_dataframe
179
  ],
180
- value="Clear All"
181
  )
182
 
183
  examples_output_dataframe = gr.DataFrame(
@@ -285,7 +286,7 @@ with gr.Blocks(title='Meta Prompt') as demo:
285
 
286
  with gr.Row():
287
  prompt_submit_button = gr.Button(value="Submit", variant="primary", interactive=False)
288
- prompt_clear_button = gr.ClearButton(value='Clear All')
289
 
290
  with gr.Row():
291
  with gr.Column():
@@ -473,10 +474,6 @@ with gr.Blocks(title='Meta Prompt') as demo:
473
  examples = gr.Examples(config.examples_path, inputs=[
474
  selected_example_input,
475
  selected_example_output,
476
- # acceptance_criteria_input,
477
- # initial_system_message_input,
478
- # recursion_limit_input,
479
- # simple_model_name_input
480
  ])
481
 
482
  prompt_model_tab_state = gr.State(value='Simple')
@@ -511,9 +508,24 @@ with gr.Blocks(title='Meta Prompt') as demo:
511
  scope_inputs_ready_state = gr.State(value=False)
512
  prompt_inputs_ready_state = gr.State(value=False)
513
 
 
 
 
 
 
 
 
 
 
 
 
514
  # set up event handlers for the scope tab
 
 
 
 
515
  input_dataframe.change(
516
- fn=lambda x: len(x) > 0, # input_dataframe has at least 1 data row
517
  inputs=[input_dataframe],
518
  outputs=[scope_inputs_ready_state],
519
  )
@@ -843,7 +855,7 @@ with gr.Blocks(title='Meta Prompt') as demo:
843
  outputs=[acceptance_criteria_input]
844
  )
845
 
846
- prompt_clear_button.add([selected_example_input, selected_example_output,
847
  acceptance_criteria_input, initial_system_message_input,
848
  system_message_output, output_output,
849
  acceptance_criteria_output, analysis_output, logs_chatbot])
@@ -884,11 +896,15 @@ with gr.Blocks(title='Meta Prompt') as demo:
884
  ]
885
  )
886
 
 
 
 
 
 
 
887
  flagging_inputs = [
888
  selected_example_input,
889
- selected_example_output,
890
- # acceptance_criteria_input,
891
- # initial_system_message_input
892
  ]
893
 
894
  # Configure flagging
 
36
  input_dataframe = gr.DataFrame(
37
  label="Input Examples",
38
  headers=["Input", "Output"],
39
+ value=[],
40
  datatype=["str", "str"],
41
  column_widths=["50%", "50%"],
42
  row_count=(1, "dynamic"),
43
  col_count=(2, "fixed"),
44
+ interactive=True,
45
  wrap=True
46
  )
47
  with gr.Column(scale=1, min_width=100):
48
  with gr.Group():
49
+ editable_checkbox = gr.Checkbox(label="Editable", value=True)
50
  json_file_object = gr.File(
51
  label="Import/Export JSON", file_types=[".json"], type="filepath",
52
  min_width=80
53
  )
54
  export_button = gr.Button("Export to JSON")
55
+ clear_inputs_button = gr.ClearButton(
56
+ [
57
+ input_dataframe
58
+ ],
59
+ value="Clear Inputs"
60
+ )
61
 
62
  with gr.Row():
63
  with gr.Column(scale=3):
 
91
  outputs=[selected_example_output],
92
  )
93
 
94
+ with (selected_input_group := gr.Group(visible=False)):
95
+ with gr.Row():
96
+ selected_row_index = gr.Number(
97
+ label="Selected Row Index", value=0, precision=0, interactive=False, visible=False
98
+ )
99
+ update_row_button = gr.Button(
100
+ "Update Selected Row", variant="secondary", visible=False
101
+ )
102
+ delete_row_button = gr.Button(
103
+ "Delete Selected Row", variant="secondary", visible=False
104
+ )
105
+ append_example_button = gr.Button(
106
+ "Append to Input Examples", variant="secondary", visible=False
107
+ )
108
+
109
+ update_row_button.click(
110
+ fn=update_selected_dataframe_row,
111
+ inputs=[
112
+ selected_example_input,
113
+ selected_example_output,
114
+ selected_row_index,
115
+ input_dataframe,
116
+ ],
117
+ outputs=[
118
+ input_dataframe,
119
+ selected_group_mode,
120
+ selected_group_index,
121
+ selected_group_input,
122
+ selected_group_output,
123
+ ],
124
+ )
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ delete_row_button.click(
127
+ fn=delete_selected_dataframe_row,
128
+ inputs=[selected_row_index, input_dataframe],
129
+ outputs=[
130
+ input_dataframe,
131
+ selected_group_mode,
132
+ selected_group_index,
133
+ selected_group_input,
134
+ selected_group_output,
135
+ ],
136
+ )
137
 
138
+ append_example_button.click(
139
+ fn=append_example_to_input_dataframe,
140
+ inputs=[
141
+ selected_example_input,
142
+ selected_example_output,
143
+ input_dataframe,
144
+ ],
145
+ outputs=[
146
+ input_dataframe,
147
+ selected_group_mode,
148
+ selected_group_index,
149
+ selected_group_input,
150
+ selected_group_output,
151
+ ],
152
+ )
 
 
 
 
 
 
 
153
 
154
+ selected_group_mode.change(
155
+ fn=lambda mode: [
156
+ gr.update(visible=(mode is not None)),
157
+ gr.update(visible=(mode == "update")),
158
+ gr.update(visible=(mode == "update")),
159
+ gr.update(visible=(mode == "update")),
160
+ gr.update(visible=(mode == "append")),
161
+ ],
162
+ inputs=[selected_group_mode],
163
+ outputs=[selected_input_group, selected_row_index, update_row_button, delete_row_button, append_example_button],
164
+ )
165
+
166
+ selected_group_index.change(
167
+ fn=lambda index: gr.update(value=index),
168
+ inputs=[selected_group_index],
169
+ outputs=[selected_row_index],
170
+ )
171
 
172
  with gr.Tabs() as tabs:
173
 
 
177
  scope_submit_button = gr.Button("Generate", variant="primary", interactive=False)
178
  scope_clear_button = gr.ClearButton(
179
  [
 
180
  ],
181
+ value="Clear Outputs"
182
  )
183
 
184
  examples_output_dataframe = gr.DataFrame(
 
286
 
287
  with gr.Row():
288
  prompt_submit_button = gr.Button(value="Submit", variant="primary", interactive=False)
289
+ prompt_clear_button = gr.ClearButton(value='Clear Output')
290
 
291
  with gr.Row():
292
  with gr.Column():
 
474
  examples = gr.Examples(config.examples_path, inputs=[
475
  selected_example_input,
476
  selected_example_output,
 
 
 
 
477
  ])
478
 
479
  prompt_model_tab_state = gr.State(value='Simple')
 
508
  scope_inputs_ready_state = gr.State(value=False)
509
  prompt_inputs_ready_state = gr.State(value=False)
510
 
511
+ # event handlers for inputs
512
+ editable_checkbox.change(
513
+ fn=lambda x: gr.update(interactive=x),
514
+ inputs=[editable_checkbox],
515
+ outputs=[input_dataframe],
516
+ )
517
+
518
+ clear_inputs_button.add(
519
+ [selected_group_input, selected_example_output, selected_group_index, selected_group_mode]
520
+ )
521
+
522
  # set up event handlers for the scope tab
523
+ def valid_input_dataframe(x):
524
+ # validate it's not empty and not all the values are ''
525
+ return not x.empty and not x.isnull().any().any() and not x.eq('').any().any()
526
+
527
  input_dataframe.change(
528
+ fn=valid_input_dataframe, # input_dataframe has at least 1 data row and no NaN values
529
  inputs=[input_dataframe],
530
  outputs=[scope_inputs_ready_state],
531
  )
 
855
  outputs=[acceptance_criteria_input]
856
  )
857
 
858
+ prompt_clear_button.add([
859
  acceptance_criteria_input, initial_system_message_input,
860
  system_message_output, output_output,
861
  acceptance_criteria_output, analysis_output, logs_chatbot])
 
896
  ]
897
  )
898
 
899
+ examples.load_input_event.then(
900
+ lambda: "append",
901
+ None,
902
+ selected_group_mode,
903
+ )
904
+
905
  flagging_inputs = [
906
  selected_example_input,
907
+ selected_example_output
 
 
908
  ]
909
 
910
  # Configure flagging
solara_editable_dataframe_demo.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import solara
2
+ import pandas as pd
3
+ import plotly
4
+
5
+ df = plotly.data.iris()
6
+
7
+ @solara.component
8
+ def Page():
9
+ solara.DataFrame(df, items_per_page=5)
10
+
11
+ # Run the Solara app
12
+ if __name__ == "__main__":
13
+ Page()