yaleh commited on
Commit
f9df713
·
1 Parent(s): 641fd34

Updated layout.

Browse files
Files changed (2) hide show
  1. TODO.md +4 -1
  2. app/gradio_sample_generator.py +27 -34
TODO.md CHANGED
@@ -4,4 +4,7 @@
4
  * [ ] Implement `Map Reduce` using the guide provided at https://langchain-ai.github.io/langgraph/how-tos/map-reduce/ for meta-prompting with batch data.
5
  * [ ] Fine-tune a model/LoRa for Meta Prompt.
6
  * [ ] Collect/create a data set for the fine-tuning.
7
- * [ ] Create a benchmark for Meta Prompt.
 
 
 
 
4
  * [ ] Implement `Map Reduce` using the guide provided at https://langchain-ai.github.io/langgraph/how-tos/map-reduce/ for meta-prompting with batch data.
5
  * [ ] Fine-tune a model/LoRa for Meta Prompt.
6
  * [ ] Collect/create a data set for the fine-tuning.
7
+ * [ ] Create a benchmark for Meta Prompt.
8
+ * [ ] `Clear` button for Streamlit UI.
9
+ * [ ] `Validate` button for `Prompt` tab.
10
+ * [ ] `Diff` button for `Prompt` tab to show the difference between the expected output and the actual output.
app/gradio_sample_generator.py CHANGED
@@ -128,21 +128,16 @@ def generate_examples_directly(
128
  def format_selected_example(evt: gr.SelectData, examples):
129
  if evt.index[0] < len(examples):
130
  selected_example = examples.iloc[evt.index[0]]
131
- json_example = json.dumps(
132
- {"input": selected_example.iloc[0], "output": selected_example.iloc[1]},
133
- indent=2,
134
- ensure_ascii=False,
135
- )
136
- return json_example
137
- return ""
138
 
139
- def import_json(file):
140
  if file is not None:
141
  df = pd.read_json(file.name)
142
  # Uppercase the first letter of each column name
143
  df.columns = df.columns.str.title()
144
  return df
145
- return None
146
 
147
  def export_json(df):
148
  if df is not None and not df.empty:
@@ -160,16 +155,13 @@ def export_json(df):
160
  return temp_file_path
161
  return None
162
 
163
- def append_example_to_input(new_example_json, input_df):
164
  try:
165
- new_example = json.loads(new_example_json)
166
- new_row = pd.DataFrame([[new_example['input'], new_example['output']]], columns=['Input', 'Output'])
167
  updated_df = pd.concat([input_df, new_row], ignore_index=True)
168
  return updated_df
169
- except json.JSONDecodeError:
170
- raise gr.Error("Invalid JSON format")
171
  except KeyError:
172
- raise gr.Error("JSON must contain 'input' and 'output' keys")
173
 
174
  with gr.Blocks(title="Task Description Generator") as demo:
175
  gr.Markdown("# Task Description Generator")
@@ -185,6 +177,13 @@ with gr.Blocks(title="Task Description Generator") as demo:
185
  row_count=(1, "dynamic"),
186
  col_count=(2, "fixed"),
187
  )
 
 
 
 
 
 
 
188
  with gr.Accordion("Import/Export JSON", open=False):
189
  json_file = gr.File(
190
  label="Import/Export JSON", file_types=[".json"], type="filepath"
@@ -209,14 +208,11 @@ with gr.Blocks(title="Task Description Generator") as demo:
209
  generating_batch_size = gr.Slider(
210
  label="Generating Batch Size", value=3, minimum=1, maximum=10, step=1
211
  )
212
- with gr.Row():
213
- submit_button = gr.Button("Generate", variant="primary")
214
  generate_description_button = gr.Button(
215
  "Generate Description", variant="secondary"
216
  )
217
-
218
-
219
- with gr.Accordion("Description and Analysis", open=False):
220
  description_output = gr.Textbox(
221
  label="Description", lines=5, show_copy_button=True
222
  )
@@ -238,7 +234,6 @@ with gr.Blocks(title="Task Description Generator") as demo:
238
  input_analysis_output = gr.Textbox(
239
  label="Input Analysis", lines=5, show_copy_button=True
240
  )
241
- with gr.Accordion("Briefs and Examples", open=False):
242
  generate_briefs_button = gr.Button(
243
  "Generate Briefs", variant="secondary"
244
  )
@@ -264,10 +259,6 @@ with gr.Blocks(title="Task Description Generator") as demo:
264
  row_count=(1, "dynamic"),
265
  col_count=(2, "fixed"),
266
  )
267
- new_example_json = gr.Textbox(
268
- label="New Example JSON", lines=5, show_copy_button=True
269
- )
270
- append_example_button = gr.Button("Append to Input Examples", variant="secondary")
271
 
272
  clear_button = gr.ClearButton(
273
  [
@@ -277,13 +268,15 @@ with gr.Blocks(title="Task Description Generator") as demo:
277
  example_briefs_output,
278
  examples_from_briefs_output,
279
  examples_output,
280
- new_example_json,
281
- ]
 
 
282
  )
283
 
284
  json_file.change(
285
  fn=import_json,
286
- inputs=[json_file],
287
  outputs=[input_df],
288
  )
289
 
