Spaces:
Sleeping
Sleeping
Dropdown selection logic refactor
Browse files- app.py +91 -38
- model_params.cfg +1 -0
- style.css +3 -0
app.py
CHANGED
|
@@ -414,48 +414,100 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
| 414 |
gr.Markdown("""<div class="question-tooltip">?
|
| 415 |
<div class="tooltip-content">Select the audit reports that you want to analyse directly or browse through categories and select reports</div>
|
| 416 |
</div>""", elem_id="reports-tooltip")
|
| 417 |
-
|
| 418 |
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
["
|
| 422 |
-
label="
|
| 423 |
-
value=
|
| 424 |
-
# value="Consolidated",
|
| 425 |
-
interactive=True,
|
| 426 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
)
|
| 450 |
-
gr.Markdown("-------------------------------------------------------------------------")
|
| 451 |
-
#---------------- Another way to select reports across category and sub-type ------------
|
| 452 |
-
dropdown_reports = gr.Dropdown(
|
| 453 |
-
new_report_list,
|
| 454 |
-
label="Or select specific reports",
|
| 455 |
-
multiselect=True,
|
| 456 |
-
value=None,
|
| 457 |
-
# value=[],
|
| 458 |
-
interactive=True,)
|
| 459 |
|
| 460 |
############### tab for Question selection ###############
|
| 461 |
with gr.TabItem("Examples",elem_id = "tab-examples",id = 0):
|
|
@@ -875,6 +927,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
|
|
| 875 |
[textbox]
|
| 876 |
)
|
| 877 |
|
|
|
|
| 878 |
cancel_btn.click(
|
| 879 |
lambda: (
|
| 880 |
None, # reset check status
|
|
|
|
| 414 |
gr.Markdown("""<div class="question-tooltip">?
|
| 415 |
<div class="tooltip-content">Select the audit reports that you want to analyse directly or browse through categories and select reports</div>
|
| 416 |
</div>""", elem_id="reports-tooltip")
|
|
|
|
| 417 |
|
| 418 |
+
#---------------- SELECTION METHOD - RADIO BUTTON ------------
|
| 419 |
+
search_method = gr.Radio(
|
| 420 |
+
choices=["Search by Report Name", "Search by Filters"],
|
| 421 |
+
label="Choose search method",
|
| 422 |
+
value="Search by Report Name",
|
|
|
|
|
|
|
| 423 |
)
|
| 424 |
+
|
| 425 |
+
#---------------- SELECT BY REPORT NAME SECTION ------------
|
| 426 |
+
with gr.Group(visible=True) as report_name_section:
|
| 427 |
+
# Get default report value from config if present
|
| 428 |
+
default_report = model_config.get('app', 'dropdown_default', fallback=None)
|
| 429 |
+
# Check if it actually exists in the master list
|
| 430 |
+
default_report_value = [default_report] if default_report in new_report_list else None
|
| 431 |
+
|
| 432 |
+
dropdown_reports = gr.Dropdown(
|
| 433 |
+
new_report_list,
|
| 434 |
+
label="Select one or more reports (scroll or type to search)",
|
| 435 |
+
multiselect=True,
|
| 436 |
+
value=default_report_value,
|
| 437 |
+
interactive=True,
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
#---------------- SELECT BY FILTERS SECTION ------------
|
| 441 |
+
with gr.Group(visible=False) as filters_section:
|
| 442 |
+
#----- First level filter for selecting Report source/category ----------
|
| 443 |
+
dropdown_sources = gr.Dropdown(
|
| 444 |
+
["Consolidated","Ministry, Department, Agency and Projects","Local Government","Value for Money","Thematic"],
|
| 445 |
+
label="Select Report Category",
|
| 446 |
+
value=None,
|
| 447 |
+
interactive=True,
|
| 448 |
+
)
|
| 449 |
|
| 450 |
+
#------ second level filter for selecting subtype within the report category selected above
|
| 451 |
+
dropdown_category = gr.Dropdown(
|
| 452 |
+
[], # Start with empty choices
|
| 453 |
+
value=None,
|
| 454 |
+
label = "Filter for Sub-Type",
|
| 455 |
+
interactive=True)
|
| 456 |
+
|
| 457 |
+
#----------- update the second level filter based on values from first level ----------------
|
| 458 |
+
def rs_change(rs):
|
| 459 |
+
if rs: # Only update choices if a value is selected
|
| 460 |
+
return gr.update(choices=new_files[rs], value=None) # Set value to None (no preselection)
|
| 461 |
+
else:
|
| 462 |
+
return gr.update(choices=[], value=None) # Empty choices if nothing selected
|
| 463 |
+
dropdown_sources.change(fn=rs_change, inputs=[dropdown_sources], outputs=[dropdown_category])
|
| 464 |
+
|
| 465 |
+
#--------- Select the years for reports -------------------------------------
|
| 466 |
+
dropdown_year = gr.Dropdown(
|
| 467 |
+
['2018','2019','2020','2021','2022','2023'],
|
| 468 |
+
label="Filter for year",
|
| 469 |
+
multiselect=True,
|
| 470 |
+
value=None,
|
| 471 |
+
interactive=True,
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
# Toggle visibility based on search method
|
| 475 |
+
def toggle_search_method(method):
|
| 476 |
+
"""Note - this function removes the default value from report search when toggled"""
|
| 477 |
+
if method == "Search by Report Name":
|
| 478 |
+
# Show report selection, hide filters, and clear filter values
|
| 479 |
+
return (
|
| 480 |
+
gr.update(visible=True), # report_name_section
|
| 481 |
+
gr.update(visible=False), # filters_section
|
| 482 |
+
gr.update(value=None), # dropdown_sources
|
| 483 |
+
gr.update(value=None), # dropdown_category
|
| 484 |
+
gr.update(value=None), # dropdown_year
|
| 485 |
+
gr.update() # dropdown_reports
|
| 486 |
+
)
|
| 487 |
+
else: # "Search by Filters"
|
| 488 |
+
# Show filters, hide report selection, and clear report values
|
| 489 |
+
return (
|
| 490 |
+
gr.update(visible=False), # report_name_section
|
| 491 |
+
gr.update(visible=True), # filters_section
|
| 492 |
+
gr.update(), # dropdown_sources
|
| 493 |
+
gr.update(), # dropdown_category
|
| 494 |
+
gr.update(), # dropdown_year
|
| 495 |
+
gr.update(value=[]) # dropdown_reports
|
| 496 |
+
)
|
| 497 |
+
|
| 498 |
+
# Pass to the event handler
|
| 499 |
+
search_method.change(
|
| 500 |
+
fn=toggle_search_method,
|
| 501 |
+
inputs=[search_method],
|
| 502 |
+
outputs=[
|
| 503 |
+
report_name_section,
|
| 504 |
+
filters_section,
|
| 505 |
+
dropdown_sources,
|
| 506 |
+
dropdown_category,
|
| 507 |
+
dropdown_year,
|
| 508 |
+
dropdown_reports
|
| 509 |
+
]
|
| 510 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
|
| 512 |
############### tab for Question selection ###############
|
| 513 |
with gr.TabItem("Examples",elem_id = "tab-examples",id = 0):
|
|
|
|
| 927 |
[textbox]
|
| 928 |
)
|
| 929 |
|
| 930 |
+
# Cancel button for no filters
|
| 931 |
cancel_btn.click(
|
| 932 |
lambda: (
|
| 933 |
None, # reset check status
|
model_params.cfg
CHANGED
|
@@ -14,3 +14,4 @@ NVIDIA_ENDPOINT = https://huggingface.co/api/integrations/dgx/v1
|
|
| 14 |
MAX_TOKENS = 64
|
| 15 |
[app]
|
| 16 |
repo_id = mtyrrell/spaces_log
|
|
|
|
|
|
| 14 |
MAX_TOKENS = 64
|
| 15 |
[app]
|
| 16 |
repo_id = mtyrrell/spaces_log
|
| 17 |
+
dropdown_default = Consolidted Report ,Report of the Auditor General 2023
|
style.css
CHANGED
|
@@ -584,3 +584,6 @@ span.chatbot > p > img{
|
|
| 584 |
|
| 585 |
|
| 586 |
|
|
|
|
|
|
|
|
|
|
|
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
|