yaleh commited on
Commit
ac847d0
·
1 Parent(s): 6fc28f9

Updated layout.

Browse files
Files changed (1) hide show
  1. app/gradio_sample_generator.py +114 -61
app/gradio_sample_generator.py CHANGED
@@ -38,9 +38,10 @@ def process_json_data(
38
  [example["input"], example["output"]]
39
  for example in result["additional_examples"]
40
  ]
41
-
42
  return (
43
  description,
 
44
  examples_directly,
45
  input_analysis,
46
  new_example_briefs,
@@ -56,8 +57,10 @@ def generate_description(examples, model_name, temperature):
56
 
57
  model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
58
  generator = TaskDescriptionGenerator(model)
59
- description = generator.generate_description(input_json)
60
- return description
 
 
61
  except Exception as e:
62
  raise gr.Error(f"An error occurred: {str(e)}")
63
 
@@ -212,11 +215,28 @@ def input_dataframe_change(
212
  selected_group_output,
213
  )
214
 
215
- with gr.Blocks(title="Task Description Generator") as demo:
216
- gr.Markdown("# Task Description Generator")
217
- gr.Markdown(
218
- "Enter a JSON object with 'input' and 'output' fields to generate a task description and additional examples."
219
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
 
221
  input_dataframe = gr.DataFrame(
222
  label="Input Examples",
@@ -270,6 +290,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
270
  update_row_button = gr.Button(
271
  "Update Selected Row", variant="secondary"
272
  )
 
273
 
274
  delete_row_button.click(
275
  fn=delete_selected_dataframe_row,
@@ -317,6 +338,8 @@ with gr.Blocks(title="Task Description Generator") as demo:
317
  append_example_button = gr.Button(
318
  "Append to Input Examples", variant="secondary"
319
  )
 
 
320
  append_example_button.click(
321
  fn=append_example_to_input_dataframe,
322
  inputs=[
@@ -333,22 +356,30 @@ with gr.Blocks(title="Task Description Generator") as demo:
333
  ],
334
  )
335
 
336
- with gr.Row():
337
- close_button = gr.Button("Close", variant="secondary")
338
  close_button.click(
339
  fn=lambda: None,
340
  inputs=[],
341
  outputs=[selected_group_mode],
342
  )
343
 
344
- with gr.Row():
345
- submit_button = gr.Button("Generate", variant="primary")
346
  with gr.Accordion("Import/Export JSON", open=False):
347
  json_file_object = gr.File(
348
  label="Import/Export JSON", file_types=[".json"], type="filepath"
349
  )
350
  export_button = gr.Button("Export to JSON")
351
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  with gr.Accordion("Model Settings", open=False):
353
  model_name = gr.Dropdown(
354
  label="Model Name",
@@ -369,60 +400,69 @@ with gr.Blocks(title="Task Description Generator") as demo:
369
  )
370
 
371
  with gr.Accordion("Analysis", open=False):
372
- generate_description_button = gr.Button(
373
- "Generate Description", variant="secondary"
374
- )
375
- description_output = gr.Textbox(
376
- label="Description", lines=5, show_copy_button=True
377
- )
378
  with gr.Row():
379
- generate_examples_directly_button = gr.Button(
380
- "Generate Examples Directly", variant="secondary"
381
- )
382
- analyze_input_button = gr.Button(
383
- "Analyze Input", variant="secondary"
384
- )
385
- examples_directly_output_dataframe = gr.DataFrame(
386
- label="Examples Directly",
387
- headers=["Input", "Output"],
388
- interactive=False,
389
- datatype=["str", "str"],
390
- row_count=(1, "dynamic"),
391
- col_count=(2, "fixed"),
392
- )
393
- input_analysis_output = gr.Textbox(
394
- label="Input Analysis", lines=5, show_copy_button=True
395
- )
396
- generate_briefs_button = gr.Button(
397
- "Generate Briefs", variant="secondary"
398
- )
399
- example_briefs_output = gr.Textbox(
400
- label="Example Briefs", lines=5, show_copy_button=True
401
- )
402
- generate_examples_from_briefs_button = gr.Button(
403
- "Generate Examples from Briefs", variant="secondary"
404
- )
405
- examples_from_briefs_output_dataframe = gr.DataFrame(
406
- label="Examples from Briefs",
407
- headers=["Input", "Output"],
408
- interactive=False,
409
- datatype=["str", "str"],
410
- row_count=(1, "dynamic"),
411
- col_count=(2, "fixed"),
412
- )
413
- examples_output_dataframe = gr.DataFrame(
414
- label="Examples",
415
- headers=["Input", "Output"],
416
- interactive=False,
417
- datatype=["str", "str"],
418
- row_count=(1, "dynamic"),
419
- col_count=(2, "fixed"),
420
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
421
 
422
  clear_button = gr.ClearButton(
423
  [
424
  input_dataframe,
425
  description_output,
 
 
426
  input_analysis_output,
427
  example_briefs_output,
428
  examples_from_briefs_output_dataframe,
@@ -453,6 +493,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
453
  ],
454
  outputs=[
455
  description_output,
 
456
  examples_directly_output_dataframe,
457
  input_analysis_output,
458
  example_briefs_output,
@@ -464,7 +505,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
464
  generate_description_button.click(
465
  fn=generate_description,
466
  inputs=[input_dataframe, model_name, temperature],
467
- outputs=[description_output],
468
  )
469
 
470
  generate_examples_directly_button.click(
@@ -590,5 +631,17 @@ with gr.Blocks(title="Task Description Generator") as demo:
590
  ],
591
  )
592
 
 
 
 
 
 
 
 
 
 
 
 
 
593
  if __name__ == "__main__":
594
  demo.launch()
 
38
  [example["input"], example["output"]]
39
  for example in result["additional_examples"]
40
  ]
41
+ suggestions = result.get("suggestions", [])
42
  return (
43
  description,
44
+ gr.update(choices=suggestions, value=[]),
45
  examples_directly,
46
  input_analysis,
47
  new_example_briefs,
 
57
 
58
  model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
59
  generator = TaskDescriptionGenerator(model)
60
+ result = generator.generate_description(input_json)
61
+ description = result["description"]
62
+ suggestions = result["suggestions"]
63
+ return description, gr.update(choices=suggestions, value=[])
64
  except Exception as e:
65
  raise gr.Error(f"An error occurred: {str(e)}")
66
 
 
215
  selected_group_output,
216
  )
217
 
218
+ def generate_suggestions(description, examples, model_name, temperature):
219
+ try:
220
+ input_json = convert_examples_to_json(examples)
221
+ model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
222
+ generator = TaskDescriptionGenerator(model)
223
+ result = generator.generate_suggestions(input_json, description)
224
+ return gr.update(choices=result["suggestions"])
225
+ except Exception as e:
226
+ raise gr.Error(f"An error occurred: {str(e)}")
227
+
228
+ def apply_suggestions(description, suggestions, examples, model_name, temperature):
229
+ try:
230
+ input_json = convert_examples_to_json(examples)
231
+ model = ChatOpenAI(model=model_name, temperature=temperature, max_retries=3)
232
+ generator = TaskDescriptionGenerator(model)
233
+ result = generator.update_description(input_json, description, suggestions)
234
+ return result["description"]
235
+ except Exception as e:
236
+ raise gr.Error(f"An error occurred: {str(e)}")
237
+
238
+ with gr.Blocks(title="Meta Prompt") as demo:
239
+ gr.Markdown("# Scope")
240
 
241
  input_dataframe = gr.DataFrame(
242
  label="Input Examples",
 
290
  update_row_button = gr.Button(
291
  "Update Selected Row", variant="secondary"
292
  )
293
+ close_button = gr.Button("Close", variant="secondary")
294
 
295
  delete_row_button.click(
296
  fn=delete_selected_dataframe_row,
 
338
  append_example_button = gr.Button(
339
  "Append to Input Examples", variant="secondary"
340
  )
341
+ close_button = gr.Button("Close", variant="secondary")
342
+
343
  append_example_button.click(
344
  fn=append_example_to_input_dataframe,
345
  inputs=[
 
356
  ],
357
  )
358
 
 
 
359
  close_button.click(
360
  fn=lambda: None,
361
  inputs=[],
362
  outputs=[selected_group_mode],
363
  )
364
 
 
 
365
  with gr.Accordion("Import/Export JSON", open=False):
366
  json_file_object = gr.File(
367
  label="Import/Export JSON", file_types=[".json"], type="filepath"
368
  )
369
  export_button = gr.Button("Export to JSON")
370
 
371
+ with gr.Group():
372
+ submit_button = gr.Button("Generate", variant="primary")
373
+
374
+ examples_output_dataframe = gr.DataFrame(
375
+ # label="Examples",
376
+ headers=["Input", "Output"],
377
+ interactive=False,
378
+ datatype=["str", "str"],
379
+ row_count=(1, "dynamic"),
380
+ col_count=(2, "fixed"),
381
+ )
382
+
383
  with gr.Accordion("Model Settings", open=False):
384
  model_name = gr.Dropdown(
385
  label="Model Name",
 
400
  )
401
 
402
  with gr.Accordion("Analysis", open=False):
 
 
 
 
 
 
403
  with gr.Row():
404
+ with gr.Column():
405
+ generate_description_button = gr.Button(
406
+ "Generate Description", variant="secondary"
407
+ )
408
+ description_output = gr.Textbox(
409
+ label="Description", lines=5, show_copy_button=True
410
+ )
411
+ with gr.Column():
412
+ # Suggestions components
413
+ generate_suggestions_button = gr.Button("Generate Suggestions", variant="secondary")
414
+ suggestions_output = gr.Dropdown(label="Suggestions", choices=[], multiselect=True, allow_custom_value=True)
415
+ apply_suggestions_button = gr.Button("Apply Suggestions", variant="secondary")
416
+
417
+ with gr.Row():
418
+ with gr.Column():
419
+ analyze_input_button = gr.Button(
420
+ "Analyze Input", variant="secondary"
421
+ )
422
+ input_analysis_output = gr.Textbox(
423
+ label="Input Analysis", lines=5, show_copy_button=True
424
+ )
425
+ with gr.Column():
426
+ generate_briefs_button = gr.Button(
427
+ "Generate Briefs", variant="secondary"
428
+ )
429
+ example_briefs_output = gr.Textbox(
430
+ label="Example Briefs", lines=5, show_copy_button=True
431
+ )
432
+
433
+ with gr.Row():
434
+ with gr.Column():
435
+ generate_examples_directly_button = gr.Button(
436
+ "Generate Examples Directly", variant="secondary"
437
+ )
438
+ examples_directly_output_dataframe = gr.DataFrame(
439
+ label="Examples Directly",
440
+ headers=["Input", "Output"],
441
+ interactive=False,
442
+ datatype=["str", "str"],
443
+ row_count=(1, "dynamic"),
444
+ col_count=(2, "fixed"),
445
+ )
446
+
447
+ with gr.Column():
448
+ generate_examples_from_briefs_button = gr.Button(
449
+ "Generate Examples from Briefs", variant="secondary"
450
+ )
451
+ examples_from_briefs_output_dataframe = gr.DataFrame(
452
+ label="Examples from Briefs",
453
+ headers=["Input", "Output"],
454
+ interactive=False,
455
+ datatype=["str", "str"],
456
+ row_count=(1, "dynamic"),
457
+ col_count=(2, "fixed"),
458
+ )
459
 
460
  clear_button = gr.ClearButton(
461
  [
462
  input_dataframe,
463
  description_output,
464
+ suggestions_output,
465
+ examples_directly_output_dataframe,
466
  input_analysis_output,
467
  example_briefs_output,
468
  examples_from_briefs_output_dataframe,
 
493
  ],
494
  outputs=[
495
  description_output,
496
+ suggestions_output,
497
  examples_directly_output_dataframe,
498
  input_analysis_output,
499
  example_briefs_output,
 
505
  generate_description_button.click(
506
  fn=generate_description,
507
  inputs=[input_dataframe, model_name, temperature],
508
+ outputs=[description_output, suggestions_output],
509
  )
510
 
511
  generate_examples_directly_button.click(
 
631
  ],
632
  )
633
 
634
+ generate_suggestions_button.click(
635
+ fn=generate_suggestions,
636
+ inputs=[description_output, input_dataframe, model_name, temperature],
637
+ outputs=[suggestions_output],
638
+ )
639
+
640
+ apply_suggestions_button.click(
641
+ fn=apply_suggestions,
642
+ inputs=[description_output, suggestions_output, input_dataframe, model_name, temperature],
643
+ outputs=[description_output],
644
+ )
645
+
646
  if __name__ == "__main__":
647
  demo.launch()