@@ -363,23 +356,23 @@ with gr.Blocks(title="Task Description Generator") as demo:
363
  examples_directly_output.select(
364
  fn=format_selected_example,
365
  inputs=[examples_directly_output],
366
- outputs=[new_example_json],
367
  )
368
 
369
  examples_from_briefs_output.select(
370
  fn=format_selected_example,
371
  inputs=[examples_from_briefs_output],
372
- outputs=[new_example_json],
373
  )
374
 
375
  examples_output.select(
376
  fn=format_selected_example,
377
  inputs=[examples_output],
378
- outputs=[new_example_json],
379
  )
380
 
381
- gr.Markdown("### Manual Flagging")
382
- with gr.Row():
383
  flag_button = gr.Button("Flag")
384
  flag_reason = gr.Textbox(label="Reason for flagging")
385
 
@@ -399,7 +392,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
399
 
400
  append_example_button.click(
401
  fn=append_example_to_input,
402
- inputs=[new_example_json, input_df],
403
  outputs=[input_df],
404
  )
405
 
 
128
  def format_selected_example(evt: gr.SelectData, examples):
129
  if evt.index[0] < len(examples):
130
  selected_example = examples.iloc[evt.index[0]]
131
+ return selected_example.iloc[0], selected_example.iloc[1]
132
+ return "", ""
 
 
 
 
 
133
 
134
+ def import_json(file, input_df):
135
  if file is not None:
136
  df = pd.read_json(file.name)
137
  # Uppercase the first letter of each column name
138
  df.columns = df.columns.str.title()
139
  return df
140
+ return input_df
141
 
142
  def export_json(df):
143
  if df is not None and not df.empty:
 
155
  return temp_file_path
156
  return None
157
 
158
+ def append_example_to_input(new_example_input, new_example_output, input_df):
159
  try:
160
+ new_row = pd.DataFrame([[new_example_input, new_example_output]], columns=['Input', 'Output'])
 
161
  updated_df = pd.concat([input_df, new_row], ignore_index=True)
162
  return updated_df
 
 
163
  except KeyError:
164
+ raise gr.Error("Invalid input or output")
165
 
166
  with gr.Blocks(title="Task Description Generator") as demo:
167
  gr.Markdown("# Task Description Generator")
 
177
  row_count=(1, "dynamic"),
178
  col_count=(2, "fixed"),
179
  )
180
+ with gr.Group():
181
+ with gr.Row():
182
+ new_example_input = gr.Textbox(label="Selected Example Input", lines=2, show_copy_button=True)
183
+ new_example_output = gr.Textbox(label="Selected Example Output", lines=2, show_copy_button=True)
184
+ append_example_button = gr.Button("Append to Input Examples", variant="secondary")
185
+ with gr.Row():
186
+ submit_button = gr.Button("Generate", variant="primary")
187
  with gr.Accordion("Import/Export JSON", open=False):
188
  json_file = gr.File(
189
  label="Import/Export JSON", file_types=[".json"], type="filepath"
 
208
  generating_batch_size = gr.Slider(
209
  label="Generating Batch Size", value=3, minimum=1, maximum=10, step=1
210
  )
211
+
212
+ with gr.Accordion("Analysis", open=False):
213
  generate_description_button = gr.Button(
214
  "Generate Description", variant="secondary"
215
  )
 
 
 
216
  description_output = gr.Textbox(
217
  label="Description", lines=5, show_copy_button=True
218
  )
 
234
  input_analysis_output = gr.Textbox(
235
  label="Input Analysis", lines=5, show_copy_button=True
236
  )
 
237
  generate_briefs_button = gr.Button(
238
  "Generate Briefs", variant="secondary"
239
  )
 
259
  row_count=(1, "dynamic"),
260
  col_count=(2, "fixed"),
261
  )
 
 
 
 
262
 
263
  clear_button = gr.ClearButton(
264
  [
 
268
  example_briefs_output,
269
  examples_from_briefs_output,
270
  examples_output,
271
+ new_example_input,
272
+ new_example_output,
273
+ ],
274
+ value="Clear All"
275
  )
276
 
277
  json_file.change(
278
  fn=import_json,
279
+ inputs=[json_file, input_df],
280
  outputs=[input_df],
281
  )
282
 
 
356
  examples_directly_output.select(
357
  fn=format_selected_example,
358
  inputs=[examples_directly_output],
359
+ outputs=[new_example_input, new_example_output],
360
  )
361
 
362
  examples_from_briefs_output.select(
363
  fn=format_selected_example,
364
  inputs=[examples_from_briefs_output],
365
+ outputs=[new_example_input, new_example_output],
366
  )
367
 
368
  examples_output.select(
369
  fn=format_selected_example,
370
  inputs=[examples_output],
371
+ outputs=[new_example_input, new_example_output],
372
  )
373
 
374
+ gr.Markdown("### Manual Flagging", visible=False)
375
+ with gr.Row(visible=False):
376
  flag_button = gr.Button("Flag")
377
  flag_reason = gr.Textbox(label="Reason for flagging")
378
 
 
392
 
393
  append_example_button.click(
394
  fn=append_example_to_input,
395
+ inputs=[new_example_input, new_example_output, input_df],
396
  outputs=[input_df],
397
  )
398