ppsingh commited on
Commit
ae92e4d
·
verified ·
1 Parent(s): 87d63a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -52
app.py CHANGED
@@ -336,7 +336,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
336
  avatar_images = (None,"data-collection.png"),
337
  )
338
 
339
- # feedback UI
340
  with gr.Column(elem_id="feedback-container"):
341
  with gr.Row(visible=False) as feedback_row:
342
  gr.Markdown("Was this response helpful?")
@@ -345,10 +345,25 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
345
  not_okay_btn = gr.Button("👎 Not to expectations", elem_classes="feedback-button")
346
  feedback_thanks = gr.Markdown("Thanks for the feedback!", visible=False)
347
  feedback_state = gr.State()
348
-
349
-
350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
 
 
352
  with gr.Row(elem_id = "input-message"):
353
  textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,
354
  lines = 1,interactive = True,elem_id="input-textbox")
@@ -383,23 +398,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
383
  value=default_report_value,
384
  interactive=True,
385
  )
386
-
387
- #----- First level filter for selecting Report source/category ----------
388
 
389
- #with gr.Group(visible=True) as report_name_section:
390
- # # Get default report value from config if present
391
- # default_report = model_config.get('app', 'dropdown_default', fallback=None)
392
- # # Check if it actually exists in the master list
393
- # default_report_value = [default_report] if default_report in new_report_list else None
394
- #
395
- # dropdown_reports = gr.Dropdown(
396
- # new_report_list,
397
- # label="Select one or more reports (scroll or type to search)",
398
- # multiselect=True,
399
- # value=default_report_value,
400
- # interactive=True,
401
- # )
402
-
403
  #---------------- SELECT BY FILTERS SECTION ------------
404
  with gr.Group(visible=False) as filters_section:
405
  #----- First level filter for selecting Report source/category ----------
@@ -416,29 +415,16 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
416
  value=None,
417
  label = "Filter for Sub-Type",
418
  interactive=True)
419
-
420
- #dropdown_sources = gr.Dropdown(
421
- # ["Consolidated","Ministry, Department and Agency","Project","Hospital","Local Government","Value for Money","Thematic"],
422
- # label="Select Report Category",
423
- # value="Consolidated",
424
- # interactive=True,
425
- #)
426
-
427
- #------ second level filter for selecting subtype within the report category selected above
428
- #dropdown_category = gr.Dropdown(
429
- # new_files["Consolidated"],
430
- # multiselect = True,
431
- # value = new_files["Consolidated"][0],
432
- # label = "Filter for Sub-reports",
433
- # interactive=True)
434
-
435
- #----------- update the secodn level filter abse don values from first level ----------------
436
- def rs_change(rs):
437
- return gr.update(choices=new_files[rs], value=new_files[rs])
438
- dropdown_sources.change(fn=rs_change, inputs=[dropdown_sources], outputs=[dropdown_category])
439
 
 
 
 
 
 
 
 
440
 
441
- # Toggle visibility based on search method
442
  def toggle_search_method(method):
443
  """Note - this function removes the default value from report search when toggled"""
444
  if method == "Search by Report Name":
@@ -461,7 +447,7 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
461
  gr.update(), # dropdown_year
462
  gr.update(value=[]) # dropdown_reports
463
  )
464
-
465
  # Pass to the event handler
466
  search_method.change(
467
  fn=toggle_search_method,
@@ -474,6 +460,37 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
474
  dropdown_reports
475
  ]
476
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
  #--------- Select the years for reports -------------------------------------
479
  #dropdown_year = gr.Dropdown(
@@ -536,25 +553,29 @@ with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-
536
 
537
  dropdown_samples.change(change_sample_questions,dropdown_samples,samples)
538
 
539
- # ---- New Guidelines Tab ----
 
540
  with gr.Tab("Guidelines", elem_classes="max-height other-tabs"):
