botsi commited on
Commit
69ba09b
·
verified ·
1 Parent(s): ad6ce90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -130,6 +130,11 @@ def generate(
130
  params = request.query_params
131
  print('those are the query params')
132
  print(params)
 
 
 
 
 
133
 
134
  # Construct the input prompt using the functions from the system_prompt_config module
135
  input_prompt = construct_input_prompt(chat_history, message)
@@ -177,6 +182,13 @@ def generate(
177
  outputs.append(text)
178
  yield "".join(outputs)
179
 
 
 
 
 
 
 
 
180
  # Save chat history to .csv file on HuggingFace Hub
181
  # Generate filename with bot id and session id
182
  filename = f"{DATA_FILENAME}"
@@ -192,7 +204,8 @@ def generate(
192
 
193
  # Add timestamp column
194
  conversation_df = pd.DataFrame(conversation)
195
- #conversation_df['readable_sentence'] = readable_sentence
 
196
  conversation_df['timestamp'] = timestamp
197
 
198
  # Append new conversation to existing data
@@ -201,7 +214,8 @@ def generate(
201
  else:
202
  # If file doesn't exist, create new file with conversation data
203
  conversation_df = pd.DataFrame(conversation)
204
- #conversation_df['readable_sentence'] = readable_sentence
 
205
  conversation_df['timestamp'] = timestamp
206
  conversation_df.to_csv(data_file, index=False)
207
 
 
130
  params = request.query_params
131
  print('those are the query params')
132
  print(params)
133
+
134
+ if request:
135
+ print("Request headers dictionary:", request.headers)
136
+ print("IP address:", request.client.host)
137
+ print("Query parameters:", dict(request.query_params))
138
 
139
  # Construct the input prompt using the functions from the system_prompt_config module
140
  input_prompt = construct_input_prompt(chat_history, message)
 
182
  outputs.append(text)
183
  yield "".join(outputs)
184
 
185
+ # Fix bug that last answer is not recorded!
186
+ # Parse the outputs into a readable sentence and record them
187
+ # Filter out empty strings and join the remaining strings with spaces
188
+ readable_sentence = ' '.join(filter(lambda x: x.strip(), outputs))
189
+ # Print the readable sentence
190
+ print(readable_sentence)
191
+
192
  # Save chat history to .csv file on HuggingFace Hub
193
  # Generate filename with bot id and session id
194
  filename = f"{DATA_FILENAME}"
 
204
 
205
  # Add timestamp column
206
  conversation_df = pd.DataFrame(conversation)
207
+ conversation_df['ip_address'] = request.client.host
208
+ conversation_df['readable_sentence'] = readable_sentence
209
  conversation_df['timestamp'] = timestamp
210
 
211
  # Append new conversation to existing data
 
214
  else:
215
  # If file doesn't exist, create new file with conversation data
216
  conversation_df = pd.DataFrame(conversation)
217
+ conversation_df['ip_address'] = request.client.host
218
+ conversation_df['readable_sentence'] = readable_sentence
219
  conversation_df['timestamp'] = timestamp
220
  conversation_df.to_csv(data_file, index=False)
221