File size: 11,505 Bytes
c83f30f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c51a88
83a6fef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93fa507
702b856
93fa507
83a6fef
9ce164b
83a6fef
9ce164b
83a6fef
 
 
 
 
93fa507
83a6fef
 
 
 
 
9ce164b
 
702b856
93fa507
 
 
 
9ce164b
93fa507
 
 
9ce164b
93fa507
9ce164b
93fa507
9ce164b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93fa507
9ce164b
 
93fa507
79bc4e9
 
 
 
 
 
 
 
 
93fa507
 
702b856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28cb3ca
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import gradio as gr
import pandas as pd
import numpy as np
import os
import time
import re
import json
from auditqa.sample_questions import QUESTIONS
from auditqa.engine.prompts import audience_prompts
from auditqa.reports import POSSIBLE_REPORTS, files
from auditqa.doc_process import process_pdf
from langchain_core.messages import (
    HumanMessage,
    SystemMessage,
)
from langchain_huggingface import ChatHuggingFace
from langchain_core.output_parsers import StrOutputParser
from langchain_huggingface import HuggingFaceEndpoint
from dotenv import load_dotenv
load_dotenv()

HF_token = os.environ["HF_TOKEN"]
#process_pdf()


# --------------------------------------------------------------------
# Gradio
# --------------------------------------------------------------------

# Set up Gradio Theme
theme = gr.themes.Base(
    primary_hue="blue",
    secondary_hue="red",
    font=[gr.themes.GoogleFont("Poppins"), "ui-sans-serif", "system-ui", "sans-serif"],
    text_size = gr.themes.utils.sizes.text_sm,
)

init_prompt =  """
Hello, I am Audit Q&A, a conversational assistant designed to help you understand audit Reports. I will answer your questions by using **Audit reports publishsed by Auditor General Office**.
💡 How to use (tabs on right)
- **Reports**: You can choose to address your question to either specific report or a collection of report like District or Ministry focused reports. \
If you dont select any then the Consolidated report is relied upon to answer your question.
- **Examples**: We have curated some example questions,select a particular question from category of questions.
- **Sources**: This tab will display the relied upon paragraphs from the report, to help you in assessing or fact checking if the answer provided by Audit Q&A assitant is correct or not.
⚠️ For limitations of the tool please check **Disclaimer** tab.
"""


