Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -195,11 +195,12 @@ processor = PdfProcessor()
|
|
| 195 |
def chat_function(message, history):
|
| 196 |
response = query_documents(message, processor)
|
| 197 |
answer = response["answer"]
|
|
|
|
| 198 |
new_history = history + [
|
| 199 |
{"role": "user", "content": message},
|
| 200 |
{"role": "assistant", "content": answer}
|
| 201 |
]
|
| 202 |
-
return new_history, ""
|
| 203 |
|
| 204 |
def upload_file(file):
|
| 205 |
if file is None:
|
|
@@ -309,17 +310,25 @@ with gr.Blocks(theme=modern_theme, css=custom_css) as demo:
|
|
| 309 |
"Delete Selected Document",
|
| 310 |
size="sm"
|
| 311 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
# Event handlers
|
| 314 |
send_btn.click(
|
| 315 |
chat_function,
|
| 316 |
inputs=[msg, chatbot],
|
| 317 |
-
outputs=[chatbot, msg]
|
| 318 |
)
|
| 319 |
msg.submit(
|
| 320 |
chat_function,
|
| 321 |
inputs=[msg, chatbot],
|
| 322 |
-
outputs=[chatbot, msg]
|
| 323 |
)
|
| 324 |
upload_btn.click(
|
| 325 |
upload_file,
|
|
|
|
| 195 |
def chat_function(message, history):
|
| 196 |
response = query_documents(message, processor)
|
| 197 |
answer = response["answer"]
|
| 198 |
+
chunks = "\n\n".join([f"Chunk {i+1}: {chunk}" for i, chunk in enumerate(response["chunks"])])
|
| 199 |
new_history = history + [
|
| 200 |
{"role": "user", "content": message},
|
| 201 |
{"role": "assistant", "content": answer}
|
| 202 |
]
|
| 203 |
+
return new_history, "", chunks
|
| 204 |
|
| 205 |
def upload_file(file):
|
| 206 |
if file is None:
|
|
|
|
| 310 |
"Delete Selected Document",
|
| 311 |
size="sm"
|
| 312 |
)
|
| 313 |
+
chunks_display = gr.Textbox(
|
| 314 |
+
value="Query results will appear here",
|
| 315 |
+
label="Retrieved Chunks",
|
| 316 |
+
interactive=False,
|
| 317 |
+
lines=5,
|
| 318 |
+
max_lines=5,
|
| 319 |
+
elem_classes="info-box"
|
| 320 |
+
)
|
| 321 |
|
| 322 |
# Event handlers
|
| 323 |
send_btn.click(
|
| 324 |
chat_function,
|
| 325 |
inputs=[msg, chatbot],
|
| 326 |
+
outputs=[chatbot, msg, chunks_display]
|
| 327 |
)
|
| 328 |
msg.submit(
|
| 329 |
chat_function,
|
| 330 |
inputs=[msg, chatbot],
|
| 331 |
+
outputs=[chatbot, msg, chunks_display]
|
| 332 |
)
|
| 333 |
upload_btn.click(
|
| 334 |
upload_file,
|