Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -280,7 +280,35 @@ def compress_data_og(c, instruct, history):
|
|
| 280 |
return resp
|
| 281 |
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
def summarize(inp,history,report_check,sum_check,mem_check,data=None,files=None,url=None,pdf_url=None,pdf_batch=None):
|
| 285 |
json_box=[]
|
| 286 |
if inp == "":
|
|
@@ -643,8 +671,24 @@ def save_memory(purpose, history):
|
|
| 643 |
out_box.append(resp)
|
| 644 |
create_index()
|
| 645 |
return out_box
|
| 646 |
-
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
|
| 649 |
|
| 650 |
|
|
@@ -680,8 +724,13 @@ with gr.Blocks() as app:
|
|
| 680 |
pdf_url = gr.Textbox(label="PDF URL")
|
| 681 |
with gr.Tab("PDF Batch"):
|
| 682 |
pdf_batch = gr.Textbox(label="PDF URL Batch (comma separated)")
|
|
|
|
|
|
|
|
|
|
| 683 |
json_out=gr.JSON()
|
| 684 |
e_box=gr.Textbox()
|
|
|
|
|
|
|
| 685 |
#text=gr.JSON()
|
| 686 |
#inp_query.change(search_models,inp_query,models_dd)
|
| 687 |
clear_btn.click(clear_fn,None,[prompt,chatbot])
|
|
|
|
| 280 |
return resp
|
| 281 |
|
| 282 |
|
| 283 |
+
RECALL_MEMORY="""
|
| 284 |
+
The user will give you a query, and you will pick keywords from the provided KEYWORD LIST that will be used to search for information about the query.
|
| 285 |
+
Your response will be only a list of keywords.
|
| 286 |
+
Example Response:
|
| 287 |
+
[keyword1,keyword2,keyword3]
|
| 288 |
|
| 289 |
+
USER QUERY:
|
| 290 |
+
{prompt}
|
| 291 |
+
|
| 292 |
+
KEYWORD LIST:
|
| 293 |
+
{keywords}
|
| 294 |
+
"""
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def get_mem(prompt,kw):
|
| 300 |
+
seed=random.randint(1,1000000000)
|
| 301 |
+
resp = run_gpt(
|
| 302 |
+
RECALL_MEMORY.format(keywords=kw,prompt=prompt),
|
| 303 |
+
stop_tokens=[],
|
| 304 |
+
max_tokens=1024,
|
| 305 |
+
seed=seed,
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
print (resp)
|
| 309 |
+
return resp
|
| 310 |
+
|
| 311 |
+
|
| 312 |
def summarize(inp,history,report_check,sum_check,mem_check,data=None,files=None,url=None,pdf_url=None,pdf_batch=None):
|
| 313 |
json_box=[]
|
| 314 |
if inp == "":
|
|
|
|
| 671 |
out_box.append(resp)
|
| 672 |
create_index()
|
| 673 |
return out_box
|
| 674 |
+
def recall_memory(inp,history)
|
| 675 |
+
error_box=""
|
| 676 |
+
json_out={}
|
| 677 |
+
r = requests.get(f'{save_data}mem-test2/index.json')
|
| 678 |
+
print(f'status code main:: {r.status_code}')
|
| 679 |
+
if r.status_code==200:
|
| 680 |
+
mem = json.loads(r.text)
|
| 681 |
+
print (f'ind::\n{mem}')
|
| 682 |
+
if not r.status_code==200:
|
| 683 |
+
print("Create new IND")
|
| 684 |
+
out="MEMORY FILE NOT FOUND"
|
| 685 |
+
return out,out,out,out
|
| 686 |
+
mem_keys = mem.keys()
|
| 687 |
+
rawp = get_mem(inp,mem_keys)
|
| 688 |
+
|
| 689 |
+
history.clear()
|
| 690 |
+
history.append((inp,rawp))
|
| 691 |
+
yield "", history,error_box,json_out
|
| 692 |
|
| 693 |
|
| 694 |
|
|
|
|
| 724 |
pdf_url = gr.Textbox(label="PDF URL")
|
| 725 |
with gr.Tab("PDF Batch"):
|
| 726 |
pdf_batch = gr.Textbox(label="PDF URL Batch (comma separated)")
|
| 727 |
+
with gr.Tab("Memory"):
|
| 728 |
+
mem_inp = gr.Textbox(label="Query")
|
| 729 |
+
mem = gr.Button()
|
| 730 |
json_out=gr.JSON()
|
| 731 |
e_box=gr.Textbox()
|
| 732 |
+
|
| 733 |
+
mem.click(recall_memory,mem_inp,[prompt,chatbot,e_box,json_out])
|
| 734 |
#text=gr.JSON()
|
| 735 |
#inp_query.change(search_models,inp_query,models_dd)
|
| 736 |
clear_btn.click(clear_fn,None,[prompt,chatbot])
|