Spaces:
Sleeping
Sleeping
Ajaykanth Maddi commited on
Commit Β·
e17ca12
1
Parent(s): d1ff209
Code Changes - Advanced Options
Browse files- app.py +53 -5
- ragbench.py +3 -3
app.py
CHANGED
|
@@ -158,6 +158,47 @@ def plot_chunking_strategies(subset_name):
|
|
| 158 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 159 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
def generate_file(subset_dropdown, dataset_type_dropdown,
|
| 162 |
chunking_dropdown, embed_dropdown, retriever_dropdown,
|
| 163 |
chunk_count, retriever_type,
|
|
@@ -474,7 +515,7 @@ with gr.Blocks(
|
|
| 474 |
|
| 475 |
with gr.Row():
|
| 476 |
# Add export button
|
| 477 |
-
with gr.Column(scale=
|
| 478 |
with gr.Accordion("Advanced Options", open=False):
|
| 479 |
noOfQuestions = gr.Slider(
|
| 480 |
minimum=1,
|
|
@@ -486,6 +527,9 @@ with gr.Blocks(
|
|
| 486 |
|
| 487 |
# Create button with initial label
|
| 488 |
evaluate_btn = gr.Button("π Run RAG Evaluation for 5 Questions", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 489 |
|
| 490 |
# Function to update button label
|
| 491 |
def update_button_label(value):
|
|
@@ -509,13 +553,14 @@ with gr.Blocks(
|
|
| 509 |
outputs=[evaluator_json_output]
|
| 510 |
)
|
| 511 |
|
|
|
|
|
|
|
| 512 |
generate_btn = gr.Button("Generate JSON & Download")
|
| 513 |
with gr.Column(scale=2):
|
| 514 |
json_output = gr.Code(label="JSON Output", max_lines=50, language="json")
|
| 515 |
download_file = gr.File(label="Download Link")
|
| 516 |
|
| 517 |
|
| 518 |
-
|
| 519 |
submit_btn.click(
|
| 520 |
fn=run_rag_pipeline,
|
| 521 |
inputs=[
|
|
@@ -527,8 +572,6 @@ with gr.Blocks(
|
|
| 527 |
outputs=[gen_ans_display, y_pred_metrics_display, chunks_retrieved_display, evaluator_json_output, download_file]
|
| 528 |
)
|
| 529 |
|
| 530 |
-
|
| 531 |
-
|
| 532 |
generate_btn.click(
|
| 533 |
fn=generate_file,
|
| 534 |
inputs=[subset_dropdown, dataset_type_dropdown,
|
|
@@ -543,5 +586,10 @@ with gr.Blocks(
|
|
| 543 |
outputs=[json_output, download_file]
|
| 544 |
)
|
| 545 |
|
| 546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
demo.launch(debug=True, prevent_thread_lock=True, share=True)
|
|
|
|
| 158 |
initial_subset = available_subsets[0] if available_subsets else None
|
| 159 |
initial_plot = plot_subset_metrics(initial_subset) if initial_subset else "No data available"
|
| 160 |
|
| 161 |
+
|
| 162 |
+
def generate_advance_report(subset_dropdown, dataset_type_dropdown, chunking_dropdown, embed_dropdown, retriever_dropdown,
|
| 163 |
+
chunk_count, retriever_type,
|
| 164 |
+
reranking_checkbox, evaluator_dropdown)
|
| 165 |
+
|
| 166 |
+
export_data = {
|
| 167 |
+
"metadata": {
|
| 168 |
+
"timestamp": datetime.datetime.now().isoformat(),
|
| 169 |
+
"format_version": "1.0"
|
| 170 |
+
},
|
| 171 |
+
"subset": {
|
| 172 |
+
"subset": subset_dropdown,
|
| 173 |
+
"dataset_type": dataset_type_dropdown,
|
| 174 |
+
},
|
| 175 |
+
"model_details": {
|
| 176 |
+
"strategy": chunking_dropdown,
|
| 177 |
+
"embed_model": embed_dropdown,
|
| 178 |
+
"generator_model": retriever_dropdown,
|
| 179 |
+
"chunk_count": chunk_count,
|
| 180 |
+
"noOfQuestions": noOfQuestions,
|
| 181 |
+
"retriever_type": retriever_type,
|
| 182 |
+
"reranking": reranking_checkbox,
|
| 183 |
+
"evaluator_model": evaluator_dropdown
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
export_data["questions"] = []
|
| 188 |
+
# for sq in advanced_analysis[subset_dropdown][QUESTIONS]:
|
| 189 |
+
# export['questions'].append(
|
| 190 |
+
|
| 191 |
+
# Step 2: Convert to JSON string for display
|
| 192 |
+
json_str = json.dumps(export_data, indent=2)
|
| 193 |
+
|
| 194 |
+
fileName = f"{subset_dropdown}_{chunking_dropdown}_{embed_dropdown}_output_{datetime.datetime.now().strftime('%d-%B-%Y-%H-%M-%S')}.json"
|
| 195 |
+
# Save to file inside Space
|
| 196 |
+
with open(fileName, "w") as f:
|
| 197 |
+
f.write(json_str)
|
| 198 |
+
|
| 199 |
+
return json_str, fileName
|
| 200 |
+
|
| 201 |
+
|
| 202 |
def generate_file(subset_dropdown, dataset_type_dropdown,
|
| 203 |
chunking_dropdown, embed_dropdown, retriever_dropdown,
|
| 204 |
chunk_count, retriever_type,
|
|
|
|
| 515 |
|
| 516 |
with gr.Row():
|
| 517 |
# Add export button
|
| 518 |
+
with gr.Column(scale=3):
|
| 519 |
with gr.Accordion("Advanced Options", open=False):
|
| 520 |
noOfQuestions = gr.Slider(
|
| 521 |
minimum=1,
|
|
|
|
| 527 |
|
| 528 |
# Create button with initial label
|
| 529 |
evaluate_btn = gr.Button("π Run RAG Evaluation for 5 Questions", variant="primary")
|
| 530 |
+
|
| 531 |
+
# Create button with initial label
|
| 532 |
+
evaluate_report = gr.Button("π Generated report", variant="primary")
|
| 533 |
|
| 534 |
# Function to update button label
|
| 535 |
def update_button_label(value):
|
|
|
|
| 553 |
outputs=[evaluator_json_output]
|
| 554 |
)
|
| 555 |
|
| 556 |
+
|
| 557 |
+
|
| 558 |
generate_btn = gr.Button("Generate JSON & Download")
|
| 559 |
with gr.Column(scale=2):
|
| 560 |
json_output = gr.Code(label="JSON Output", max_lines=50, language="json")
|
| 561 |
download_file = gr.File(label="Download Link")
|
| 562 |
|
| 563 |
|
|
|
|
| 564 |
submit_btn.click(
|
| 565 |
fn=run_rag_pipeline,
|
| 566 |
inputs=[
|
|
|
|
| 572 |
outputs=[gen_ans_display, y_pred_metrics_display, chunks_retrieved_display, evaluator_json_output, download_file]
|
| 573 |
)
|
| 574 |
|
|
|
|
|
|
|
| 575 |
generate_btn.click(
|
| 576 |
fn=generate_file,
|
| 577 |
inputs=[subset_dropdown, dataset_type_dropdown,
|
|
|
|
| 586 |
outputs=[json_output, download_file]
|
| 587 |
)
|
| 588 |
|
| 589 |
+
evaluate_report.click(
|
| 590 |
+
fn=generate_file,
|
| 591 |
+
inputs=[
|
| 592 |
+
],
|
| 593 |
+
outputs=[json_output, download_file]
|
| 594 |
+
)
|
| 595 |
demo.launch(debug=True, prevent_thread_lock=True, share=True)
|
ragbench.py
CHANGED
|
@@ -138,9 +138,9 @@ class RAGSystem:
|
|
| 138 |
repo_type=HF_REPO_TYPE,
|
| 139 |
)
|
| 140 |
|
| 141 |
-
print(f"Repository {HF_DATASET_REPO_NAME} is accessible. Files:")
|
| 142 |
-
for index, item in enumerate(repo_files):
|
| 143 |
-
|
| 144 |
|
| 145 |
except Exception as e:
|
| 146 |
print(f"Error accessing Hugging Face repo: {e}")
|
|
|
|
| 138 |
repo_type=HF_REPO_TYPE,
|
| 139 |
)
|
| 140 |
|
| 141 |
+
print(f"Repository {HF_DATASET_REPO_NAME} is accessible. No of Files: {len(repo_files)}")
|
| 142 |
+
# for index, item in enumerate(repo_files):
|
| 143 |
+
# print(f"Index, {index}, File: {item}")
|
| 144 |
|
| 145 |
except Exception as e:
|
| 146 |
print(f"Error accessing Hugging Face repo: {e}")
|