farmax commited on
Commit
12b47b9
·
verified ·
1 Parent(s): fabd344

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -86,7 +86,7 @@ def conversation(qa_chain, message, history):
86
  response = qa_chain({"question": message, "chat_history": formatted_chat_history})
87
  response_answer = response["answer"].split("Helpful Answer:")[-1]
88
  response_sources = response["source_documents"]
89
- sources = [(source.page_content.strip(), source.metadata["page"] + 1) for source in response_sources[:3]]
90
  new_history = history + [(message, response_answer)]
91
  return qa_chain, gr.update(value=""), new_history, *[item for source in sources for item in source]
92
 
@@ -118,21 +118,21 @@ def demo():
118
  language_btn = gr.Radio(["Italiano", "Inglese"], label="Lingua", value="Italiano", type="index")
119
  llm_progress = gr.Textbox(value="Nessuna", label="Inizializzazione catena QA")
120
  qachain_btn = gr.Button("Inizializza catena di Domanda e Risposta")
121
-
122
  with gr.Tab("Passo 4 - Chatbot"):
123
  chatbot = gr.Chatbot(height=300)
124
  with gr.Accordion("Opzioni avanzate - Riferimenti ai documenti", open=False):
125
- doc_sources = [gr.Textbox(label=f"Riferimento {i+1}", lines=2, container=True, scale=20) for i in range(3)]
126
- source_pages = [gr.Number(label="Pagina", scale=1) for _ in range(3)]
127
  msg = gr.Textbox(placeholder="Inserisci il messaggio (es. 'Di cosa tratta questo documento?')", container=True)
128
  submit_btn = gr.Button("Invia messaggio")
129
- clear_btn = gr.ClearButton([msg, chatbot], value="Cancella conversazione")
130
 
131
  db_btn.click(initialize_database, inputs=[document, slider_chunk_size, slider_chunk_overlap], outputs=[vector_db, collection_name, db_progress])
132
  qachain_btn.click(initialize_LLM, inputs=[llm_btn, slider_temperature, slider_maxtokens, slider_topk, vector_db], outputs=[qa_chain, llm_progress])
133
-
134
  submit_btn.click(conversation, inputs=[qa_chain, msg, chatbot], outputs=[qa_chain, msg, chatbot] + doc_sources + source_pages)
135
- msg.submit(conversation, inputs=[qa_chain, msg, chatbot], outputs=[qa_chain, msg, chatbot] + doc_sources + source_pages)
136
 
137
  demo.queue().launch(debug=True)
138
 
 
86
  response = qa_chain({"question": message, "chat_history": formatted_chat_history})
87
  response_answer = response["answer"].split("Helpful Answer:")[-1]
88
  response_sources = response["source_documents"]
89
+ sources = [(source.page_content.strip(), source.metadata["page"] + 1) for source in response_sources[:5]] # Modificato da [:3] a [:5]
90
  new_history = history + [(message, response_answer)]
91
  return qa_chain, gr.update(value=""), new_history, *[item for source in sources for item in source]
92
 
 
118
  language_btn = gr.Radio(["Italiano", "Inglese"], label="Lingua", value="Italiano", type="index")
119
  llm_progress = gr.Textbox(value="Nessuna", label="Inizializzazione catena QA")
120
  qachain_btn = gr.Button("Inizializza catena di Domanda e Risposta")
121
+
122
  with gr.Tab("Passo 4 - Chatbot"):
123
  chatbot = gr.Chatbot(height=300)
124
  with gr.Accordion("Opzioni avanzate - Riferimenti ai documenti", open=False):
125
+ doc_sources = [gr.Textbox(label=f"Riferimento {i+1}", lines=2, container=True, scale=20) for i in range(5)] # Modificato da range(3) a range(5)
126
+ source_pages = [gr.Number(label="Pagina", scale=1) for _ in range(5)] # Modificato da range(3) a range(5)
127
  msg = gr.Textbox(placeholder="Inserisci il messaggio (es. 'Di cosa tratta questo documento?')", container=True)
128
  submit_btn = gr.Button("Invia messaggio")
129
+ clear_btn = gr.Button("Cancella conversazione")
130
 
131
  db_btn.click(initialize_database, inputs=[document, slider_chunk_size, slider_chunk_overlap], outputs=[vector_db, collection_name, db_progress])
132
  qachain_btn.click(initialize_LLM, inputs=[llm_btn, slider_temperature, slider_maxtokens, slider_topk, vector_db], outputs=[qa_chain, llm_progress])
133
+
134
  submit_btn.click(conversation, inputs=[qa_chain, msg, chatbot], outputs=[qa_chain, msg, chatbot] + doc_sources + source_pages)
135
+ msg.submit(conversation, inputs=[qa_chain, msg, chatbot], outputs=[qa_chain, msg, chatbot] + doc_sources + source_pages)
136
 
137
  demo.queue().launch(debug=True)
138