Update app.py
Browse files
app.py
CHANGED
@@ -76,13 +76,17 @@ class AdvancedPdfChatbot:
|
|
76 |
logging.error(f"PDF processing error: {e}")
|
77 |
return False
|
78 |
|
79 |
-
def chat(self, query):
|
80 |
if not self.db:
|
81 |
return "Please upload a PDF first."
|
82 |
|
83 |
# Retrieve chat history
|
84 |
chat_history = self.memory.load_memory_variables({}).get('chat_history', [])
|
85 |
|
|
|
|
|
|
|
|
|
86 |
# Generate context-aware response
|
87 |
response = self.response_generator.generate_response(
|
88 |
context=self.document_context,
|
@@ -106,7 +110,8 @@ def upload_pdf(pdf_file):
|
|
106 |
|
107 |
def respond(message, history):
|
108 |
try:
|
109 |
-
|
|
|
110 |
history.append((message, bot_message))
|
111 |
return "", history
|
112 |
except Exception as e:
|
|
|
76 |
logging.error(f"PDF processing error: {e}")
|
77 |
return False
|
78 |
|
79 |
+
def chat(self, query, is_new_question=False):
|
80 |
if not self.db:
|
81 |
return "Please upload a PDF first."
|
82 |
|
83 |
# Retrieve chat history
|
84 |
chat_history = self.memory.load_memory_variables({}).get('chat_history', [])
|
85 |
|
86 |
+
# Reset chat history for new questions
|
87 |
+
if is_new_question:
|
88 |
+
chat_history = [] # For new questions, reset the chat history
|
89 |
+
|
90 |
# Generate context-aware response
|
91 |
response = self.response_generator.generate_response(
|
92 |
context=self.document_context,
|
|
|
110 |
|
111 |
def respond(message, history):
|
112 |
try:
|
113 |
+
is_new_question = len(history) == 0 # If history is empty, it's a new question
|
114 |
+
bot_message = pdf_chatbot.chat(message, is_new_question)
|
115 |
history.append((message, bot_message))
|
116 |
return "", history
|
117 |
except Exception as e:
|