with gr.Blocks(title="Audit Q&A", css= "style.css", theme=theme,elem_id = "main-component") as demo:
    #----------------------------------------------------------------------------------------------
    # main tab where chat interaction happens
    # ---------------------------------------------------------------------------------------------
    with gr.Tab("AuditQ&A"):
        
        with gr.Row(elem_id="chatbot-row"):
            # chatbot output screen
            with gr.Column(scale=2):
                chatbot = gr.Chatbot(
                    value=[(None,init_prompt)],
                    show_copy_button=True,show_label = False,elem_id="chatbot",layout = "panel",
                    avatar_images = (None,"data-collection.png"),
                )
                



                with gr.Row(elem_id = "input-message"):
                    textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,
                                       lines = 1,interactive = True,elem_id="input-textbox")

            # second column with playground area for user to select values
            with gr.Column(scale=1, variant="panel",elem_id = "right-panel"):
                # creating tabs on right panel
                with gr.Tabs() as tabs:
                    ################## tab for REPORTS SELECTION ##########
                    with gr.Tab("Reports",elem_id = "tab-config",id = 2):
                        gr.Markdown("Reminder: To get better results select the specific report/reports")

                    ############### tab for Question selection ###############
                    with gr.TabItem("Examples",elem_id = "tab-examples",id = 0):
                        examples_hidden = gr.Textbox(visible = False)

                        # getting defualt key value to display
                        first_key = list(QUESTIONS.keys())[0]
                        # create the question category dropdown
                        dropdown_samples = gr.Dropdown(QUESTIONS.keys(),value = first_key,
                                                       interactive = True,show_label = True,
                                                       label = "Select a category of sample questions",
                                                       elem_id = "dropdown-samples")
                        
                        
                        # iterate through the questions list
                        samples = []
                        for i,key in enumerate(QUESTIONS.keys()):
                            examples_visible = True if i == 0 else False
                            with gr.Row(visible = examples_visible) as group_examples:
                                examples_questions = gr.Examples(
                                    QUESTIONS[key],
                                    [examples_hidden],
                                    examples_per_page=8,
                                    run_on_click=False,
                                    elem_id=f"examples{i}",
                                    api_name=f"examples{i}",
                                    # label = "Click on the example question or enter your own",
                                    # cache_examples=True,
                                )
                            
                            samples.append(group_examples)
                    ########## tab for Sources reporting #################
                    with gr.Tab("Sources",elem_id = "tab-citations",id = 1):
                        sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox")
                        docs_textbox = gr.State("")
                        gr.Markdown("Reminder: To get better results select the specific report/reports")

    def change_sample_questions(key):
        # update the questions list based on key selected
        index = list(QUESTIONS.keys()).index(key)
        visible_bools = [False] * len(samples)
        visible_bools[index] = True
        return [gr.update(visible=visible_bools[i]) for i in range(len(samples))]

    dropdown_samples.change(change_sample_questions,dropdown_samples,samples)
                        

    # static tab 'about us'
    with gr.Tab("About",elem_classes = "max-height other-tabs"):
        with gr.Row():
            with gr.Column(scale=1):
                    gr.Markdown("""The <ins>[**Office of the Auditor General (OAG)**](https://www.oag.go.ug/welcome)</ins> in Uganda, \
                consistent with the mandate of Supreme Audit Institutions (SAIs),\
                remains integral in ensuring transparency and fiscal responsibility.\
                Regularly, the OAG submits comprehensive audit reports to Parliament, \
                which serve as instrumental references for both policymakers and the public, \
                facilitating informed decisions regarding public expenditure. 
                
                However, the prevalent underutilization of these audit reports, \
                leading to numerous unimplemented recommendations, has posed significant challenges\
                to the effectiveness and impact of the OAG's operations. The audit reports made available \
                to the public have not been effectively used by them and other relevant stakeholders. \
                The current format of the audit reports is considered a challenge to the \
                stakeholders' accessibility and usability. This in one way constrains transparency \
                and accountability in the utilization of public funds and effective service delivery. 
                
                In the face of this, modern advancements in Artificial Intelligence (AI),\
                particularly Retrieval Augmented Generation (RAG) technology, \
                emerge as a promising solution. By harnessing the capabilities of such AI tools, \
                there is an opportunity not only to improve the accessibility and understanding \
                of these audit reports but also to ensure that their insights are effectively \
                translated into actionable outcomes, thereby reinforcing public transparency \
                and service delivery in Uganda. 
                
                To address these issues, the OAG has initiated several projects, \
                such as the Audit Recommendation Tracking (ART) System and the Citizens Feedback Platform (CFP). \
                These systems are designed to increase the transparency and relevance of audit activities. \
                However, despite these efforts, engagement and awareness of the audit findings remain low, \
                and the complexity of the information often hinders effective public utilization. Recognizing the need for further\
                enhancement in how audit reports are processed and understood, \
                the **Civil Society and Budget Advocacy Group (CSBAG)** in partnership with the **GIZ**, \
                has recognizing the need for further enhancement in how audit reports are processed and understood.   
                
                This prototype tool leveraging AI (Artificial Intelligence) aims at offering critical capabilities such as '
                summarizing complex texts, extracting thematic insights, and enabling interactive, \
                user-friendly analysis through a chatbot interface. By making the audit reports more accessible,\
                this aims to increase readership and utilization among stakeholders, \
                which can lead to better accountability and improve service delivery
                
                """)


    # static tab for disclaimer
    with gr.Tab("Disclaimer",elem_classes = "max-height other-tabs"):
        with gr.Row():
            with gr.Column(scale=1):
                gr.Markdown("""
                - This chatbot is intended for specific use of answering the questions based on audit reports published by OAG, for any use beyond this scope we have no liability to response provided by chatbot.
                - We do not guarantee the accuracy, reliability, or completeness of any information provided by the chatbot and disclaim any liability or responsibility for actions taken based on its responses.
                - The chatbot may occasionally provide inaccurate or inappropriate responses, and it is important to exercise judgment and critical thinking when interpreting its output.
                - The chatbot responses should not be considered professional or authoritative advice and are generated based on patterns in the data it has been trained on.
                - The chatbot's responses do not reflect the opinions or policies of our organization or its affiliates.
                - Any personal or sensitive information shared with the chatbot is at the user's own risk, and we cannot guarantee complete privacy or confidentiality.
                - the chatbot is not deterministic, so there might be change in answer to same question when asked by different users or multiple times.
                - By using this chatbot, you agree to these terms and acknowledge that you are solely responsible for any reliance on or actions taken based on its responses.
                - **This is just a prototype and being tested and worked upon, so its not perfect and may sometimes give irrelevant answers**. If you are not satisfied with the answer, please ask a more specific question or report your feedback to help us improve the system.
                """)
    demo.queue()

demo.launch()