Omnibus commited on
Commit
07422cb
·
verified ·
1 Parent(s): ee382c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -55
app.py CHANGED
@@ -8,7 +8,7 @@ import random
8
  import json
9
  import datetime
10
  import xmltodict
11
- """
12
  from prompts import (
13
  COMPRESS_HISTORY_PROMPT,
14
  COMPRESS_DATA_PROMPT,
@@ -112,7 +112,7 @@ def compress_data(c,purpose, task, history, result):
112
  hist = history[s:e]
113
 
114
  resp = run_gpt(
115
- COMPRESS_DATA_PROMPT,
116
  stop_tokens=["observation:", "task:", "action:", "thought:"],
117
  max_tokens=2048,
118
  seed=seed,
@@ -142,61 +142,46 @@ def compress_data(c,purpose, task, history, result):
142
  history = "result: {}\n".format(resp)
143
  return history
144
 
145
- def find_all(purpose,task,history, rss_url, result):
146
- return_list=[]
147
- #if action_input in query.tasks:
148
- print (f"trying URL:: {rss_url}")
149
- lod=""
150
- try:
151
- if rss_url != "" and rss_url != None:
152
- #rawp = []
153
- out = []
154
- r = requests.get(f'{rss_url}')
155
- if ".json" in rss_url:
156
- lod = json.loads(r.text)
157
- if ".xml" in rss_url:
158
- lod = xmltodict.parse(r.content)
159
- if ".rss" in rss_url:
160
- lod = xmltodict.parse(r.content)
161
- else:
162
- try:
163
- lod = xmltodict.parse(r.content)
164
- except Exception as e:
165
- history+=f"observation: could not complete RSS Search due to this error:\n{e}"
166
- return "MAIN", None, history, task, result
167
- rawp = lod
168
- print(f'RAWP::\n{rawp}')
169
- cnt=0
170
- cnt+=len(rawp)
171
- out.append(rawp)
172
- out = str(out)
173
  rl = len(out)
174
  print(f'rl:: {rl}')
175
- c=0
176
  for i in str(out):
177
- c +=1
178
- print (f'c:: {c}')
179
- if c > MAX_HISTORY:
180
- print("compressing...")
181
- rawp = compress_data(c,purpose,task,out,result)
182
- else:
183
- rawp = out
184
- result += rawp
185
-
186
- print (rawp)
187
- print (f'out:: {out}')
188
- history = "observation: the search results are:\n {}\n".format(rawp)
189
- task = "compile report and return action: COMPLETE"
190
- return "MAIN", None, history, task, result
191
- else:
192
- history += "observation: An Error occured\nI need to trigger a search using the following syntax:\naction: READ-RSS action_input=URL\n"
193
- return "UPDATE-TASK", None, history, task, result
194
- except Exception as e:
195
- print (e)
196
- history += "observation: I need to trigger a search using the following syntax:\naction: READ-RSS action_input=URL\n"
197
- return "UPDATE-TASK", None, history, task, result
198
- return "MAIN", None, history, task, result
199
- """
200
  def find_rss():
201
  lod=""
202
  out_box=[]
@@ -280,6 +265,6 @@ with gr.Blocks() as app:
280
  fil = gr.Textbox()
281
  r_btn.click(find_rss,None,[out_json,cb])
282
  #r_btn.click(read_rss,None,[out_json,fil])
283
- #search_btn.click(find_rss,rss_search,out_json)
284
  #btn.click(get_rss,rss,out_json)
285
  app.launch()
 
8
  import json
9
  import datetime
10
  import xmltodict
11
+
12
  from prompts import (
13
  COMPRESS_HISTORY_PROMPT,
14
  COMPRESS_DATA_PROMPT,
 
112
  hist = history[s:e]
113
 
114
  resp = run_gpt(
115
+ COMPRESS_DATA_PROMPT_SMALL,
116
  stop_tokens=["observation:", "task:", "action:", "thought:"],
117
  max_tokens=2048,
118
  seed=seed,
 
142
  history = "result: {}\n".format(resp)
143
  return history
144
 
145
+
146
+
147
+ def summarize(inp,history,data=None):
148
+ json_box=[]
149
+ if inp == "":
150
+ inp = "Process this data"
151
+ history.clear()
152
+ history = [(inp,"Working on it...")]
153
+ yield "",history
154
+
155
+ if data != "Error" and data != "":
156
+ print(inp)
157
+ out = str(data)
158
+ rl = len(out)
159
+ print(f'rl:: {rl}')
160
+ c=1
161
+ for i in str(out):
162
+ if i == " " or i=="," or i=="\n":
163
+ c +=1
164
+ print (f'c:: {c}')
165
+
166
+ json_out = compress_data(c,inp,out)
167
+ out = str(json_out)
168
+ if report_check:
 
 
 
 
169
  rl = len(out)
170
  print(f'rl:: {rl}')
171
+ c=1
172
  for i in str(out):
173
+ if i == " " or i=="," or i=="\n":
174
+ c +=1
175
+ print (f'c2:: {c}')
176
+ rawp = compress_data_og(c,inp,out)
177
+ else:
178
+ rawp = out
179
+ else:
180
+ rawp = "Provide a valid data source"
181
+ history.append((inp,rawp))
182
+ yield "", history
183
+
184
+
 
 
 
 
 
 
 
 
 
 
 
185
  def find_rss():
186
  lod=""
187
  out_box=[]
 
265
  fil = gr.Textbox()
266
  r_btn.click(find_rss,None,[out_json,cb])
267
  #r_btn.click(read_rss,None,[out_json,fil])
268
+ search_btn.click(summarize,[rss_search,cb,out_json],[rss_search,cb])
269
  #btn.click(get_rss,rss,out_json)
270
  app.launch()