Update app.py
Browse files
app.py
CHANGED
|
@@ -145,14 +145,18 @@ def chat(user_input, history):
|
|
| 145 |
global chat_history
|
| 146 |
|
| 147 |
# Build full context (PDF + conversation history)
|
| 148 |
-
full_context = "\n".join([
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
]) if chat_history else ""
|
| 152 |
-
|
|
|
|
| 153 |
|
| 154 |
# Store in memory
|
| 155 |
-
chat_history.append({
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
# Update UI history
|
| 158 |
new_history = history + [
|
|
@@ -161,7 +165,6 @@ answer = generate_answer(user_input, full_context)
|
|
| 161 |
]
|
| 162 |
|
| 163 |
return new_history, new_history
|
| 164 |
-
|
| 165 |
def generate_answer(query, conversation_context=""):
|
| 166 |
if index is None:
|
| 167 |
return "⚠️ Please load a PDF first."
|
|
|
|
| 145 |
global chat_history
|
| 146 |
|
| 147 |
# Build full context (PDF + conversation history)
|
| 148 |
+
full_context = "\n".join([
|
| 149 |
+
f"User: {h['user']}\nBot: {h['bot']}"
|
| 150 |
+
for h in chat_history[-5:]
|
| 151 |
+
]) if chat_history else ""
|
| 152 |
+
|
| 153 |
+
answer = generate_answer(user_input, full_context)
|
| 154 |
|
| 155 |
# Store in memory
|
| 156 |
+
chat_history.append({
|
| 157 |
+
"user": user_input,
|
| 158 |
+
"bot": answer
|
| 159 |
+
})
|
| 160 |
|
| 161 |
# Update UI history
|
| 162 |
new_history = history + [
|
|
|
|
| 165 |
]
|
| 166 |
|
| 167 |
return new_history, new_history
|
|
|
|
| 168 |
def generate_answer(query, conversation_context=""):
|
| 169 |
if index is None:
|
| 170 |
return "⚠️ Please load a PDF first."
|