Omnibus commited on
Commit
7e4fb7d
·
1 Parent(s): 33fa1b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -5
app.py CHANGED
@@ -19,13 +19,64 @@ from agent import (
19
  )
20
  api=HfApi()
21
 
22
-
23
-
24
  client = InferenceClient(
25
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
26
  )
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
 
 
 
 
29
 
30
  def read_txt(txt_path):
31
  text=""
@@ -154,13 +205,18 @@ def compress_data(c, instruct, history):
154
 
155
 
156
 
157
- def summarize(inp,history,data=None,file=None):
158
  if inp == "":
159
  inp = "Process this data"
160
-
161
-
162
  history = [(inp,"Working on it...")] if not history else history
163
  yield "",history
 
 
 
 
 
 
 
164
  if file:
165
  try:
166
  print (file)
 
19
  )
20
  api=HfApi()
21
 
 
 
22
  client = InferenceClient(
23
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
24
  )
25
 
26
+ def find_all(url):
27
+ return_list=[]
28
+ print (url)
29
+ #if action_input in query.tasks:
30
+ print (f"trying URL:: {url}")
31
+ try:
32
+ if url != "" and url != None:
33
+ out = []
34
+ source = requests.get(url)
35
+ #source = urllib.request.urlopen(url).read()
36
+ soup = bs4.BeautifulSoup(source.content,'lxml')
37
+ # title of the page
38
+ print(soup.title)
39
+ # get attributes:
40
+ print(soup.title.name)
41
+ # get values:
42
+ print(soup.title.string)
43
+ # beginning navigation:
44
+ print(soup.title.parent.name)
45
+ #rawp.append([tag.name for tag in soup.find_all()] )
46
+ print([tag.name for tag in soup.find_all()])
47
+ rawp=(f'RAW TEXT RETURNED: {soup.text}')
48
+ out.append(rawp)
49
+ q=("a","p","span","content","article")
50
+ for p in soup.find_all(q):
51
+ out.append([{q:p.string,"parent":p.parent.name,"previous":[b for b in p.previous],"first-child":[b.name for b in p.children],"content":p}])
52
+ print (f'OUT :: {out}')
53
+ '''
54
+ c=0
55
+ out = str(out)
56
+ rl = len(out)
57
+ print(f'rl:: {rl}')
58
+ #for ea in out:
59
+ for i in str(out):
60
+ if i == " " or i=="," or i=="\n":
61
+ c +=1
62
+ print (f'c:: {c}')
63
+ if rl > MAX_DATA:
64
+ print("compressing...")
65
+ rawp = compress_data(c,purpose,task,out)
66
+ print (rawp)
67
+ print (f'out:: {out}')
68
+ '''
69
+ return True, rawp
70
+ else:
71
+ return False, "Enter Valid URL"
72
+ except Exception as e:
73
+ print (e)
74
+ return False, f'Error: {e}'
75
 
76
+ #else:
77
+ # history = "observation: The search query I used did not return a valid response"
78
+
79
+ return "MAIN", None, history, task
80
 
81
  def read_txt(txt_path):
82
  text=""
 
205
 
206
 
207
 
208
+ def summarize(inp,history,data=None,file=None,url=None):
209
  if inp == "":
210
  inp = "Process this data"
 
 
211
  history = [(inp,"Working on it...")] if not history else history
212
  yield "",history
213
+ if url != "":
214
+ val, out = find_all(url)
215
+ if not val:
216
+ data="Error"
217
+ rawp = out
218
+ else:
219
+ rawp=out
220
  if file:
221
  try:
222
  print (file)