Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,9 +25,22 @@ st.header("Welcome!. Today, What company's sustainability story is inspiring you
|
|
25 |
|
26 |
myurl = st.text_input("Give the URL to find a sustainability or annual report", "Type URL of any company PDF document here")
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
loader1 = PyPDFLoader(myurl)
|
32 |
langchainembeddings = OpenAIEmbeddings(deployment="textembedding", chunk_size=1)
|
33 |
|
@@ -45,26 +58,7 @@ if st.button("Load this report "):
|
|
45 |
st.write(index)
|
46 |
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
yourquestion = st.text_input('Ask your question on best practices', 'What is Wipro plans for Biodiversity in 2024?')
|
54 |
-
st.write('Your input is ', yourquestion)
|
55 |
-
|
56 |
-
aimethod = st.radio(
|
57 |
-
"Choose a AI brain",
|
58 |
-
('GPT3', 'GPT3.5' ), index=1)
|
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 |
-
llmchatgpt = AzureOpenAI( deployment_name="esujnand", model_name="gpt-35-turbo" )
|
66 |
-
|
67 |
-
if st.button("Ask Best practices "):
|
68 |
answer = index.query(llm=llmchatgpt, question=yourquestion, chain_type="map_reduce")
|
69 |
st.write(answer)
|
70 |
|
@@ -80,59 +74,7 @@ if aimethod == '4 minutes AI method refine':
|
|
80 |
mychain_type = "refine"
|
81 |
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
loader1 = PyPDFLoader(url)
|
86 |
-
|
87 |
-
|
88 |
-
def history():
|
89 |
-
mycount = 0
|
90 |
-
if 'count' not in st.session_state:
|
91 |
-
st.session_state['count'] = 0
|
92 |
-
else:
|
93 |
-
mycount = st.session_state['count']
|
94 |
-
|
95 |
-
if True:
|
96 |
-
st.write(mycount)
|
97 |
-
mycount = mycount + 1
|
98 |
-
st.session_state['count'] = mycount
|
99 |
-
for i in range(mycount):
|
100 |
-
mystatekeyindex = "element" + str(i)
|
101 |
-
mystatekeyanswerindex = "elementANS" + str(i)
|
102 |
-
if mystatekeyindex not in st.session_state:
|
103 |
-
st.session_state[mystatekeyindex] = yourquestion
|
104 |
-
st.session_state[mystatekeyanswerindex] = answer
|
105 |
-
if mystatekeyindex in st.session_state:
|
106 |
-
with st.expander(st.session_state[mystatekeyindex]):
|
107 |
-
st.write( st.session_state[mystatekeyanswerindex] )
|
108 |
-
|
109 |
-
|
110 |
-
def colorizedtext(acolor, astring):
|
111 |
-
formattedcolor = ":" + acolor + "[" + astring + "]"
|
112 |
-
return formattedcolor
|
113 |
-
|
114 |
|
115 |
|
116 |
-
if st.button("Ask QA "):
|
117 |
-
documents = loader1.load()
|
118 |
-
answer = ""
|
119 |
-
with st.spinner(" Finding answer for your question .... AI will get you answer in 2 more minutes... " ):
|
120 |
-
with st.expander( "Employing your choice of AI method ... " + aimethod + "..."):
|
121 |
-
st.write(str(chain)[:700])
|
122 |
-
st.write("AI is reading this [link](%s)" % url)
|
123 |
-
prgpgress = st.progress(0)
|
124 |
-
st.subheader(colorizedtext("red", yourquestion))
|
125 |
-
for i in range(100):
|
126 |
-
time.sleep(0.9)
|
127 |
-
prgpgress.progress(i+1)
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
answer = chain.run(input_documents=documents, question=yourquestion)
|
132 |
-
st.subheader(colorizedtext("blue", answer))
|
133 |
-
history()
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
|
138 |
|
|
|
25 |
|
26 |
myurl = st.text_input("Give the URL to find a sustainability or annual report", "Type URL of any company PDF document here")
|
27 |
|
28 |
+
yourquestion = st.text_input('Ask your question on best practices', 'What is Wipro plans for Biodiversity in 2024?')
|
29 |
+
st.write('Your input is ', yourquestion)
|
30 |
+
|
31 |
+
aimethod = st.radio(
|
32 |
+
"Choose a AI brain",
|
33 |
+
('GPT3', 'GPT3.5' ), index=1)
|
34 |
|
35 |
+
|
36 |
+
os.environ['OPENAI_API_TYPE'] = 'azure'
|
37 |
+
os.environ['OPENAI_API_VERSION'] = '2023-03-15-preview'
|
38 |
+
|
39 |
+
#llmgpt3 = AzureOpenAI( deployment_name="testdavanci", model_name="text-davinci-003" )
|
40 |
+
llmchatgpt = AzureOpenAI( deployment_name="esujnand", model_name="gpt-35-turbo" )
|
41 |
+
|
42 |
+
if myurl:
|
43 |
+
index = None
|
44 |
loader1 = PyPDFLoader(myurl)
|
45 |
langchainembeddings = OpenAIEmbeddings(deployment="textembedding", chunk_size=1)
|
46 |
|
|
|
58 |
st.write(index)
|
59 |
|
60 |
|
61 |
+
if yourquestion:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
answer = index.query(llm=llmchatgpt, question=yourquestion, chain_type="map_reduce")
|
63 |
st.write(answer)
|
64 |
|
|
|
74 |
mychain_type = "refine"
|
75 |
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
|