Shriharsh commited on
Commit
16b939d
·
verified ·
1 Parent(s): 6b8ae3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -159,13 +159,13 @@ initial_state = {
159
  }
160
 
161
  # Initialize log_messages outside initial_state
162
- log_messages = []
163
 
164
  # Logging function to store messages in memory
165
  def log_message(message, log_messages):
166
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
167
  log_entry = f"{timestamp} - {message}"
168
- log_messages.append(log_entry)
169
  return log_messages
170
 
171
  # Function to save logs to file
@@ -181,7 +181,8 @@ with gr.Blocks() as demo:
181
  chat = gr.Chatbot()
182
  user_input = gr.Textbox(label="Your query or feedback")
183
  submit_btn = gr.Button("Submit")
184
- log_file = gr.File(label="Download Log File") # Changed: No initial value
 
185
 
186
  # Process file upload
187
  file_upload.upload(process_file, inputs=[file_upload, state, gr.State(log_messages)], outputs=[chat, state, gr.State(log_messages)])
@@ -190,7 +191,7 @@ with gr.Blocks() as demo:
190
  submit_btn.click(handle_input, inputs=[user_input, state, gr.State(log_messages)], outputs=[chat, state, gr.State(log_messages)]).then(lambda: "", None, user_input)
191
 
192
  # Update the log file just before download
193
- log_file.click(save_logs_to_file, inputs=[gr.State(log_messages)], outputs=[log_file]) # Trigger save on click
194
 
195
  # Also save logs when user exits
196
  user_input.submit(
 
159
  }
160
 
161
  # Initialize log_messages outside initial_state
162
+ log_messages =
163
 
164
  # Logging function to store messages in memory
165
  def log_message(message, log_messages):
166
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
167
  log_entry = f"{timestamp} - {message}"
168
+ log_messages.append(log_entry)
169
  return log_messages
170
 
171
  # Function to save logs to file
 
181
  chat = gr.Chatbot()
182
  user_input = gr.Textbox(label="Your query or feedback")
183
  submit_btn = gr.Button("Submit")
184
+ download_log_btn = gr.Button("Download Log File") # Changed to Button
185
+ log_file = gr.File(label="Log File") # Keep File for serving
186
 
187
  # Process file upload
188
  file_upload.upload(process_file, inputs=[file_upload, state, gr.State(log_messages)], outputs=[chat, state, gr.State(log_messages)])
 
191
  submit_btn.click(handle_input, inputs=[user_input, state, gr.State(log_messages)], outputs=[chat, state, gr.State(log_messages)]).then(lambda: "", None, user_input)
192
 
193
  # Update the log file just before download
194
+ download_log_btn.click(save_logs_to_file, inputs=[gr.State(log_messages)], outputs=[log_file]) # Trigger save on click
195
 
196
  # Also save logs when user exits
197
  user_input.submit(