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"

{CFG_APP.BOT_NAME} 🤖

") 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. Prompts used to initialize CSRD_GPT: - "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 :
- Open AI Api version : gpt-3.5-turbo - Embedding model : https://huggingface.co/sentence-transformers/multi-qa-mpnet-base-dot-v1 """ ) gr.Markdown( "

Disclaimer ⚠️

\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 data@nexialog.com. - 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()