AlanOC commited on
Commit
639ccc4
1 Parent(s): 384cc23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -49
app.py CHANGED
@@ -115,6 +115,56 @@ pdf_qa = ConversationalRetrievalChain.from_llm(
115
  chat_history = []
116
 
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  def ask_alans_ai(query, vectordb):
119
  global chat_history
120
  result = pdf_qa(
@@ -172,52 +222,3 @@ if __name__ == "__main__":
172
 
173
 
174
 
175
- # Create a log file to store user queries and responses
176
- log_file = None # Initialize log_file as None
177
-
178
- def setup_log_file():
179
- global log_file
180
- try:
181
- log_file = open("query_log.txt", "a")
182
- except Exception as e:
183
- print("Error opening log file:", str(e))
184
-
185
- def close_log_file():
186
- global log_file
187
- if log_file is not None:
188
- log_file.close()
189
-
190
-
191
-
192
- def log_query(query, response):
193
- if log_file is not None:
194
- timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
195
- log_entry = f"[{timestamp}] User Query: {query}\nSystem Response: {response}\n\n"
196
- log_file.write(log_entry)
197
- log_file.flush() # Ensure the log is written immediately
198
-
199
-
200
- # Setup the log file before launching the interface
201
- setup_log_file()
202
-
203
-
204
- log_file_path = "query_log.txt"
205
-
206
- def log_message(message):
207
- timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
208
- log_entry = f"[{timestamp}] {message}\n"
209
- with open(log_file_path, "a") as log_file:
210
- log_file.write(log_entry)
211
- print("Message logged successfully.")
212
- log_file.flush() # Ensure the log is written immediately
213
-
214
- # Test logging
215
- log_message("This is a test message.")
216
-
217
-
218
-
219
-
220
-
221
-
222
- # Close the log file when the application exits
223
- atexit.register(close_log_file)
 
115
  chat_history = []
116
 
117
 
118
+ ##################################################################################################################
119
+ # Create a log file to store user queries and responses
120
+ log_file = None # Initialize log_file as None
121
+
122
+ def setup_log_file():
123
+ global log_file
124
+ try:
125
+ log_file = open("query_log.txt", "a")
126
+ except Exception as e:
127
+ print("Error opening log file:", str(e))
128
+
129
+ def close_log_file():
130
+ global log_file
131
+ if log_file is not None:
132
+ log_file.close()
133
+
134
+
135
+
136
+ def log_query(query, response):
137
+ if log_file is not None:
138
+ timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
139
+ log_entry = f"[{timestamp}] User Query: {query}\nSystem Response: {response}\n\n"
140
+ log_file.write(log_entry)
141
+ log_file.flush() # Ensure the log is written immediately
142
+
143
+
144
+ # Setup the log file before launching the interface
145
+ setup_log_file()
146
+
147
+
148
+ log_file_path = "query_log.txt"
149
+
150
+ def log_message(message):
151
+ timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
152
+ log_entry = f"[{timestamp}] {message}\n"
153
+ with open(log_file_path, "a") as log_file:
154
+ log_file.write(log_entry)
155
+ print("Message logged successfully.")
156
+ log_file.flush() # Ensure the log is written immediately
157
+
158
+ # Test logging
159
+ log_message("This is a test message.")
160
+
161
+
162
+
163
+ # Close the log file when the application exits
164
+ atexit.register(close_log_file)
165
+ ###########################################################################################################
166
+
167
+
168
  def ask_alans_ai(query, vectordb):
169
  global chat_history
170
  result = pdf_qa(
 
222
 
223
 
224