giannantonio15 commited on
Commit
55ea49d
β€’
1 Parent(s): 24beca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -475,7 +475,6 @@ def main():
475
  history[-1][1] += html_escape(str(character))
476
  time.sleep(0.05)
477
  yield history,responseHTML
478
-
479
 
480
  else:
481
  print("MODALITA STANDARD")
@@ -538,11 +537,18 @@ def main():
538
  retriever = VectorIndexRetriever(index=index, similarity_top_k=3, vector_store_query_mode="hybrid", embed_model=embed_model, alpha=0.5)
539
 
540
  if(str(current_response_mode)=="tree_summarize"):
 
 
 
 
 
 
541
  # Misura il tempo di inizio
542
  start_time = time.time()
543
 
544
  # Esegui la funzione
545
- retriever.retrieve(userMessage)
 
546
 
547
  # Misura il tempo di fine
548
  end_time = time.time()
@@ -550,14 +556,10 @@ def main():
550
  # Calcola il tempo di esecuzione
551
  execution_time = end_time - start_time
552
  print(f"Tempo di esecuzione: {execution_time} secondi")
553
- # define response synthesizer
554
- response_synthesizer = get_response_synthesizer(streaming=True,response_mode="tree_summarize",text_qa_template=text_qa_template)
555
- query_engine = None
556
- query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
557
- stream_response = None
558
- print(userMessage)
559
- stream_response = query_engine.query(userMessage)
560
  print("risposta con query engine")
 
 
561
  responseHTML = ""
562
  for i, node in enumerate(stream_response.source_nodes):
563
  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>"
 
475
  history[-1][1] += html_escape(str(character))
476
  time.sleep(0.05)
477
  yield history,responseHTML
 
478
 
479
  else:
480
  print("MODALITA STANDARD")
 
537
  retriever = VectorIndexRetriever(index=index, similarity_top_k=3, vector_store_query_mode="hybrid", embed_model=embed_model, alpha=0.5)
538
 
539
  if(str(current_response_mode)=="tree_summarize"):
540
+ # define response synthesizer
541
+ response_synthesizer = get_response_synthesizer(streaming=True,response_mode="tree_summarize",text_qa_template=text_qa_template)
542
+ query_engine = None
543
+ query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=response_synthesizer)
544
+ stream_response = None
545
+ print(userMessage)
546
  # Misura il tempo di inizio
547
  start_time = time.time()
548
 
549
  # Esegui la funzione
550
+ stream_response = query_engine.query(userMessage)
551
+
552
 
553
  # Misura il tempo di fine
554
  end_time = time.time()
 
556
  # Calcola il tempo di esecuzione
557
  execution_time = end_time - start_time
558
  print(f"Tempo di esecuzione: {execution_time} secondi")
559
+ #stream_response = query_engine.query(userMessage)
 
 
 
 
 
 
560
  print("risposta con query engine")
561
+
562
+
563
  responseHTML = ""
564
  for i, node in enumerate(stream_response.source_nodes):
565
  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>"