Rajagopal commited on
Commit
13b193b
·
0 Parent(s):

Duplicate from Rajagopal/Nand1

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. Wipro logo.png +0 -0
  4. app.py +133 -0
  5. requirements.txt +7 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: csrd trying
3
+ emoji: 🏆
4
+ colorFrom: yellow
5
+ colorTo: gray
6
+ sdk: streamlit
7
+ sdk_version: 1.21.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: Rajagopal/Nand1
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Wipro logo.png ADDED
app.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.chains import RetrievalQA
3
+ from langchain.llms import AzureOpenAI
4
+ from langchain.document_loaders import TextLoader
5
+ from langchain.document_loaders import PyPDFLoader
6
+ from langchain.indexes import VectorstoreIndexCreator
7
+ from langchain.text_splitter import CharacterTextSplitter
8
+ from langchain.embeddings import OpenAIEmbeddings
9
+ from langchain.vectorstores import Chroma
10
+ from langchain.chains.question_answering import load_qa_chain
11
+ from langchain.llms import AzureOpenAI
12
+ from langchain.chains.question_answering import load_qa_chain
13
+ import streamlit as st
14
+ from PIL import Image
15
+ import time
16
+
17
+ image = Image.open('Wipro logo.png')
18
+ st.image(image)
19
+
20
+ st.title("Wipro Impact | CSRD | Advisor")
21
+
22
+ st.header("Enable clients to prepare for CSRD.. ")
23
+
24
+
25
+ genre = st.radio(
26
+ "Choose a CSRD focus area for AI question answering",
27
+ ('E1-Climate Change', 'E4-Biodiversity and ecosystem', 'S1-Own Workforce'), index=0)
28
+
29
+ url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F13%2520Draft%2520ESRS%2520S1%2520Own%2520workforce%2520November%25202022.pdf"
30
+
31
+ if genre == 'E1-Climate Change':
32
+ url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F08%2520Draft%2520ESRS%2520E1%2520Climate%2520Change%2520November%25202022.pdf"
33
+ samplequestions = ["What are the climate related indicators?", "List all the disclosure requirments listed in page 3?", "Policies related to climate change mitigation and adaptation?",
34
+ "What should the company disclose regarding Actions and resources in relation to climate change policies?" , "How should the GHG emission reduction targets be reported?" ,
35
+ "Total energy consumption from non-renewable sources for high climate impact sectors should be disaggregated as ?",
36
+ "Total energy consumption from renewable sources should be disaggregated as ?" ,
37
+ "What should be disclosed on GHG removals and GHG mitigation projects financed through carbon credits ?" ,
38
+ "Is it wise to invest on carbon credits? ",
39
+ "What is Climate change adaptation? ", "What are Decarbonisation levers?" ]
40
+
41
+ if genre == 'E4-Biodiversity and ecosystem':
42
+ url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F11%2520Draft%2520ESRS%2520E4%2520Biodiversity%2520and%2520ecosystems%2520November%25202022.pdf"
43
+ samplequestions = ["What are the Biodiversity related indicators?", "List all the disclosure requirments listed in page 3?"]
44
+ if genre == 'S1-Own Workforce':
45
+ url = "https://www.efrag.org/Assets/Download?assetUrl=%2Fsites%2Fwebpublishing%2FSiteAssets%2F13%2520Draft%2520ESRS%2520S1%2520Own%2520workforce%2520November%25202022.pdf"
46
+ samplequestions = ["What are the social related indicators?", "List all the disclosure requirments listed in page 3?"]
47
+
48
+
49
+
50
+
51
+ sampleselectedquestion = st.selectbox(
52
+ 'Just ask your question or start with a one of these example questions...', samplequestions )
53
+
54
+ st.write(" :green[ Ask any thing on your mind...just type your question here...]")
55
+ yourquestion = st.text_input('Your question', sampleselectedquestion)
56
+ st.write('Your typed .. ', yourquestion)
57
+
58
+
59
+
60
+
61
+ os.environ['OPENAI_API_TYPE'] = 'azure'
62
+ os.environ['OPENAI_API_VERSION'] = '2023-03-15-preview'
63
+
64
+ llmgpt3 = AzureOpenAI( deployment_name="testdavanci", model_name="text-davinci-003" )
65
+ chain = load_qa_chain(llm=llmgpt3, chain_type="map_reduce")
66
+
67
+ aimethod = st.radio(
68
+ "Choose a AI brain or document comprehension method",
69
+ ('2 minutes AI method map_reduce', '4 minutes AI method refine' ), index=0)
70
+
71
+ mychain_type = "map_reduce"
72
+ if aimethod == '2 minutes AI method map_reduce':
73
+ mychain_type = "map_reduce"
74
+ if aimethod == '4 minutes AI method refine':
75
+ mychain_type = "refine"
76
+
77
+ chain = load_qa_chain(llm=llmgpt3, chain_type=mychain_type)
78
+
79
+
80
+ loader1 = PyPDFLoader(url)
81
+
82
+
83
+ def history():
84
+ mycount = 0
85
+ if 'count' not in st.session_state:
86
+ st.session_state['count'] = 0
87
+ else:
88
+ mycount = st.session_state['count']
89
+
90
+ if True:
91
+ st.write(mycount)
92
+ mycount = mycount + 1
93
+ st.session_state['count'] = mycount
94
+ for i in range(mycount):
95
+ mystatekeyindex = "element" + str(i)
96
+ mystatekeyanswerindex = "elementANS" + str(i)
97
+ if mystatekeyindex not in st.session_state:
98
+ st.session_state[mystatekeyindex] = yourquestion
99
+ st.session_state[mystatekeyanswerindex] = answer
100
+ if mystatekeyindex in st.session_state:
101
+ with st.expander(st.session_state[mystatekeyindex]):
102
+ st.write( st.session_state[mystatekeyanswerindex] )
103
+
104
+
105
+ def colorizedtext(acolor, astring):
106
+ formattedcolor = ":" + acolor + "[" + astring + "]"
107
+ return formattedcolor
108
+
109
+
110
+
111
+ if st.button("Ask QA "):
112
+ documents = loader1.load()
113
+ answer = ""
114
+ with st.spinner(" Finding answer for your question .... AI will get you answer in 2 more minutes... " ):
115
+ with st.expander( "Employing your choice of AI method ... " + aimethod + "..."):
116
+ st.write(str(chain)[:700])
117
+ st.write("AI is reading this [link](%s)" % url)
118
+ prgpgress = st.progress(0)
119
+ st.subheader(colorizedtext("red", yourquestion))
120
+ for i in range(100):
121
+ time.sleep(0.9)
122
+ prgpgress.progress(i+1)
123
+
124
+
125
+
126
+ answer = chain.run(input_documents=documents, question=yourquestion)
127
+ st.subheader(colorizedtext("blue", answer))
128
+ history()
129
+
130
+
131
+
132
+
133
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ openai
2
+ langchain
3
+ streamlit
4
+ PyPDF2
5
+ tiktoken
6
+ pypdf
7
+ chromadb