Ajaykanth Maddi commited on
Commit
8238aba
·
1 Parent(s): c27e646

Export Button UI Changes

Browse files
Files changed (1) hide show
  1. app.py +48 -63
app.py CHANGED
@@ -180,55 +180,46 @@ initial_subset = available_subsets[0] if available_subsets else None
180
  initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
181
 
182
 
183
- def export_to_file(
184
- # Component values
185
- orig_answer, orig_metrics, gen_answer, pred_metrics, chunks, analysis,
186
- # Pipeline parameters
187
- subset, dataset_type, chunking_strategy, embedding_model,
188
- retriever_type, reranking, evaluator
189
- ):
190
- print("Export function triggered!") # Check console for this
191
- # print(f"Received {len(args)} arguments") # Verify input count
192
-
193
- # Create metadata header
194
- timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
195
- export_content = f"""=== RAG Pipeline Export ({timestamp}) ===
196
-
197
- === PIPELINE CONFIGURATION ===
198
- Subset: {subset}
199
- Dataset Type: {dataset_type}
200
- Chunking Strategy: {chunking_strategy}
201
- Embedding Model: {embedding_model}
202
- Retriever Type: {retriever_type}
203
- Reranking Enabled: {reranking}
204
- Evaluator: {evaluator}
205
-
206
- === RESULTS ===
207
- ORIGINAL ANSWER:
208
- {orig_answer}
209
-
210
- ORIGINAL METRICS:
211
- {json.dumps(orig_metrics, indent=2)}
212
-
213
- GENERATED ANSWER:
214
- {gen_answer}
215
-
216
- PREDICTION METRICS:
217
- {json.dumps(pred_metrics, indent=2)}
218
-
219
- RETRIEVED CHUNKS:
220
- {chunks}
221
-
222
- ANALYSIS RESULTS:
223
- {json.dumps(analysis, indent=2)}
224
- """
225
-
226
- # Create filename with timestamp
227
- filename = f"rag_export_{timestamp.replace(' ', '_').replace(':', '')}.txt"
228
- with open(filename, "w") as f:
229
- f.write(export_content)
230
-
231
- return filename
232
 
233
  def run_rag_pipeline(subset, question, custom_question, chunking, embed_model, retriever, chunk_count, retriever_type,
234
  reranking, evaluator):
@@ -320,11 +311,11 @@ def run_rag_pipeline(subset, question, custom_question, chunking, embed_model, r
320
 
321
 
322
  # UI Layout
323
- # with gr.Blocks(title="RAGBench Explorer") as demo:
324
- with gr.Blocks(
325
- head="<!DOCTYPE html>",
326
- css=":root { -webkit-print-color-adjust: exact; }") as demo:
327
- demo.title = "RAGBench Interactive Explorer"
328
  gr.Markdown("## 🔍 RAGBench Interactive Explorer")
329
 
330
  with gr.Row():
@@ -408,22 +399,16 @@ with gr.Blocks(
408
  )
409
 
410
  # Add export button
411
- export_btn = gr.Button("📤 Export All Data", variant="secondary")
412
- export_file = gr.File(label="Export File", visible=False)
413
-
414
- # Export handler
415
- # Export handler with ALL parameters
416
  export_btn.click(
417
- fn=export_to_file,
418
  inputs=[
419
- # Component values
420
  orig_ans_display,
421
  y_metrics_display,
422
  gen_ans_display,
423
  y_pred_metrics_display,
424
  chunks_retrieved_display,
425
  evaluator_json_output,
426
- # Pipeline parameters (add your actual components here)
427
  subset_dropdown,
428
  dataset_type_dropdown,
429
  chunking_dropdown,
@@ -432,7 +417,7 @@ with gr.Blocks(
432
  reranking_checkbox,
433
  evaluator_dropdown
434
  ],
435
- outputs=export_file
436
  )
437
 
438
  demo.launch(debug=True, prevent_thread_lock=True, share=True)
 
180
  initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
181
 
182
 
183
+ def export_data(*components):
184
+ """Local file export function that avoids cloud dependencies"""
185
+ try:
186
+ # Create timestamped filename
187
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
188
+ filename = f"rag_export_{timestamp}.json"
189
+
190
+ # Prepare structured data
191
+ export_data = {
192
+ "metadata": {
193
+ "export_time": timestamp,
194
+ "format_version": "1.0"
195
+ },
196
+ "content": {
197
+ "original_answer": components[0],
198
+ "original_metrics": components[1],
199
+ "generated_answer": components[2],
200
+ "prediction_metrics": components[3],
201
+ "retrieved_chunks": components[4],
202
+ "analysis_results": components[5],
203
+ "parameters": {
204
+ "subset": components[6],
205
+ "dataset_type": components[7],
206
+ "chunking_strategy": components[8],
207
+ "embedding_model": components[9],
208
+ "retriever_type": components[10],
209
+ "reranking": components[11],
210
+ "evaluator": components[12]
211
+ }
212
+ }
213
+ }
214
+
215
+ # Save to local JSON file
216
+ with open(filename, 'w', encoding='utf-8') as f:
217
+ json.dump(export_data, f, indent=2)
218
+
219
+ return filename
220
+
221
+ except Exception as e:
222
+ raise gr.Error(f"Local export failed: {str(e)}")
 
 
 
 
 
 
 
 
 
223
 
224
  def run_rag_pipeline(subset, question, custom_question, chunking, embed_model, retriever, chunk_count, retriever_type,
225
  reranking, evaluator):
 
311
 
312
 
313
  # UI Layout
314
+ with gr.Blocks(title="RAGBench Explorer") as demo:
315
+ # with gr.Blocks(
316
+ # head="<!DOCTYPE html>",
317
+ # css=":root { -webkit-print-color-adjust: exact; }") as demo:
318
+ # demo.title = "RAGBench Interactive Explorer"
319
  gr.Markdown("## 🔍 RAGBench Interactive Explorer")
320
 
321
  with gr.Row():
 
399
  )
400
 
401
  # Add export button
402
+ export_btn = gr.Button("💾 Export Locally", variant="primary")
 
 
 
 
403
  export_btn.click(
404
+ fn=export_data,
405
  inputs=[
 
406
  orig_ans_display,
407
  y_metrics_display,
408
  gen_ans_display,
409
  y_pred_metrics_display,
410
  chunks_retrieved_display,
411
  evaluator_json_output,
 
412
  subset_dropdown,
413
  dataset_type_dropdown,
414
  chunking_dropdown,
 
417
  reranking_checkbox,
418
  evaluator_dropdown
419
  ],
420
+ outputs=gr.File(label="Download will start automatically", visible=False)
421
  )
422
 
423
  demo.launch(debug=True, prevent_thread_lock=True, share=True)