Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
else:
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
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
|