Spaces:
Running
on
T4
Running
on
T4
change report selection
Browse files
app.py
CHANGED
|
@@ -362,28 +362,123 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
| 362 |
with gr.Tab("Reports",elem_id = "tab-config",id = 2):
|
| 363 |
gr.Markdown("Reminder: To get better results select the specific report/reports")
|
| 364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
#----- First level filter for selecting Report source/category ----------
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
#------ second level filter for selecting subtype within the report category selected above
|
| 375 |
-
dropdown_category = gr.Dropdown(
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
|
| 382 |
#----------- update the secodn level filter abse don values from first level ----------------
|
| 383 |
def rs_change(rs):
|
| 384 |
return gr.update(choices=new_files[rs], value=new_files[rs])
|
| 385 |
dropdown_sources.change(fn=rs_change, inputs=[dropdown_sources], outputs=[dropdown_category])
|
| 386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
#--------- Select the years for reports -------------------------------------
|
| 388 |
#dropdown_year = gr.Dropdown(
|
| 389 |
# ['2018','2019','2020','2021','2022','2023'],
|
|
@@ -392,14 +487,14 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
| 392 |
# value=['2023'],
|
| 393 |
# interactive=True,
|
| 394 |
#)
|
| 395 |
-
gr.Markdown("-------------------------------------------------------------------------")
|
| 396 |
#---------------- Another way to select reports across category and sub-type ------------
|
| 397 |
-
dropdown_reports = gr.Dropdown(
|
| 398 |
-
new_report_list,
|
| 399 |
-
label="Or select specific reports",
|
| 400 |
-
multiselect=True,
|
| 401 |
-
value=[],
|
| 402 |
-
interactive=True,)
|
| 403 |
|
| 404 |
############### tab for Question selection ###############
|
| 405 |
with gr.TabItem("Examples",elem_id = "tab-examples",id = 0):
|
|
|
|
| 362 |
with gr.Tab("Reports",elem_id = "tab-config",id = 2):
|
| 363 |
gr.Markdown("Reminder: To get better results select the specific report/reports")
|
| 364 |
|
| 365 |
+
#---------------- SELECTION METHOD - RADIO BUTTON ------------
|
| 366 |
+
search_method = gr.Radio(
|
| 367 |
+
choices=["Search by Report Name", "Search by Filters"],
|
| 368 |
+
label="""Choose search method <div class="question-tooltip">?
|
| 369 |
+
<div class="tooltip-content">Select the audit reports that you want to analyse directly or browse through categories and select reports</div>
|
| 370 |
+
</div>""",
|
| 371 |
+
info= """This is test"""
|
| 372 |
+
value="Search by Report Name",
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
#---------------- SELECT BY REPORT NAME SECTION ------------
|
| 376 |
+
with gr.Group(visible=True) as report_name_section:
|
| 377 |
+
# Get default report value from config if present
|
| 378 |
+
default_report = model_config.get('app', 'dropdown_default', fallback=None)
|
| 379 |
+
# Check if it actually exists in the master list
|
| 380 |
+
default_report_value = [default_report] if default_report in new_report_list else None
|
| 381 |
+
|
| 382 |
+
dropdown_reports = gr.Dropdown(
|
| 383 |
+
new_report_list,
|
| 384 |
+
label="Select one or more reports (scroll or type to search)",
|
| 385 |
+
multiselect=True,
|
| 386 |
+
value=default_report_value,
|
| 387 |
+
interactive=True,
|
| 388 |
+
)
|
| 389 |
|
| 390 |
#----- First level filter for selecting Report source/category ----------
|
| 391 |
+
|
| 392 |
+
#with gr.Group(visible=True) as report_name_section:
|
| 393 |
+
# # Get default report value from config if present
|
| 394 |
+
# default_report = model_config.get('app', 'dropdown_default', fallback=None)
|
| 395 |
+
# # Check if it actually exists in the master list
|
| 396 |
+
# default_report_value = [default_report] if default_report in new_report_list else None
|
| 397 |
+
#
|
| 398 |
+
# dropdown_reports = gr.Dropdown(
|
| 399 |
+
# new_report_list,
|
| 400 |
+
# label="Select one or more reports (scroll or type to search)",
|
| 401 |
+
# multiselect=True,
|
| 402 |
+
# value=default_report_value,
|
| 403 |
+
# interactive=True,
|
| 404 |
+
# )
|
| 405 |
+
|
| 406 |
+
#---------------- SELECT BY FILTERS SECTION ------------
|
| 407 |
+
with gr.Group(visible=False) as filters_section:
|
| 408 |
+
#----- First level filter for selecting Report source/category ----------
|
| 409 |
+
dropdown_sources = gr.Dropdown(
|
| 410 |
+
["Consolidated","Ministry, Department, Agency and Projects","Local Government","Value for Money","Thematic"],
|
| 411 |
+
label="Select Report Category",
|
| 412 |
+
value=None,
|
| 413 |
+
interactive=True,
|
| 414 |
+
)
|
| 415 |
+
|
| 416 |
+
#------ second level filter for selecting subtype within the report category selected above
|
| 417 |
+
dropdown_category = gr.Dropdown(
|
| 418 |
+
[], # Start with empty choices
|
| 419 |
+
value=None,
|
| 420 |
+
label = "Filter for Sub-Type",
|
| 421 |
+
interactive=True)
|
| 422 |
+
|
| 423 |
+
#dropdown_sources = gr.Dropdown(
|
| 424 |
+
# ["Consolidated","Ministry, Department and Agency","Project","Hospital","Local Government","Value for Money","Thematic"],
|
| 425 |
+
# label="Select Report Category",
|
| 426 |
+
# value="Consolidated",
|
| 427 |
+
# interactive=True,
|
| 428 |
+
#)
|
| 429 |
|
| 430 |
#------ second level filter for selecting subtype within the report category selected above
|
| 431 |
+
#dropdown_category = gr.Dropdown(
|
| 432 |
+
# new_files["Consolidated"],
|
| 433 |
+
# multiselect = True,
|
| 434 |
+
# value = new_files["Consolidated"][0],
|
| 435 |
+
# label = "Filter for Sub-reports",
|
| 436 |
+
# interactive=True)
|
| 437 |
|
| 438 |
#----------- update the secodn level filter abse don values from first level ----------------
|
| 439 |
def rs_change(rs):
|
| 440 |
return gr.update(choices=new_files[rs], value=new_files[rs])
|
| 441 |
dropdown_sources.change(fn=rs_change, inputs=[dropdown_sources], outputs=[dropdown_category])
|
| 442 |
|
| 443 |
+
|
| 444 |
+
# Toggle visibility based on search method
|
| 445 |
+
def toggle_search_method(method):
|
| 446 |
+
"""Note - this function removes the default value from report search when toggled"""
|
| 447 |
+
if method == "Search by Report Name":
|
| 448 |
+
# Show report selection, hide filters, and clear filter values
|
| 449 |
+
return (
|
| 450 |
+
gr.update(visible=True), # report_name_section
|
| 451 |
+
gr.update(visible=False), # filters_section
|
| 452 |
+
gr.update(value=None), # dropdown_sources
|
| 453 |
+
gr.update(value=None), # dropdown_category
|
| 454 |
+
gr.update(value=None), # dropdown_year
|
| 455 |
+
gr.update() # dropdown_reports
|
| 456 |
+
)
|
| 457 |
+
else: # "Search by Filters"
|
| 458 |
+
# Show filters, hide report selection, and clear report values
|
| 459 |
+
return (
|
| 460 |
+
gr.update(visible=False), # report_name_section
|
| 461 |
+
gr.update(visible=True), # filters_section
|
| 462 |
+
gr.update(), # dropdown_sources
|
| 463 |
+
gr.update(), # dropdown_category
|
| 464 |
+
gr.update(), # dropdown_year
|
| 465 |
+
gr.update(value=[]) # dropdown_reports
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
# Pass to the event handler
|
| 469 |
+
search_method.change(
|
| 470 |
+
fn=toggle_search_method,
|
| 471 |
+
inputs=[search_method],
|
| 472 |
+
outputs=[
|
| 473 |
+
report_name_section,
|
| 474 |
+
filters_section,
|
| 475 |
+
dropdown_sources,
|
| 476 |
+
dropdown_category,
|
| 477 |
+
dropdown_year,
|
| 478 |
+
dropdown_reports
|
| 479 |
+
]
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
#--------- Select the years for reports -------------------------------------
|
| 483 |
#dropdown_year = gr.Dropdown(
|
| 484 |
# ['2018','2019','2020','2021','2022','2023'],
|
|
|
|
| 487 |
# value=['2023'],
|
| 488 |
# interactive=True,
|
| 489 |
#)
|
| 490 |
+
#gr.Markdown("-------------------------------------------------------------------------")
|
| 491 |
#---------------- Another way to select reports across category and sub-type ------------
|
| 492 |
+
#dropdown_reports = gr.Dropdown(
|
| 493 |
+
#new_report_list,
|
| 494 |
+
#label="Or select specific reports",
|
| 495 |
+
#multiselect=True,
|
| 496 |
+
#value=[],
|
| 497 |
+
#interactive=True,)
|
| 498 |
|
| 499 |
############### tab for Question selection ###############
|
| 500 |
with gr.TabItem("Examples",elem_id = "tab-examples",id = 0):
|