Omnibus commited on
Commit
98ae583
·
verified ·
1 Parent(s): e8cb9e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -29
app.py CHANGED
@@ -235,36 +235,42 @@ def find_all(purpose,task,history, url, result):
235
  if url != "" and url != None:
236
  out = []
237
  source = requests.get(url)
238
- soup = bs4.BeautifulSoup(source.content,'lxml')
239
-
240
- rawp=(f'RAW TEXT RETURNED: {soup.text}')
241
- cnt=0
242
- cnt+=len(rawp)
243
- out.append(rawp)
244
- out.append("HTML fragments: ")
245
- q=("a","p","span","content","article")
246
- for p in soup.find_all("a"):
247
- out.append([{"LINK TITLE":p.get('title'),"URL":p.get('href'),"STRING":p.string}])
248
- c=0
249
- out = str(out)
250
- rl = len(out)
251
- print(f'rl:: {rl}')
252
- for i in str(out):
253
- if i == " " or i=="," or i=="\n" or i=="/" or i=="." or i=="<":
254
- c +=1
255
- print (f'c:: {c}')
256
- if c > MAX_HISTORY:
257
- print("compressing...")
258
- rawp = compress_data(c,purpose,task,out,result)
 
 
 
 
 
 
 
 
 
 
259
  else:
260
- rawp = out
261
- result += rawp
262
-
263
- #print (rawp)
264
- #print (f'out:: {out}')
265
- history += "observation: the search results are:\n {}\n".format(rawp)
266
- task = "compile report or complete?"
267
- return "MAIN", None, history, task, result
268
  else:
269
  history += "observation: An Error occured\nI need to trigger a search using the following syntax:\naction: SCRAPE_WEBSITE action_input=URL\n"
270
  return "MAIN", None, history, task, result
 
235
  if url != "" and url != None:
236
  out = []
237
  source = requests.get(url)
238
+ if source.status_code ==200:
239
+ soup = bs4.BeautifulSoup(source.content,'lxml')
240
+
241
+ rawp=(f'RAW TEXT RETURNED: {soup.text}')
242
+ cnt=0
243
+ cnt+=len(rawp)
244
+ out.append(rawp)
245
+ out.append("HTML fragments: ")
246
+ q=("a","p","span","content","article")
247
+ for p in soup.find_all("a"):
248
+ out.append([{"LINK TITLE":p.get('title'),"URL":p.get('href'),"STRING":p.string}])
249
+ c=0
250
+ out = str(out)
251
+ rl = len(out)
252
+ print(f'rl:: {rl}')
253
+ for i in str(out):
254
+ if i == " " or i=="," or i=="\n" or i=="/" or i=="." or i=="<":
255
+ c +=1
256
+ print (f'c:: {c}')
257
+ if c > MAX_HISTORY:
258
+ print("compressing...")
259
+ rawp = compress_data(c,purpose,task,out,result)
260
+ else:
261
+ rawp = out
262
+ result += rawp
263
+
264
+ #print (rawp)
265
+ #print (f'out:: {out}')
266
+ history += "observation: the search results are:\n {}\n".format(rawp)
267
+ task = "compile report or complete?"
268
+ return "MAIN", None, history, task, result
269
  else:
270
+ history += f"observation: That URL string returned an error: {source.status_code}, I should try a different URL string\n"
271
+ result+="Still Working..."
272
+ return "MAIN", None, history, task, result
273
+
 
 
 
 
274
  else:
275
  history += "observation: An Error occured\nI need to trigger a search using the following syntax:\naction: SCRAPE_WEBSITE action_input=URL\n"
276
  return "MAIN", None, history, task, result