yaleh commited on
Commit
18d102a
·
1 Parent(s): a7dd734

Append new samples.

Browse files
Files changed (1) hide show
  1. app/gradio_sample_generator.py +18 -0
app/gradio_sample_generator.py CHANGED
@@ -160,6 +160,17 @@ def export_json(df):
160
  return temp_file_path
161
  return None
162
 
 
 
 
 
 
 
 
 
 
 
 
163
  with gr.Blocks(title="Task Description Generator") as demo:
164
  gr.Markdown("# Task Description Generator")
165
  gr.Markdown(
@@ -252,6 +263,7 @@ with gr.Blocks(title="Task Description Generator") as demo:
252
  new_example_json = gr.Textbox(
253
  label="New Example JSON", lines=5, show_copy_button=True
254
  )
 
255
 
256
  clear_button = gr.ClearButton(
257
  [
@@ -381,5 +393,11 @@ with gr.Blocks(title="Task Description Generator") as demo:
381
  outputs=[],
382
  )
383
 
 
 
 
 
 
 
384
  if __name__ == "__main__":
385
  demo.launch()
 
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")
176
  gr.Markdown(
 
263
  new_example_json = gr.Textbox(
264
  label="New Example JSON", lines=5, show_copy_button=True
265
  )
266
+ append_example_button = gr.Button("Append to Input Examples", variant="secondary")
267
 
268
  clear_button = gr.ClearButton(
269
  [
 
393
  outputs=[],
394
  )
395
 
396
+ append_example_button.click(
397
+ fn=append_example_to_input,
398
+ inputs=[new_example_json, input_df],
399
+ outputs=[input_df],
400
+ )
401
+
402
  if __name__ == "__main__":
403
  demo.launch()