Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -399,7 +399,7 @@ with gr.Blocks(title="Document Q&A System", css=custom_css) as demo:
|
|
| 399 |
label="Upload Document",
|
| 400 |
file_types=[".pdf", ".txt", ".doc", ".docx"],
|
| 401 |
file_count="single",
|
| 402 |
-
type="binary"
|
| 403 |
)
|
| 404 |
file_output = gr.Textbox(
|
| 405 |
label="Upload Status",
|
|
@@ -410,28 +410,46 @@ with gr.Blocks(title="Document Q&A System", css=custom_css) as demo:
|
|
| 410 |
|
| 411 |
with gr.Row():
|
| 412 |
with gr.Column(scale=2):
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
)
|
| 433 |
-
|
| 434 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
with gr.Row():
|
| 437 |
with gr.Column(scale=1):
|
|
|
|
| 399 |
label="Upload Document",
|
| 400 |
file_types=[".pdf", ".txt", ".doc", ".docx"],
|
| 401 |
file_count="single",
|
| 402 |
+
type="binary"
|
| 403 |
)
|
| 404 |
file_output = gr.Textbox(
|
| 405 |
label="Upload Status",
|
|
|
|
| 410 |
|
| 411 |
with gr.Row():
|
| 412 |
with gr.Column(scale=2):
|
| 413 |
+
chatbot = gr.Chatbot(
|
| 414 |
+
height=500,
|
| 415 |
+
type="messages",
|
| 416 |
+
show_label=False,
|
| 417 |
+
elem_classes="chatbot",
|
| 418 |
+
placeholder="Ask questions about your uploaded document..."
|
| 419 |
+
)
|
| 420 |
+
|
| 421 |
+
def chat_fn(message, history):
|
| 422 |
+
if not rag.thread_id:
|
| 423 |
+
return "Please upload a document first."
|
| 424 |
+
try:
|
| 425 |
+
response = rag.ask_question(message)
|
| 426 |
+
return response
|
| 427 |
+
except Exception as e:
|
| 428 |
+
return f"Error: {str(e)}"
|
| 429 |
+
|
| 430 |
+
def vote(data: gr.LikeData):
|
| 431 |
+
if data.liked:
|
| 432 |
+
print("You upvoted this response: " + data.value["value"])
|
| 433 |
+
else:
|
| 434 |
+
print("You downvoted this response: " + data.value["value"])
|
| 435 |
+
|
| 436 |
+
chatbot.like(vote, None, None)
|
| 437 |
+
|
| 438 |
+
gr.ChatInterface(
|
| 439 |
+
fn=chat_fn,
|
| 440 |
+
chatbot=chatbot,
|
| 441 |
+
examples=[
|
| 442 |
+
"What is this document about?",
|
| 443 |
+
"Can you summarize the main points?",
|
| 444 |
+
"What are the key findings?"
|
| 445 |
+
],
|
| 446 |
+
title="Document Q&A",
|
| 447 |
+
description="Ask questions about your uploaded document",
|
| 448 |
+
theme="soft",
|
| 449 |
+
retry_btn=None,
|
| 450 |
+
undo_btn=None,
|
| 451 |
+
clear_btn="Clear Chat"
|
| 452 |
+
)
|
| 453 |
|
| 454 |
with gr.Row():
|
| 455 |
with gr.Column(scale=1):
|