File size: 7,716 Bytes
7013379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f4ad80a
7013379
 
 
 
 
318257f
7013379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ad069e
 
 
 
 
 
b9822c8
 
4ad069e
7013379
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import openai
import gradio as gr
from dotenv import load_dotenv
from utils import chat
from config import CFG_APP

# Load API KEY
try:
    load_dotenv()
except Exception as e:
    pass
openai.api_key = os.environ["OPENAI_API_KEY"]


# SYS Template
system_template = {
    "role": "system",
    "content": CFG_APP.INIT_PROMPT,
}

# APP
theme = gr.themes.Monochrome(
    font=[gr.themes.GoogleFont("Kanit"), "sans-serif"],
)

with gr.Blocks(title=CFG_APP.BOT_NAME, css="assets/style.css", theme=theme) as demo:
    gr.Markdown(f"<h1><center>{CFG_APP.BOT_NAME} 🤖</center></h1>")

    with gr.Row():
        with gr.Column(scale=2):
            chatbot = gr.Chatbot(
                elem_id="chatbot", label=f"{CFG_APP.BOT_NAME} chatbot", show_label=False
            )
            state = gr.State([system_template])


            with gr.Row():
                ask = gr.Textbox(
                    show_label=False,
                    placeholder="Ask here your question and press enter",
                    )

            ask_examples_hidden = gr.Textbox(elem_id="hidden-message")

            examples_questions = gr.Examples(
                [*CFG_APP.DEFAULT_QUESTIONS],
                [ask_examples_hidden],
                examples_per_page=15,
            )

        with gr.Column(scale=1, variant="panel"):
            sources_textbox = gr.Markdown(show_label=False)

    ask.submit(
        fn=chat,
        inputs=[ask, state],
        outputs=[chatbot, state, sources_textbox],
    )
    ask.submit(lambda x: gr.update(value=""), [], [ask])

    ask_examples_hidden.change(
        fn=chat,
        inputs=[ask_examples_hidden, state],
        outputs=[chatbot, state, sources_textbox],
    )
    demo.queue(concurrency_count=16)
    gr.Markdown(
        """
    
    ### 🎯 Understanding CSRD_GPT's Purpose
    
    In an era marked by growing emphasis on Environmental, Social, and Governance (ESG) considerations, staying well-informed about the intricate landscape of ESG and CSRD regulations can be a challenging endeavor. The evolving nature of these regulations and the wealth of information available can make it difficult to extract precise insights.


    \n CSRD_GPT, a conversational tool related to a chatbot, offers an effective solution to this challenge. CSRD_GPT is specifically designed to address queries related to CSRD regulations. This tool draws its insights solely from documents published by official European regulatory sources, thus assuring the reliability and pertinence of its responses. By strictly focusing on these documents, CSRD_GPT ensures that it does not reference non-relevant sources, maintaining a high standard of precision in its responses. This novel tool harnesses the power of conversational AI to help users navigate the complex world of environmental's regulations, simplifying the task and promoting compliance efficiency.
    
    """
    )

    gr.Markdown(
        """
    
    ### 📃 Inputs and functionalities
    
    In its initial release, Version 0, CSRD_GPT uses the subsequent 4 documents as the basis for its answers:
    \n
    |Document|Link|
    |:----|:----|
    |CSRD|https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:32022L2464|
    |CSRD - Delegated Act|https://webgate.ec.europa.eu/regdel/web/delegatedActs/2111/documents/latest?lang=en|
    |ESRS – CSRD DA annex 1 et 2|https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=OJ:L_202302772|
    |Q&A on the Adoption of European Sustainability Reporting Standards|https://ec.europa.eu/commission/presscorner/detail/en/qanda_23_4043|
    
     """
    )

    gr.Markdown(
        """

    CSRD_GPT provides users with the opportunity to input queries using a dedicated prompt area, much like the one used in OpenAI's ChatGPT. If you're unsure of what to ask, examples of potential questions are displayed below the query bar. Simply click on one of these and the tool will generate corresponding responses.


    \n When a query is submitted to the model, 10 sources are extracted from the previously mentioned documents to provide a comprehensive answer. These sources are quoted within the generated answer to ensure accuracy and reliability. For easy reference, exact passages can be quickly located by clicking on the link icon 🔗 located beneath each excerpt, which will directly guide you to the relevant section within the document.
    
    """
    )

    gr.Markdown(
        """
    
    ### 💬 Prompt Initialization
    
    To limit the model's responses to only the 10 proposed sources, a set of prompts has been designed and will serve as instructions to the GPT API. This design decision ensures that the model's output is reliably grounded in the selected documents, contributing to the overall accuracy and reliability of the tool. The structured guidance provided by these prompts enables the GPT API to more effectively navigate the wealth of information contained within the ten sources, delivering highly relevant and concise responses to the users' queries.

    <u>Prompts used to initialize CSRD_GPT: </u>

    - "You are CSRD_GPT, an expert in CSRD regulations, an AI Assistant by Nexialog Consulting."
    - "You are given a question and extracted parts of regulation reports."
    - "Provide a clear and structured answer based only on the context provided."
    - "When relevant, use bullet points and lists to structure your answers."
    - "When relevant, use facts and numbers from the following documents in your answer."
    - "Whenever you use information from a document, reference it at the end of the sentence (ex: [doc 2])."
    - "You don't have to use all documents, only if it makes sense in the conversation."
    - "Don't make up new sources and references that don't exist."
    - "If no relevant information to answer the question is present in the documents, just say you don't have enough information to answer."


    
    """
    )

    gr.Markdown(
        """

    ### 🔨 Si vous êtes un consultant et que vous testez l'outil : 
    https://docs.google.com/forms/d/e/1FAIpQLSdI-fhYIOF13NoCsRapWxBHVSKkd3WimK3CN0I-t-O5u8mzGg/viewform?usp=sf_link

    """
    )

    gr.Markdown(
        """
    
    ### ⚙️Technical features
    
    CSRD_GPT operates through two core modules, the GPT API from OpenAI and an embedding model. The functioning of these components is integrated into a seamless workflow, which can be summarized in the figure below :


    <div style="display:flex; justify-content:center;">
    <img src="file/Images/Reg-GPT.png" width="800" height="800" />
    </div>
 

    - Open AI Api version :  gpt-3.5-turbo
    - Embedding model : https://huggingface.co/sentence-transformers/multi-qa-mpnet-base-dot-v1



    
    """
    )
    gr.Markdown(
        "<h1><center>Disclaimer ⚠️</center></h1>\n"
        + """
- Please be aware that this is Version 0 of our application. You may encounter certain errors or glitches as we continue to refine and enhance its functionality. You might experience some nonsensical answers, similar to those experienced when using chat-GPT. If you encounter any issues, don't hesitate to reach out to us at [email protected].
- Our application relies on an external API provided by OpenAI. There may be instances where errors occur due to high demand on the API. If you encounter such an issue, we recommend that you refresh the page and retry your query, or try again a little bit later.
- When using our application, we urge you to ask clear and explicit questions that adhere to the scope of credit risk regulations. This will ensure that you receive the most accurate and relevant responses from the system.
"""
    )

demo.launch()