Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -394,7 +394,7 @@ def format_json(inp):
|
|
394 |
return out_json
|
395 |
|
396 |
|
397 |
-
|
398 |
def summarize(inp,history,report_check,chart_check,data=None,files=None,directory=None,url=None,pdf_url=None,pdf_batch=None):
|
399 |
json_box=[]
|
400 |
error_box=""
|
@@ -404,6 +404,124 @@ def summarize(inp,history,report_check,chart_check,data=None,files=None,director
|
|
404 |
history = [(inp,"Working on it...")]
|
405 |
yield "",history,error_box,json_box
|
406 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
if pdf_batch.startswith("http"):
|
408 |
c=0
|
409 |
data=""
|
@@ -496,11 +614,19 @@ def summarize(inp,history,report_check,chart_check,data=None,files=None,director
|
|
496 |
history.append((inp,rawp))
|
497 |
yield "", history,error_box,json_out
|
498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
#################################
|
500 |
def clear_fn():
|
501 |
return "",[(None,None)]
|
502 |
|
503 |
with gr.Blocks() as app:
|
|
|
504 |
gr.HTML("""<center><h1>Mixtral 8x7B TLDR Summarizer + Web</h1><h3>Summarize Data of unlimited length</h3>""")
|
505 |
chatbot = gr.Chatbot(label="Mixtral 8x7B Chatbot",show_copy_button=True)
|
506 |
with gr.Row():
|
@@ -509,7 +635,8 @@ with gr.Blocks() as app:
|
|
509 |
with gr.Column(scale=1):
|
510 |
report_check=gr.Checkbox(label="Return Report", value=False)
|
511 |
chart_check=gr.Checkbox(label="Return Chart", value=False)
|
512 |
-
|
|
|
513 |
|
514 |
#models_dd=gr.Dropdown(choices=[m for m in return_list],interactive=True)
|
515 |
with gr.Row():
|
@@ -535,7 +662,8 @@ with gr.Blocks() as app:
|
|
535 |
clear_btn.click(clear_fn,None,[prompt,chatbot])
|
536 |
|
537 |
#go=button.click(summarize,[prompt,chatbot,report_check,chart_check,data,file,directory,url,pdf_url,pdf_batch],[prompt,chatbot,e_box,json_out])
|
538 |
-
|
539 |
-
|
|
|
540 |
stop_button.click(None,None,None,cancels=[go])
|
541 |
app.queue(default_concurrency_limit=20).launch(show_api=False)
|
|
|
394 |
return out_json
|
395 |
|
396 |
|
397 |
+
|
398 |
def summarize(inp,history,report_check,chart_check,data=None,files=None,directory=None,url=None,pdf_url=None,pdf_batch=None):
|
399 |
json_box=[]
|
400 |
error_box=""
|
|
|
404 |
history = [(inp,"Working on it...")]
|
405 |
yield "",history,error_box,json_box
|
406 |
|
407 |
+
if pdf_batch.startswith("http"):
|
408 |
+
c=0
|
409 |
+
data=""
|
410 |
+
for i in str(pdf_batch):
|
411 |
+
if i==",":
|
412 |
+
c+=1
|
413 |
+
print (f'c:: {c}')
|
414 |
+
|
415 |
+
try:
|
416 |
+
for i in range(c+1):
|
417 |
+
batch_url = pdf_batch.split(",",c)[i]
|
418 |
+
bb = read_pdf_online(batch_url)
|
419 |
+
data=f'{data}\nFile Name URL ({batch_url}):\n{bb}'
|
420 |
+
except Exception as e:
|
421 |
+
print(e)
|
422 |
+
#data=f'{data}\nError reading URL ({batch_url})'
|
423 |
+
|
424 |
+
if directory:
|
425 |
+
for ea in directory:
|
426 |
+
print(ea)
|
427 |
+
|
428 |
+
if pdf_url.startswith("http"):
|
429 |
+
print("PDF_URL")
|
430 |
+
out = read_pdf_online(pdf_url)
|
431 |
+
data=out
|
432 |
+
if url.startswith("http"):
|
433 |
+
val, out = find_all(url)
|
434 |
+
if not val:
|
435 |
+
data="Error"
|
436 |
+
rawp = str(out)
|
437 |
+
else:
|
438 |
+
data=out
|
439 |
+
if files:
|
440 |
+
for i, file in enumerate(files):
|
441 |
+
try:
|
442 |
+
print (file)
|
443 |
+
if file.endswith(".pdf"):
|
444 |
+
zz=read_pdf(file)
|
445 |
+
print (zz)
|
446 |
+
data=f'{data}\nFile Name ({file}):\n{zz}'
|
447 |
+
elif file.endswith(".txt"):
|
448 |
+
zz=read_txt(file)
|
449 |
+
print (zz)
|
450 |
+
data=f'{data}\nFile Name ({file}):\n{zz}'
|
451 |
+
except Exception as e:
|
452 |
+
data=f'{data}\nError opening File Name ({file})'
|
453 |
+
print (e)
|
454 |
+
if data != "Error" and data != "":
|
455 |
+
print(inp)
|
456 |
+
out = str(data)
|
457 |
+
rl = len(out)
|
458 |
+
print(f'rl:: {rl}')
|
459 |
+
c=1
|
460 |
+
for i in str(out):
|
461 |
+
if i == " " or i=="," or i=="\n":
|
462 |
+
c +=1
|
463 |
+
print (f'c:: {c}')
|
464 |
+
|
465 |
+
json_out = sort_fn(out)
|
466 |
+
yield "", history,error_box,json_out,json_out
|
467 |
+
|
468 |
+
|
469 |
+
def search_fn(prompt,history,report_check,chart_check,data):
|
470 |
+
if data != "Error" and data != "":
|
471 |
+
print(inp)
|
472 |
+
out = str(data)
|
473 |
+
rl = len(out)
|
474 |
+
print(f'rl:: {rl}')
|
475 |
+
c=1
|
476 |
+
for i in str(out):
|
477 |
+
if i == " " or i=="," or i=="\n":
|
478 |
+
c +=1
|
479 |
+
print (f'c:: {c}')
|
480 |
+
|
481 |
+
#json_start = sort_fn(out)
|
482 |
+
json_out = find_keyword_fn(c,prompt,data)
|
483 |
+
print(f'JSON_BOX:: {json_out}')
|
484 |
+
out = str(json_out)
|
485 |
+
if report_check:
|
486 |
+
rl = len(out)
|
487 |
+
print(f'rl:: {rl}')
|
488 |
+
c=1
|
489 |
+
for i in str(out):
|
490 |
+
if i == " " or i=="," or i=="\n":
|
491 |
+
c +=1
|
492 |
+
print (f'c2:: {c}')
|
493 |
+
rawp = compress_data_og(c,inp,out)
|
494 |
+
else:
|
495 |
+
rawp = out
|
496 |
+
try:
|
497 |
+
json_out=format_json(json_out)
|
498 |
+
print("JSON FORMATTED")
|
499 |
+
except Exception as e:
|
500 |
+
print (e)
|
501 |
+
if chart_check:
|
502 |
+
print (f"making chart from ::: {rawp}")
|
503 |
+
error_box = get_chart(str(json_out))
|
504 |
+
print(error_box)
|
505 |
+
else:
|
506 |
+
rawp = "Provide a valid data source"
|
507 |
+
#print (rawp)
|
508 |
+
#print (f'out:: {out}')
|
509 |
+
#history += "observation: the search results are:\n {}\n".format(out)
|
510 |
+
#task = "complete?"
|
511 |
+
history.clear()
|
512 |
+
history.append((inp,rawp))
|
513 |
+
yield "", history,error_box,json_out
|
514 |
+
|
515 |
+
|
516 |
+
def summarize_OG(inp,history,report_check,chart_check,data=None,files=None,directory=None,url=None,pdf_url=None,pdf_batch=None):
|
517 |
+
json_box=[]
|
518 |
+
error_box=""
|
519 |
+
if inp == "":
|
520 |
+
inp = "Process this data"
|
521 |
+
history.clear()
|
522 |
+
history = [(inp,"Working on it...")]
|
523 |
+
yield "",history,error_box,json_box
|
524 |
+
|
525 |
if pdf_batch.startswith("http"):
|
526 |
c=0
|
527 |
data=""
|
|
|
614 |
history.append((inp,rawp))
|
615 |
yield "", history,error_box,json_out
|
616 |
|
617 |
+
|
618 |
+
|
619 |
+
|
620 |
+
|
621 |
+
|
622 |
+
|
623 |
+
|
624 |
#################################
|
625 |
def clear_fn():
|
626 |
return "",[(None,None)]
|
627 |
|
628 |
with gr.Blocks() as app:
|
629 |
+
doc_state=gr.State()
|
630 |
gr.HTML("""<center><h1>Mixtral 8x7B TLDR Summarizer + Web</h1><h3>Summarize Data of unlimited length</h3>""")
|
631 |
chatbot = gr.Chatbot(label="Mixtral 8x7B Chatbot",show_copy_button=True)
|
632 |
with gr.Row():
|
|
|
635 |
with gr.Column(scale=1):
|
636 |
report_check=gr.Checkbox(label="Return Report", value=False)
|
637 |
chart_check=gr.Checkbox(label="Return Chart", value=False)
|
638 |
+
load_button=gr.Button("Load")
|
639 |
+
button=gr.Button("Run")
|
640 |
|
641 |
#models_dd=gr.Dropdown(choices=[m for m in return_list],interactive=True)
|
642 |
with gr.Row():
|
|
|
662 |
clear_btn.click(clear_fn,None,[prompt,chatbot])
|
663 |
|
664 |
#go=button.click(summarize,[prompt,chatbot,report_check,chart_check,data,file,directory,url,pdf_url,pdf_batch],[prompt,chatbot,e_box,json_out])
|
665 |
+
find=button.click(search_fn,[prompt,chatbot,report_check,chart_check,doc_state],[prompt,chatbot,e_box,json_out])
|
666 |
+
go=load_button.click(summarize,[prompt,chatbot,report_check,chart_check,data,file,directory,url,pdf_url,pdf_batch],[prompt,chatbot,e_box,json_out,doc_state])
|
667 |
+
#find=button.click()
|
668 |
stop_button.click(None,None,None,cancels=[go])
|
669 |
app.queue(default_concurrency_limit=20).launch(show_api=False)
|