Ajaykanth Maddi commited on
Commit ·
8238aba
1
Parent(s): c27e646
Export Button UI Changes
Browse files
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
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 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 |
-
|
| 324 |
-
with gr.Blocks(
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 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("
|
| 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=
|
| 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=
|
| 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)
|