|
import os |
|
from langchain.chains import RetrievalQA |
|
from langchain.llms import AzureOpenAI |
|
from langchain.document_loaders import TextLoader |
|
from langchain.document_loaders import PyPDFLoader |
|
from langchain.indexes import VectorstoreIndexCreator |
|
from langchain.text_splitter import CharacterTextSplitter |
|
from langchain.embeddings import OpenAIEmbeddings |
|
from langchain.vectorstores import Chroma |
|
from langchain.chains.question_answering import load_qa_chain |
|
from langchain.llms import AzureOpenAI |
|
from langchain.chains.question_answering import load_qa_chain |
|
import streamlit as st |
|
from PIL import Image |
|
import time |
|
|
|
image = Image.open('Wipro logo.png') |
|
st.image(image) |
|
|
|
st.title("Wipro Impact | CSRD | Advisor") |
|
|
|
st.header("Enable clients to prepare for CSRD.. ") |
|
|
|
|
|
genre = st.radio( |
|
"Choose a CSRD focus area for AI question answering", |
|
('E1-Climate Change', 'E4-Biodiversity and ecosystem', 'S1-Own Workforce'), index=0) |
|
|
|
url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F13%2520Draft%2520ESRS%2520S1%2520Own%2520workforce%2520November%25202022.pdf" |
|
|
|
if genre == 'E1-Climate Change': |
|
url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F08%2520Draft%2520ESRS%2520E1%2520Climate%2520Change%2520November%25202022.pdf" |
|
samplequestions = ["What are the climate related indicators?", "List all the disclosure requirments listed in page 3?", "Policies related to climate change mitigation and adaptation?", |
|
"What should the company disclose regarding Actions and resources in relation to climate change policies?" , "How should the GHG emission reduction targets be reported?" , |
|
"Total energy consumption from non-renewable sources for high climate impact sectors should be disaggregated as ?", |
|
"Total energy consumption from renewable sources should be disaggregated as ?" , |
|
"What should be disclosed on GHG removals and GHG mitigation projects financed through carbon credits ?" , |
|
"Is it wise to invest on carbon credits? ", |
|
"What is Climate change adaptation? ", "What are Decarbonisation levers?" ] |
|
|
|
if genre == 'E4-Biodiversity and ecosystem': |
|
url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F11%2520Draft%2520ESRS%2520E4%2520Biodiversity%2520and%2520ecosystems%2520November%25202022.pdf" |
|
samplequestions = ["What are the Biodiversity related indicators?", "List all the disclosure requirments listed in page 3?"] |
|
if genre == 'S1-Own Workforce': |
|
url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F13%2520Draft%2520ESRS%2520S1%2520Own%2520workforce%2520November%25202022.pdf" |
|
samplequestions = ["What are the social related indicators?", "List all the disclosure requirments listed in page 3?"] |
|
|
|
|
|
|
|
|
|
sampleselectedquestion = st.selectbox( |
|
'Just ask your question or start with a one of these example questions...', samplequestions ) |
|
|
|
st.write(" :green[ Ask any thing on your mind...just type your question here...]") |
|
yourquestion = st.text_input('Your question', sampleselectedquestion) |
|
st.write('Your typed .. ', yourquestion) |
|
|
|
|
|
|
|
|
|
os.environ['OPENAI_API_TYPE'] = 'azure' |
|
os.environ['OPENAI_API_VERSION'] = '2023-03-15-preview' |
|
|
|
llmgpt3 = AzureOpenAI( deployment_name="testdavanci", model_name="text-davinci-003" ) |
|
chain = load_qa_chain(llm=llmgpt3, chain_type="map_reduce") |
|
|
|
aimethod = st.radio( |
|
"Choose a AI brain or document comprehension method", |
|
('2 minutes AI method map_reduce', '4 minutes AI method refine' ), index=0) |
|
|
|
mychain_type = "map_reduce" |
|
if aimethod == '2 minutes AI method map_reduce': |
|
mychain_type = "map_reduce" |
|
if aimethod == '4 minutes AI method refine': |
|
mychain_type = "refine" |
|
|
|
chain = load_qa_chain(llm=llmgpt3, chain_type=mychain_type) |
|
|
|
|
|
loader1 = PyPDFLoader(url) |
|
|
|
|
|
def history(): |
|
mycount = 0 |
|
if 'count' not in st.session_state: |
|
st.session_state['count'] = 0 |
|
else: |
|
mycount = st.session_state['count'] |
|
|
|
if True: |
|
st.write(mycount) |
|
mycount = mycount + 1 |
|
st.session_state['count'] = mycount |
|
for i in range(mycount): |
|
mystatekeyindex = "element" + str(i) |
|
mystatekeyanswerindex = "elementANS" + str(i) |
|
if mystatekeyindex not in st.session_state: |
|
st.session_state[mystatekeyindex] = yourquestion |
|
st.session_state[mystatekeyanswerindex] = answer |
|
if mystatekeyindex in st.session_state: |
|
with st.expander(st.session_state[mystatekeyindex]): |
|
st.write( st.session_state[mystatekeyanswerindex] ) |
|
|
|
|
|
def colorizedtext(acolor, astring): |
|
formattedcolor = ":" + acolor + "[" + astring + "]" |
|
return formattedcolor |
|
|
|
|
|
|
|
if st.button("Ask QA "): |
|
documents = loader1.load() |
|
answer = "" |
|
with st.spinner(" Finding answer for your question .... AI will get you answer in 2 more minutes... " ): |
|
with st.expander( "Employing your choice of AI method ... " + aimethod + "..."): |
|
st.write(str(chain)[:700]) |
|
st.write("AI is reading this [link](%s)" % url) |
|
prgpgress = st.progress(0) |
|
st.subheader(colorizedtext("red", yourquestion)) |
|
for i in range(100): |
|
time.sleep(0.9) |
|
prgpgress.progress(i+1) |
|
|
|
|
|
|
|
answer = chain.run(input_documents=documents, question=yourquestion) |
|
st.subheader(colorizedtext("blue", answer)) |
|
history() |
|
|
|
|
|
|
|
|
|
|