541
  gr.Markdown("""
542
- Welcome to Audit Q&A, your AI-powered assistant for exploring and understanding Uganda's audit reports. This tool leverages advanced language models to help you get clear and structured answers based on audit publications. To get you started, here a few tips on how to use the tool:
543
- ### Crafting Effective Prompts
 
 
 
 
 
 
 
544
  - **Be Clear and Specific**: Frame your questions clearly and focus on what you want to learn.
545
  - **One Topic at a Time**: Break complex queries into simpler, focused questions.
546
- - **Be Direct**: Instead of "What are the findings?", try "What were the main issues identified in procurement practices?" or "What challenges were found in revenue collection?"
 
547
 
548
- ### Best Practices
549
- - Start with a simple, focused question.
550
- - Follow up with additional questions if your initial query doesn't yield the desired results.
551
- - Experiment with different phrasings to get the most accurate answers.
552
- - Use the source citations as a reference to validate the provided information.
553
- ### Utilizing Filters
554
  - **Report Category & Subtype**: Use the "Reports" tab to choose your preferred report category and refine your query by selecting a specific sub-type. This will help narrow down the context for your question.
555
  - **Year Selection**: Choose one or more years from the "Year" filter to target your query to specific time periods.
556
  - **Specific Reports**: Optionally, select specific reports using the dropdown to focus on a particular document or set of documents.
557
- ### Useful Resources
558
 
559
  - <ins>[**Short Course: Generative AI for Everyone** (3 hours)](https://www.deeplearning.ai/courses/generative-ai-for-everyone/)</ins>
560
  - <ins>[**Short Course: Advanced Prompting** (1 hour)](https://www.deeplearning.ai/courses/ai-for-everyone/)</ins>
 
336
  avatar_images = (None,"data-collection.png"),
337
  )
338
 
339
+ #---------------- FEEDBACK ----------------------
340
  with gr.Column(elem_id="feedback-container"):
341
  with gr.Row(visible=False) as feedback_row:
342
  gr.Markdown("Was this response helpful?")
 
345
  not_okay_btn = gr.Button("👎 Not to expectations", elem_classes="feedback-button")
346
  feedback_thanks = gr.Markdown("Thanks for the feedback!", visible=False)
347
  feedback_state = gr.State()
 
 
348
 
349
+ #---------------- WARNINGS ----------------------
350
+ # No filters selected warning
351
+ with gr.Row(visible=False, elem_id="warning-row", elem_classes="warning-message") as warning_row:
352
+ with gr.Column():
353
+ gr.Markdown("<span class='warning-icon'>⚠️</span> **No report filter selected. Are you sure you want to proceed?**")
354
+ with gr.Row(elem_classes="warning-buttons"):
355
+ proceed_btn = gr.Button("Proceed", elem_classes="proceed")
356
+ cancel_btn = gr.Button("Cancel", elem_classes="cancel")
357
+
358
+ # Short query warning (< 4 words)
359
+ with gr.Row(visible=False, elem_id="warning-row", elem_classes="warning-message") as short_query_warning_row:
360
+ with gr.Column():
361
+ gr.Markdown("<span class='warning-icon'>⚠️</span> **Your query is too short. Please lengthen your query to ensure the app has adequate context.**")
362
+ with gr.Row(elem_classes="warning-buttons"):
363
+ short_query_proceed_btn = gr.Button("OK", elem_classes="proceed")
364
+
365
 
366
+ #---------------- QUERY INPUT ----------------------
367
  with gr.Row(elem_id = "input-message"):
368
  textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,
369
  lines = 1,interactive = True,elem_id="input-textbox")
 
398
  value=default_report_value,
399
  interactive=True,
400
  )
 
 
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  #---------------- SELECT BY FILTERS SECTION ------------
403
  with gr.Group(visible=False) as filters_section:
404
  #----- First level filter for selecting Report source/category ----------
 
415
  value=None,
416
  label = "Filter for Sub-Type",
417
  interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
 
419
+ #----------- update the secodn level filter abse don values from first level ----------------
420
+ def rs_change(rs):
421
+ if rs: # Only update choices if a value is selected
422
+ return gr.update(choices=new_files[rs], value=None) # Set value to None (no preselection)
423
+ else:
424
+ return gr.update(choices=[], value=None) # Empty choices if nothing selected
425
+ dropdown_sources.change(fn=rs_change, inputs=[dropdown_sources], outputs=[dropdown_category])
426
 
427
+ # Toggle visibility based on search method
428
  def toggle_search_method(method):
429
  """Note - this function removes the default value from report search when toggled"""
430
  if method == "Search by Report Name":
 
447
  gr.update(), # dropdown_year
448
  gr.update(value=[]) # dropdown_reports
449
  )
450
+
451
  # Pass to the event handler
452
  search_method.change(
453
  fn=toggle_search_method,
 
460
  dropdown_reports
461
  ]
462
  )
463
+ #----- First level filter for selecting Report source/category ----------
464
+
465
+ #with gr.Group(visible=True) as report_name_section:
466
+ # # Get default report value from config if present
467
+ # default_report = model_config.get('app', 'dropdown_default', fallback=None)
468
+ # # Check if it actually exists in the master list
469
+ # default_report_value = [default_report] if default_report in new_report_list else None
470
+ #
471
+ # dropdown_reports = gr.Dropdown(
472
+ # new_report_list,
473
+ # label="Select one or more reports (scroll or type to search)",
474
+ # multiselect=True,
475
+ # value=default_report_value,
476
+ # interactive=True,
477
+ # )
478
+
479
+ #dropdown_sources = gr.Dropdown(
480
+ # ["Consolidated","Ministry, Department and Agency","Project","Hospital","Local Government","Value for Money","Thematic"],
481
+ # label="Select Report Category",
482
+ # value="Consolidated",
483
+ # interactive=True,
484
+ #)
485
+
486
+ #------ second level filter for selecting subtype within the report category selected above
487
+ #dropdown_category = gr.Dropdown(
488
+ # new_files["Consolidated"],
489
+ # multiselect = True,
490
+ # value = new_files["Consolidated"][0],
491
+ # label = "Filter for Sub-reports",
492
+ # interactive=True)
493
+
494
 
495
  #--------- Select the years for reports -------------------------------------
496
  #dropdown_year = gr.Dropdown(
 
553
 
554
  dropdown_samples.change(change_sample_questions,dropdown_samples,samples)
555
 
556
+
557
+ # ---- New Guidelines Tab ----
558
  with gr.Tab("Guidelines", elem_classes="max-height other-tabs"):
559
  gr.Markdown("""
560
+ #### Welcome to Audit Q&A, your AI-powered assistant for exploring and understanding Uganda's audit reports. This tool leverages advanced language models to help you get clear and structured answers based on audit publications. To get you started, here a few tips on how to use the tool:
561
+ ## 💬 Crafting Effective Prompts
562
+ Clear, specific questions will give you the best results. Here are some examples:
563
+ | ❌ Less Effective | ✅ More Effective |
564
+ |------------------|-------------------|
565
+ | "What are the findings?" | "What were the main issues identified in procurement practices in the Ministry of Health in 2022?" |
566
+ | "Tell me about revenue collection" | "What specific challenges were identified in revenue collection at the local government level in 2021-2022?" |
567
+ | "Is there corruption?" | "What audit findings related to misappropriation of funds were reported in the education sector between 2020-2023?" |
568
+ ## ⭐ Best Practices
569
  - **Be Clear and Specific**: Frame your questions clearly and focus on what you want to learn.
570
  - **One Topic at a Time**: Break complex queries into simpler, focused questions.
571
+ - **Provide Context**: Mentioning specific ministries, years, or projects helps narrow the focus.
572
+ - **Follow Up**: Ask follow-up questions to explore a topic more deeply.
573
 
574
+ ## 🔍 Utilizing Filters
 
 
 
 
 
575
  - **Report Category & Subtype**: Use the "Reports" tab to choose your preferred report category and refine your query by selecting a specific sub-type. This will help narrow down the context for your question.
576
  - **Year Selection**: Choose one or more years from the "Year" filter to target your query to specific time periods.
577
  - **Specific Reports**: Optionally, select specific reports using the dropdown to focus on a particular document or set of documents.
578
+ ## 📚 Useful Resources
579
 
580
  - <ins>[**Short Course: Generative AI for Everyone** (3 hours)](https://www.deeplearning.ai/courses/generative-ai-for-everyone/)</ins>
581
  - <ins>[**Short Course: Advanced Prompting** (1 hour)](https://www.deeplearning.ai/courses/ai-for-everyone/)</ins>