giannantonio15 commited on
Commit
c4855d0
β€’
1 Parent(s): dc2152e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -26
app.py CHANGED
@@ -419,6 +419,11 @@ def main():
419
  print(chat_engine_bandi.chat_history)
420
  print(memory_bandi)
421
  stream_response = chat_engine_bandi.stream_chat(user_message)
 
 
 
 
 
422
  history[-1][1] = ""
423
  for character in stream_response.response_gen:
424
  tokens = character.split(" ")
@@ -429,12 +434,6 @@ def main():
429
  time.sleep(0.05)
430
  yield history, "<p>"
431
 
432
-
433
- responseHTML = ""
434
- for i, node in enumerate(stream_response.source_nodes):
435
- responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
436
- yield history, responseHTML
437
-
438
  else:
439
  if(token_count_bandi_sistema_puglia >= 1000):
440
  print("RESET!!!")
@@ -444,7 +443,11 @@ def main():
444
  print(chat_engine_bandi_sistema_puglia.chat_history)
445
  print(memory_bandi_sistema_puglia)
446
  stream_response = chat_engine_bandi_sistema_puglia.stream_chat(user_message)
447
-
 
 
 
 
448
  history[-1][1] = ""
449
  for character in stream_response.response_gen:
450
  tokens = character.split(" ")
@@ -453,48 +456,46 @@ def main():
453
  print(token_count_bandi_sistema_puglia)
454
  history[-1][1] += html_escape(str(character))
455
  time.sleep(0.05)
456
- yield history,"<p>"
457
 
458
- responseHTML = ""
459
- for i, node in enumerate(stream_response.source_nodes):
460
- responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
461
- yield history, responseHTML
462
 
463
  else:
464
  if(str(current_response_mode)=="tree_summarize"):
465
  # define response synthesizer
466
  response_synthesizer = get_response_synthesizer(streaming=True,response_mode="tree_summarize",text_qa_template=text_qa_template)
 
467
  query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
468
  stream_response = query_engine.query(user_message)
469
- history[-1][1] = ""
470
- for character in stream_response.response_gen:
471
- history[-1][1] += html_escape(str(character))
472
- time.sleep(0.05)
473
- yield history ,"<p>"
474
-
475
  responseHTML = ""
476
  for i, node in enumerate(stream_response.source_nodes):
477
  responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
478
 
479
- yield history, responseHTML
 
 
 
 
480
  else:
481
  # define response synthesizer
482
  response_synthesizer = get_response_synthesizer(streaming=True,response_mode="compact",text_qa_template=text_qa_template, refine_template=refine_template)
 
483
  query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
484
  stream_response = query_engine.query(user_message)
485
-
 
 
 
 
486
  history[-1][1] = ""
487
  for character in stream_response.response_gen:
488
  history[-1][1] += html_escape(str(character))
489
  time.sleep(0.05)
490
- yield history,"<p>"
 
491
 
492
- responseHTML = ""
493
 
494
- for i, node in enumerate(stream_response.source_nodes):
495
- responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
496
-
497
- yield history, responseHTML
498
 
499
  torch.cuda.empty_cache()
500
  torch.cuda.reset_max_memory_allocated()
 
419
  print(chat_engine_bandi.chat_history)
420
  print(memory_bandi)
421
  stream_response = chat_engine_bandi.stream_chat(user_message)
422
+ print("risposta con chat engine")
423
+ responseHTML = ""
424
+ for i, node in enumerate(stream_response.source_nodes):
425
+ responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
426
+
427
  history[-1][1] = ""
428
  for character in stream_response.response_gen:
429
  tokens = character.split(" ")
 
434
  time.sleep(0.05)
435
  yield history, "<p>"
436
 
 
 
 
 
 
 
437
  else:
438
  if(token_count_bandi_sistema_puglia >= 1000):
439
  print("RESET!!!")
 
443
  print(chat_engine_bandi_sistema_puglia.chat_history)
444
  print(memory_bandi_sistema_puglia)
445
  stream_response = chat_engine_bandi_sistema_puglia.stream_chat(user_message)
446
+ print("risposta con chat engine")
447
+ responseHTML = ""
448
+ for i, node in enumerate(stream_response.source_nodes):
449
+ responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
450
+
451
  history[-1][1] = ""
452
  for character in stream_response.response_gen:
453
  tokens = character.split(" ")
 
456
  print(token_count_bandi_sistema_puglia)
457
  history[-1][1] += html_escape(str(character))
458
  time.sleep(0.05)
459
+ yield history,responseHTML
460
 
461
+
 
 
 
462
 
463
  else:
464
  if(str(current_response_mode)=="tree_summarize"):
465
  # define response synthesizer
466
  response_synthesizer = get_response_synthesizer(streaming=True,response_mode="tree_summarize",text_qa_template=text_qa_template)
467
+ query_engine = None
468
  query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
469
  stream_response = query_engine.query(user_message)
470
+ print("risposta con query engine")
 
 
 
 
 
471
  responseHTML = ""
472
  for i, node in enumerate(stream_response.source_nodes):
473
  responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
474
 
475
+ history[-1][1] = ""
476
+ for character in stream_response.response_gen:
477
+ history[-1][1] += html_escape(str(character))
478
+ time.sleep(0.05)
479
+ yield history, responseHTML
480
  else:
481
  # define response synthesizer
482
  response_synthesizer = get_response_synthesizer(streaming=True,response_mode="compact",text_qa_template=text_qa_template, refine_template=refine_template)
483
+ query_engine = None
484
  query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
485
  stream_response = query_engine.query(user_message)
486
+ print("risposta con query engine")
487
+ responseHTML = ""
488
+ for i, node in enumerate(stream_response.source_nodes):
489
+ responseHTML += "<p><b>"+node.metadata['nome_bando']+"</b><a href='"+node.metadata['file_path']+"' download> <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='currentColor' class='bi bi-download' viewBox='0 0 16 16'><path d='M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5'/><path d='M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z'/> </svg></a><br>Nodo <span id='span"+str(i+1)+"' class='icon' onclick='toggleText(this.id)'>πŸ”</span> <!-- Text to show/hide --><p class='hidden-text' id='nodo"+str(i+1)+"'>"+node.text+"</p>"
490
+
491
  history[-1][1] = ""
492
  for character in stream_response.response_gen:
493
  history[-1][1] += html_escape(str(character))
494
  time.sleep(0.05)
495
+ yield history, responseHTML
496
+
497
 
 
498
 
 
 
 
 
499
 
500
  torch.cuda.empty_cache()
501
  torch.cuda.reset_max_memory_allocated()