Update src/pdfchatbot.py
Browse files- src/pdfchatbot.py +21 -7
src/pdfchatbot.py
CHANGED
|
@@ -172,10 +172,24 @@ class PDFChatBot:
|
|
| 172 |
history.append((text, ''))
|
| 173 |
return history
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
history.append((text, ''))
|
| 173 |
return history
|
| 174 |
|
| 175 |
+
def download_chat_history(self, history):
|
| 176 |
+
"""
|
| 177 |
+
Download the chat history as a CSV file.
|
| 178 |
+
|
| 179 |
+
Parameters:
|
| 180 |
+
history (list): List of chat history tuples.
|
| 181 |
+
Returns:
|
| 182 |
+
gr.outputs.File: A CSV file containing the chat history.
|
| 183 |
+
"""
|
| 184 |
+
import csv
|
| 185 |
+
import io
|
| 186 |
+
|
| 187 |
+
output = io.StringIO()
|
| 188 |
+
writer = csv.writer(output)
|
| 189 |
+
writer.writerow(["User Input", "Bot Response"]) # header row
|
| 190 |
+
|
| 191 |
+
for user_input, bot_response in history:
|
| 192 |
+
writer.writerow([user_input, bot_response])
|
| 193 |
+
|
| 194 |
+
output.seek(0)
|
| 195 |
+
return gr.outputs.File("chat_history.csv", output.read(), "text/csv")
|