DreamStream-1 commited on
Commit
6ca970a
·
verified ·
1 Parent(s): e0b2ed1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -23
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" # Specify that we want binary data
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
- with gr.Group(elem_classes="chat-container"):
414
- chatbot = gr.Chatbot(
415
- height=500,
416
- type="messages",
417
- show_label=False,
418
- elem_classes="chatbot"
419
- )
420
- with gr.Row():
421
- question = gr.Textbox(
422
- label="Ask a question",
423
- placeholder="Type your question here...",
424
- show_label=False,
425
- container=False,
426
- elem_classes="textbox"
427
- )
428
- submit_btn = gr.Button(
429
- "Send",
430
- variant="primary",
431
- elem_classes="send-button"
432
- )
433
- question.submit(process_question, [question, chatbot], [question, chatbot])
434
- submit_btn.click(process_question, [question, chatbot], [question, chatbot])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):