Yoxas commited on
Commit
50082c5
·
verified ·
1 Parent(s): 78d6608

Update src/pdfchatbot.py

Browse files
Files changed (1) hide show
  1. src/pdfchatbot.py +21 -7
src/pdfchatbot.py CHANGED
@@ -172,10 +172,24 @@ class PDFChatBot:
172
  history.append((text, ''))
173
  return history
174
 
175
- # Function to download conversation history
176
- def download_chat(history,text):
177
- with open('chat_history.csv', 'w', newline='') as file:
178
- writer = csv.writer(file)
179
- writer.writerow(["User Input", "Bot Response"])
180
- writer.writerows(chat_history)
181
- return "chat_history.csv"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")