File size: 5,320 Bytes
d7ff885
 
 
f9801a3
 
d7ff885
 
 
 
 
 
 
 
 
3de3b1c
f9801a3
3103d35
33a78e2
f9801a3
d7ff885
f9801a3
d7ff885
f9801a3
 
d7ff885
 
 
f9801a3
d7ff885
f9801a3
d7ff885
 
 
 
 
 
 
 
 
f9801a3
d7ff885
 
 
 
 
 
f9801a3
 
 
 
d7ff885
 
f9801a3
d7ff885
 
 
f9801a3
 
 
 
d7ff885
 
f9801a3
d7ff885
 
f9801a3
d7ff885
 
 
f9801a3
d7ff885
 
 
 
 
f9801a3
d7ff885
f9801a3
 
d7ff885
f9801a3
 
d7ff885
 
 
 
 
 
f9801a3
d7ff885
 
 
 
 
 
 
 
 
 
 
 
 
f9801a3
 
d7ff885
 
 
f9801a3
33a78e2
f9801a3
d7ff885
 
 
33a78e2
d7ff885
33a78e2
 
 
a0b08f0
33a78e2
7532108
33a78e2
1a1b933
f9801a3
 
d7ff885
 
 
f9801a3
 
 
 
d7ff885
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
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()