Ajaykanth Maddi commited on
Commit
920bfb0
·
1 Parent(s): 53f4e1e

Export Button UI Changes

Browse files
Files changed (1) hide show
  1. app.py +20 -7
app.py CHANGED
@@ -179,11 +179,23 @@ initial_subset = available_subsets[0] if available_subsets else None
179
  # initial_summary = update_summary(initial_subset) if initial_subset else "No data available"
180
  initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
181
 
182
- def generate_file(text):
 
 
 
 
 
 
 
 
 
 
 
 
183
  # Save to file inside Space
184
- with open("output.txt", "w") as f:
185
- f.write(text)
186
- return "output.txt"
187
 
188
  def export_data(orig_ans_display,
189
  y_metrics_display,
@@ -401,12 +413,13 @@ with gr.Blocks(
401
  with gr.Column(scale=2):
402
  # Add export button
403
  # gr.Interface(fn=generate_file, inputs=orig_ans_display, outputs="file")
404
- generate_btn = gr.Button("Generate & Download")
 
405
  download_file = gr.File(label="Download Link")
406
  generate_btn.click(
407
  fn=generate_file,
408
- inputs=gen_ans_display,
409
- outputs=download_file
410
  )
411
 
412
  # export_btn = gr.Button("💾 Export Locally", variant="primary")
 
179
  # initial_summary = update_summary(initial_subset) if initial_subset else "No data available"
180
  initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
181
 
182
+ def generate_file(subset, text):
183
+ """Generate a file with the given text and return the file path."""
184
+
185
+ data = {
186
+ "subset": subset,
187
+ "text": text,
188
+ "timestamp": datetime.datetime.now().isoformat()
189
+ }
190
+
191
+ # Step 2: Convert to JSON string for display
192
+ json_str = json.dumps(data, indent=2)
193
+
194
+ fileName = "output_json.json"
195
  # Save to file inside Space
196
+ with open(fileName, "w") as f:
197
+ f.write(json_str)
198
+ return json_str, fileName
199
 
200
  def export_data(orig_ans_display,
201
  y_metrics_display,
 
413
  with gr.Column(scale=2):
414
  # Add export button
415
  # gr.Interface(fn=generate_file, inputs=orig_ans_display, outputs="file")
416
+ generate_btn = gr.Button("Generate JSON & Download")
417
+ json_output = gr.Code(label="JSON Output", language="json")
418
  download_file = gr.File(label="Download Link")
419
  generate_btn.click(
420
  fn=generate_file,
421
+ inputs=[subset_dropdown, gen_ans_display],
422
+ outputs=[json_output, download_file]
423
  )
424
 
425
  # export_btn = gr.Button("💾 Export Locally", variant="primary")