Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,6 +51,7 @@ def csv_logs(mytext, result, date_time):
|
|
51 |
|
52 |
def search_internet(question):
|
53 |
try:
|
|
|
54 |
params = {
|
55 |
"q": question,
|
56 |
"location": "Bengaluru, Karnataka, India",
|
@@ -101,6 +102,7 @@ def search_internet(question):
|
|
101 |
st.write(snippets)
|
102 |
except:
|
103 |
try:
|
|
|
104 |
params = {
|
105 |
"q": question,
|
106 |
"location": "Bengaluru, Karnataka, India",
|
@@ -150,17 +152,9 @@ def search_internet(question):
|
|
150 |
st.write(string_temp)
|
151 |
st.write(snippets)
|
152 |
except:
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
"hl": "hi",
|
157 |
-
"gl": "in",
|
158 |
-
"google_domain": "google.co.in",
|
159 |
-
# "api_key": ""
|
160 |
-
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
161 |
-
}
|
162 |
-
|
163 |
-
params = {
|
164 |
"q": question,
|
165 |
"location": "Bengaluru, Karnataka, India",
|
166 |
"hl": "hi",
|
@@ -168,36 +162,457 @@ def search_internet(question):
|
|
168 |
"google_domain": "google.co.in",
|
169 |
# "api_key": ""
|
170 |
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
171 |
-
|
172 |
-
|
173 |
-
search = GoogleSearch(params)
|
174 |
-
results = search.get_dict()
|
175 |
-
organic_results = results["organic_results"]
|
176 |
-
|
177 |
-
|
178 |
-
snippets = ""
|
179 |
-
counter = 1
|
180 |
-
for item in organic_results:
|
181 |
-
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
182 |
-
counter += 1
|
183 |
-
|
184 |
-
# snippets
|
185 |
-
|
186 |
-
response = openai.Completion.create(
|
187 |
-
model="text-davinci-003",
|
188 |
-
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
189 |
-
temperature=0.49,
|
190 |
-
max_tokens=256,
|
191 |
-
top_p=1,
|
192 |
-
frequency_penalty=0,
|
193 |
-
presence_penalty=0)
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
|
203 |
openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ['OPENAI_KEY']
|
|
|
51 |
|
52 |
def search_internet(question):
|
53 |
try:
|
54 |
+
st.text("Key 0 used")
|
55 |
params = {
|
56 |
"q": question,
|
57 |
"location": "Bengaluru, Karnataka, India",
|
|
|
102 |
st.write(snippets)
|
103 |
except:
|
104 |
try:
|
105 |
+
st.text("Key 1 used")
|
106 |
params = {
|
107 |
"q": question,
|
108 |
"location": "Bengaluru, Karnataka, India",
|
|
|
152 |
st.write(string_temp)
|
153 |
st.write(snippets)
|
154 |
except:
|
155 |
+
try:
|
156 |
+
st.text("Key 2 used")
|
157 |
+
params = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
"q": question,
|
159 |
"location": "Bengaluru, Karnataka, India",
|
160 |
"hl": "hi",
|
|
|
162 |
"google_domain": "google.co.in",
|
163 |
# "api_key": ""
|
164 |
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
165 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
params = {
|
168 |
+
"q": question,
|
169 |
+
"location": "Bengaluru, Karnataka, India",
|
170 |
+
"hl": "hi",
|
171 |
+
"gl": "in",
|
172 |
+
"google_domain": "google.co.in",
|
173 |
+
# "api_key": ""
|
174 |
+
"api_key": st.secrets["GOOGLE_API2"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
175 |
+
}
|
176 |
+
|
177 |
+
search = GoogleSearch(params)
|
178 |
+
results = search.get_dict()
|
179 |
+
organic_results = results["organic_results"]
|
180 |
+
|
181 |
+
|
182 |
+
snippets = ""
|
183 |
+
counter = 1
|
184 |
+
for item in organic_results:
|
185 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
186 |
+
counter += 1
|
187 |
+
|
188 |
+
# snippets
|
189 |
+
|
190 |
+
response = openai.Completion.create(
|
191 |
+
model="text-davinci-003",
|
192 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
193 |
+
temperature=0.49,
|
194 |
+
max_tokens=256,
|
195 |
+
top_p=1,
|
196 |
+
frequency_penalty=0,
|
197 |
+
presence_penalty=0)
|
198 |
+
|
199 |
+
now = datetime.datetime.now()
|
200 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
201 |
+
string_temp = response.choices[0].text
|
202 |
+
csv_logs(question, string_temp, date_time)
|
203 |
+
st.write(string_temp)
|
204 |
+
st.write(snippets)
|
205 |
+
except:
|
206 |
+
try:
|
207 |
+
st.text("Key 3 used")
|
208 |
+
params = {
|
209 |
+
"q": question,
|
210 |
+
"location": "Bengaluru, Karnataka, India",
|
211 |
+
"hl": "hi",
|
212 |
+
"gl": "in",
|
213 |
+
"google_domain": "google.co.in",
|
214 |
+
# "api_key": ""
|
215 |
+
"api_key": st.secrets["GOOGLE_API3"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
216 |
+
}
|
217 |
+
|
218 |
+
params = {
|
219 |
+
"q": question,
|
220 |
+
"location": "Bengaluru, Karnataka, India",
|
221 |
+
"hl": "hi",
|
222 |
+
"gl": "in",
|
223 |
+
"google_domain": "google.co.in",
|
224 |
+
# "api_key": ""
|
225 |
+
"api_key": st.secrets["GOOGLE_API3"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
226 |
+
}
|
227 |
+
|
228 |
+
search = GoogleSearch(params)
|
229 |
+
results = search.get_dict()
|
230 |
+
organic_results = results["organic_results"]
|
231 |
+
|
232 |
+
|
233 |
+
snippets = ""
|
234 |
+
counter = 1
|
235 |
+
for item in organic_results:
|
236 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
237 |
+
counter += 1
|
238 |
+
|
239 |
+
# snippets
|
240 |
+
|
241 |
+
response = openai.Completion.create(
|
242 |
+
model="text-davinci-003",
|
243 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
244 |
+
temperature=0.49,
|
245 |
+
max_tokens=256,
|
246 |
+
top_p=1,
|
247 |
+
frequency_penalty=0,
|
248 |
+
presence_penalty=0)
|
249 |
+
|
250 |
+
now = datetime.datetime.now()
|
251 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
252 |
+
string_temp = response.choices[0].text
|
253 |
+
csv_logs(question, string_temp, date_time)
|
254 |
+
st.write(string_temp)
|
255 |
+
st.write(snippets)
|
256 |
+
except:
|
257 |
+
try:
|
258 |
+
st.text("Key 4 used")
|
259 |
+
params = {
|
260 |
+
"q": question,
|
261 |
+
"location": "Bengaluru, Karnataka, India",
|
262 |
+
"hl": "hi",
|
263 |
+
"gl": "in",
|
264 |
+
"google_domain": "google.co.in",
|
265 |
+
# "api_key": ""
|
266 |
+
"api_key": st.secrets["GOOGLE_API4"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
267 |
+
}
|
268 |
+
|
269 |
+
params = {
|
270 |
+
"q": question,
|
271 |
+
"location": "Bengaluru, Karnataka, India",
|
272 |
+
"hl": "hi",
|
273 |
+
"gl": "in",
|
274 |
+
"google_domain": "google.co.in",
|
275 |
+
# "api_key": ""
|
276 |
+
"api_key": st.secrets["GOOGLE_API4"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
277 |
+
}
|
278 |
+
|
279 |
+
search = GoogleSearch(params)
|
280 |
+
results = search.get_dict()
|
281 |
+
organic_results = results["organic_results"]
|
282 |
+
|
283 |
+
|
284 |
+
snippets = ""
|
285 |
+
counter = 1
|
286 |
+
for item in organic_results:
|
287 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
288 |
+
counter += 1
|
289 |
+
|
290 |
+
# snippets
|
291 |
+
|
292 |
+
response = openai.Completion.create(
|
293 |
+
model="text-davinci-003",
|
294 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
295 |
+
temperature=0.49,
|
296 |
+
max_tokens=256,
|
297 |
+
top_p=1,
|
298 |
+
frequency_penalty=0,
|
299 |
+
presence_penalty=0)
|
300 |
+
|
301 |
+
now = datetime.datetime.now()
|
302 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
303 |
+
string_temp = response.choices[0].text
|
304 |
+
csv_logs(question, string_temp, date_time)
|
305 |
+
st.write(string_temp)
|
306 |
+
st.write(snippets)
|
307 |
+
except:
|
308 |
+
try:
|
309 |
+
st.text("Key 5 used")
|
310 |
+
params = {
|
311 |
+
"q": question,
|
312 |
+
"location": "Bengaluru, Karnataka, India",
|
313 |
+
"hl": "hi",
|
314 |
+
"gl": "in",
|
315 |
+
"google_domain": "google.co.in",
|
316 |
+
# "api_key": ""
|
317 |
+
"api_key": st.secrets["GOOGLE_API5"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
318 |
+
}
|
319 |
+
|
320 |
+
params = {
|
321 |
+
"q": question,
|
322 |
+
"location": "Bengaluru, Karnataka, India",
|
323 |
+
"hl": "hi",
|
324 |
+
"gl": "in",
|
325 |
+
"google_domain": "google.co.in",
|
326 |
+
# "api_key": ""
|
327 |
+
"api_key": st.secrets["GOOGLE_API5"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
328 |
+
}
|
329 |
+
|
330 |
+
search = GoogleSearch(params)
|
331 |
+
results = search.get_dict()
|
332 |
+
organic_results = results["organic_results"]
|
333 |
+
|
334 |
+
|
335 |
+
snippets = ""
|
336 |
+
counter = 1
|
337 |
+
for item in organic_results:
|
338 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
339 |
+
counter += 1
|
340 |
+
|
341 |
+
# snippets
|
342 |
+
|
343 |
+
response = openai.Completion.create(
|
344 |
+
model="text-davinci-003",
|
345 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
346 |
+
temperature=0.49,
|
347 |
+
max_tokens=256,
|
348 |
+
top_p=1,
|
349 |
+
frequency_penalty=0,
|
350 |
+
presence_penalty=0)
|
351 |
+
|
352 |
+
now = datetime.datetime.now()
|
353 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
354 |
+
string_temp = response.choices[0].text
|
355 |
+
csv_logs(question, string_temp, date_time)
|
356 |
+
st.write(string_temp)
|
357 |
+
st.write(snippets)
|
358 |
+
except:
|
359 |
+
try:
|
360 |
+
st.text("Key 6 used")
|
361 |
+
params = {
|
362 |
+
"q": question,
|
363 |
+
"location": "Bengaluru, Karnataka, India",
|
364 |
+
"hl": "hi",
|
365 |
+
"gl": "in",
|
366 |
+
"google_domain": "google.co.in",
|
367 |
+
# "api_key": ""
|
368 |
+
"api_key": st.secrets["GOOGLE_API6"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
369 |
+
}
|
370 |
+
|
371 |
+
params = {
|
372 |
+
"q": question,
|
373 |
+
"location": "Bengaluru, Karnataka, India",
|
374 |
+
"hl": "hi",
|
375 |
+
"gl": "in",
|
376 |
+
"google_domain": "google.co.in",
|
377 |
+
# "api_key": ""
|
378 |
+
"api_key": st.secrets["GOOGLE_API6"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
379 |
+
}
|
380 |
+
|
381 |
+
search = GoogleSearch(params)
|
382 |
+
results = search.get_dict()
|
383 |
+
organic_results = results["organic_results"]
|
384 |
+
|
385 |
+
|
386 |
+
snippets = ""
|
387 |
+
counter = 1
|
388 |
+
for item in organic_results:
|
389 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
390 |
+
counter += 1
|
391 |
+
|
392 |
+
# snippets
|
393 |
+
|
394 |
+
response = openai.Completion.create(
|
395 |
+
model="text-davinci-003",
|
396 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
397 |
+
temperature=0.49,
|
398 |
+
max_tokens=256,
|
399 |
+
top_p=1,
|
400 |
+
frequency_penalty=0,
|
401 |
+
presence_penalty=0)
|
402 |
+
|
403 |
+
now = datetime.datetime.now()
|
404 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
405 |
+
string_temp = response.choices[0].text
|
406 |
+
csv_logs(question, string_temp, date_time)
|
407 |
+
st.write(string_temp)
|
408 |
+
st.write(snippets)
|
409 |
+
except:
|
410 |
+
try:
|
411 |
+
st.text("Key 7 used")
|
412 |
+
params = {
|
413 |
+
"q": question,
|
414 |
+
"location": "Bengaluru, Karnataka, India",
|
415 |
+
"hl": "hi",
|
416 |
+
"gl": "in",
|
417 |
+
"google_domain": "google.co.in",
|
418 |
+
# "api_key": ""
|
419 |
+
"api_key": st.secrets["GOOGLE_API7"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
420 |
+
}
|
421 |
+
|
422 |
+
params = {
|
423 |
+
"q": question,
|
424 |
+
"location": "Bengaluru, Karnataka, India",
|
425 |
+
"hl": "hi",
|
426 |
+
"gl": "in",
|
427 |
+
"google_domain": "google.co.in",
|
428 |
+
# "api_key": ""
|
429 |
+
"api_key": st.secrets["GOOGLE_API7"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
430 |
+
}
|
431 |
+
|
432 |
+
search = GoogleSearch(params)
|
433 |
+
results = search.get_dict()
|
434 |
+
organic_results = results["organic_results"]
|
435 |
+
|
436 |
+
|
437 |
+
snippets = ""
|
438 |
+
counter = 1
|
439 |
+
for item in organic_results:
|
440 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
441 |
+
counter += 1
|
442 |
+
|
443 |
+
# snippets
|
444 |
+
|
445 |
+
response = openai.Completion.create(
|
446 |
+
model="text-davinci-003",
|
447 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
448 |
+
temperature=0.49,
|
449 |
+
max_tokens=256,
|
450 |
+
top_p=1,
|
451 |
+
frequency_penalty=0,
|
452 |
+
presence_penalty=0)
|
453 |
+
|
454 |
+
now = datetime.datetime.now()
|
455 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
456 |
+
string_temp = response.choices[0].text
|
457 |
+
csv_logs(question, string_temp, date_time)
|
458 |
+
st.write(string_temp)
|
459 |
+
st.write(snippets)
|
460 |
+
except:
|
461 |
+
try:
|
462 |
+
st.text("Key 8 used")
|
463 |
+
params = {
|
464 |
+
"q": question,
|
465 |
+
"location": "Bengaluru, Karnataka, India",
|
466 |
+
"hl": "hi",
|
467 |
+
"gl": "in",
|
468 |
+
"google_domain": "google.co.in",
|
469 |
+
# "api_key": ""
|
470 |
+
"api_key": st.secrets["GOOGLE_API8"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
471 |
+
}
|
472 |
+
|
473 |
+
params = {
|
474 |
+
"q": question,
|
475 |
+
"location": "Bengaluru, Karnataka, India",
|
476 |
+
"hl": "hi",
|
477 |
+
"gl": "in",
|
478 |
+
"google_domain": "google.co.in",
|
479 |
+
# "api_key": ""
|
480 |
+
"api_key": st.secrets["GOOGLE_API8"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
481 |
+
}
|
482 |
+
|
483 |
+
search = GoogleSearch(params)
|
484 |
+
results = search.get_dict()
|
485 |
+
organic_results = results["organic_results"]
|
486 |
+
|
487 |
+
|
488 |
+
snippets = ""
|
489 |
+
counter = 1
|
490 |
+
for item in organic_results:
|
491 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
492 |
+
counter += 1
|
493 |
+
|
494 |
+
# snippets
|
495 |
+
|
496 |
+
response = openai.Completion.create(
|
497 |
+
model="text-davinci-003",
|
498 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
499 |
+
temperature=0.49,
|
500 |
+
max_tokens=256,
|
501 |
+
top_p=1,
|
502 |
+
frequency_penalty=0,
|
503 |
+
presence_penalty=0)
|
504 |
+
|
505 |
+
now = datetime.datetime.now()
|
506 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
507 |
+
string_temp = response.choices[0].text
|
508 |
+
csv_logs(question, string_temp, date_time)
|
509 |
+
st.write(string_temp)
|
510 |
+
st.write(snippets)
|
511 |
+
except:
|
512 |
+
try:
|
513 |
+
st.text("Key 9 used")
|
514 |
+
params = {
|
515 |
+
"q": question,
|
516 |
+
"location": "Bengaluru, Karnataka, India",
|
517 |
+
"hl": "hi",
|
518 |
+
"gl": "in",
|
519 |
+
"google_domain": "google.co.in",
|
520 |
+
# "api_key": ""
|
521 |
+
"api_key": st.secrets["GOOGLE_API9"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
522 |
+
}
|
523 |
+
|
524 |
+
params = {
|
525 |
+
"q": question,
|
526 |
+
"location": "Bengaluru, Karnataka, India",
|
527 |
+
"hl": "hi",
|
528 |
+
"gl": "in",
|
529 |
+
"google_domain": "google.co.in",
|
530 |
+
# "api_key": ""
|
531 |
+
"api_key": st.secrets["GOOGLE_API9"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
532 |
+
}
|
533 |
+
|
534 |
+
search = GoogleSearch(params)
|
535 |
+
results = search.get_dict()
|
536 |
+
organic_results = results["organic_results"]
|
537 |
+
|
538 |
+
|
539 |
+
snippets = ""
|
540 |
+
counter = 1
|
541 |
+
for item in organic_results:
|
542 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
543 |
+
counter += 1
|
544 |
+
|
545 |
+
# snippets
|
546 |
+
|
547 |
+
response = openai.Completion.create(
|
548 |
+
model="text-davinci-003",
|
549 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
550 |
+
temperature=0.49,
|
551 |
+
max_tokens=256,
|
552 |
+
top_p=1,
|
553 |
+
frequency_penalty=0,
|
554 |
+
presence_penalty=0)
|
555 |
+
|
556 |
+
now = datetime.datetime.now()
|
557 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
558 |
+
string_temp = response.choices[0].text
|
559 |
+
csv_logs(question, string_temp, date_time)
|
560 |
+
st.write(string_temp)
|
561 |
+
st.write(snippets)
|
562 |
+
except:
|
563 |
+
try:
|
564 |
+
st.text("Key 10 used")
|
565 |
+
params = {
|
566 |
+
"q": question,
|
567 |
+
"location": "Bengaluru, Karnataka, India",
|
568 |
+
"hl": "hi",
|
569 |
+
"gl": "in",
|
570 |
+
"google_domain": "google.co.in",
|
571 |
+
# "api_key": ""
|
572 |
+
"api_key": st.secrets["GOOGLE_API10"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
573 |
+
}
|
574 |
+
|
575 |
+
params = {
|
576 |
+
"q": question,
|
577 |
+
"location": "Bengaluru, Karnataka, India",
|
578 |
+
"hl": "hi",
|
579 |
+
"gl": "in",
|
580 |
+
"google_domain": "google.co.in",
|
581 |
+
# "api_key": ""
|
582 |
+
"api_key": st.secrets["GOOGLE_API10"] #os.environ("GOOGLE_API") #os.environ['GOOGLE_API']
|
583 |
+
}
|
584 |
+
|
585 |
+
search = GoogleSearch(params)
|
586 |
+
results = search.get_dict()
|
587 |
+
organic_results = results["organic_results"]
|
588 |
+
|
589 |
+
|
590 |
+
snippets = ""
|
591 |
+
counter = 1
|
592 |
+
for item in organic_results:
|
593 |
+
snippets += str(counter) + ". " + item.get("snippet", "") + '\n' + item['about_this_result']['source']['source_info_link'] + '\n'
|
594 |
+
counter += 1
|
595 |
+
|
596 |
+
# snippets
|
597 |
+
|
598 |
+
response = openai.Completion.create(
|
599 |
+
model="text-davinci-003",
|
600 |
+
prompt=f'''following are snippets from google search with these as knowledge base only answer questions and print reference link as well followed by answer. \n\n {snippets}\n\n question-{question}\n\nAnswer-''',
|
601 |
+
temperature=0.49,
|
602 |
+
max_tokens=256,
|
603 |
+
top_p=1,
|
604 |
+
frequency_penalty=0,
|
605 |
+
presence_penalty=0)
|
606 |
+
|
607 |
+
now = datetime.datetime.now()
|
608 |
+
date_time = now.strftime("%Y-%m-%d %H:%M:%S")
|
609 |
+
string_temp = response.choices[0].text
|
610 |
+
csv_logs(question, string_temp, date_time)
|
611 |
+
st.write(string_temp)
|
612 |
+
st.write(snippets)
|
613 |
+
except:
|
614 |
+
pass
|
615 |
+
|
616 |
|
617 |
|
618 |
openai.api_key = st.secrets["OPENAI_KEY"] #os.environ("OPENAI_KEY") #os.environ['OPENAI_KEY']
|