Rsnarsna commited on
Commit
5c1df96
·
verified ·
1 Parent(s): 49a315d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -193,13 +193,15 @@ def read_email():
193
  running = False
194
  loop_thread = None
195
 
 
196
  def email_processing_loop():
197
  global running
198
  logger.info("Starting email processing loop...")
199
  while running:
200
- read_email()
201
- time.sleep(10) # Check for new emails every 10 seconds
202
 
 
203
  def start_processing():
204
  global running, loop_thread
205
  if not running:
@@ -208,31 +210,33 @@ def start_processing():
208
  loop_thread.start()
209
  return "Running"
210
 
 
211
  def stop_processing():
212
  global running
213
  if running:
214
  running = False
215
  return "Stopped"
216
 
 
217
  def update_status():
218
  return "Running" if running else "Stopped"
219
 
220
  # Create Gradio interface
221
  with gr.Blocks() as demo:
222
  gr.Markdown("# Email Processing")
223
-
224
- status_display = gr.Textbox(label="Email Processing Status", interactive=False)
225
- status_display.update(value=update_status()) # Initial status display
226
 
227
  start_button = gr.Button("Start Processing")
228
  stop_button = gr.Button("Stop Processing")
229
 
230
- start_button.click(start_processing, outputs=status_display)
231
- stop_button.click(stop_processing, outputs=status_display)
 
232
 
233
- # Automatically update status every 2 seconds
234
- gr.Timer(update_status, outputs=status_display, interval=2)
235
 
236
  if __name__ == "__main__":
237
  logging.info('Starting project...')
238
- demo.launch()
 
193
  running = False
194
  loop_thread = None
195
 
196
+ # Dummy function to simulate email processing (replace with actual email processing code)
197
  def email_processing_loop():
198
  global running
199
  logger.info("Starting email processing loop...")
200
  while running:
201
+ logger.info("Processing emails...")
202
+ time.sleep(10) # Simulating a process that checks every 10 seconds
203
 
204
+ # Start the email processing loop
205
  def start_processing():
206
  global running, loop_thread
207
  if not running:
 
210
  loop_thread.start()
211
  return "Running"
212
 
213
+ # Stop the email processing loop
214
  def stop_processing():
215
  global running
216
  if running:
217
  running = False
218
  return "Stopped"
219
 
220
+ # Update the status of email processing
221
  def update_status():
222
  return "Running" if running else "Stopped"
223
 
224
  # Create Gradio interface
225
  with gr.Blocks() as demo:
226
  gr.Markdown("# Email Processing")
227
+
228
+ status_display = gr.Textbox(label="Email Processing Status", value=update_status(), interactive=False)
 
229
 
230
  start_button = gr.Button("Start Processing")
231
  stop_button = gr.Button("Stop Processing")
232
 
233
+ # Link buttons to processing functions
234
+ start_button.click(fn=start_processing, outputs=status_display)
235
+ stop_button.click(fn=stop_processing, outputs=status_display)
236
 
237
+ # Automatically update the status display every 2 seconds using Gradio's timer
238
+ gr.Timer(fn=update_status, outputs=status_display, interval=2)
239
 
240
  if __name__ == "__main__":
241
  logging.info('Starting project...')
242
+ demo.launch()