Neil-YL commited on
Commit
265cdf7
·
verified ·
1 Parent(s): 39ab7d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -6
app.py CHANGED
@@ -246,9 +246,7 @@ def update_queue_display():
246
  """Refresh queue info for the UI"""
247
  global current_task, queue_counter
248
  try:
249
- print(f"[DEBUG] Updating queue display - Counter: {queue_counter}")
250
- print(f"[DEBUG] Current task: {current_task}")
251
-
252
  if current_task:
253
  status = f"""### Current Queue Status
254
  - Active experiment: Yes
@@ -260,13 +258,11 @@ def update_queue_display():
260
  - Total experiments: {queue_counter}"""
261
  return status
262
  except Exception as e:
263
- print(f"[DEBUG] Error in update_queue_display: {str(e)}")
264
  return f"Error getting queue status: {str(e)}"
265
 
266
 
267
  def add_to_queue(student_id, R, Y, B):
268
  global queue_counter
269
- print(f"[DEBUG] Before adding - Queue counter: {queue_counter}")
270
 
271
  # Validate RYB inputs
272
  validation_result = validate_ryb_input(R, Y, B)
@@ -352,6 +348,57 @@ def add_to_queue(student_id, R, Y, B):
352
  result = result_queue.get()
353
  yield result
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
 
356
  with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
357
  gr.Markdown("## OT-2 Liquid Color Matching Experiment Queue")
@@ -417,7 +464,8 @@ with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
417
  update_status_btn.click(
418
  update_queue_display,
419
  None,
420
- queue_status
 
421
  )
422
 
423
  demo.load(
@@ -426,6 +474,14 @@ with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
426
  queue_status
427
  )
428
 
 
 
 
 
 
 
 
 
429
 
430
  demo.queue
431
 
 
246
  """Refresh queue info for the UI"""
247
  global current_task, queue_counter
248
  try:
249
+ print(f"[DEBUG] Updating queue display - Counter: {queue_counter}")
 
 
250
  if current_task:
251
  status = f"""### Current Queue Status
252
  - Active experiment: Yes
 
258
  - Total experiments: {queue_counter}"""
259
  return status
260
  except Exception as e:
 
261
  return f"Error getting queue status: {str(e)}"
262
 
263
 
264
  def add_to_queue(student_id, R, Y, B):
265
  global queue_counter
 
266
 
267
  # Validate RYB inputs
268
  validation_result = validate_ryb_input(R, Y, B)
 
348
  result = result_queue.get()
349
  yield result
350
 
351
+ def debug_experiment(student_id, R, Y, B):
352
+ if student_id != "debug":
353
+ return {"Status": "Error", "Message": "Invalid debug request"}
354
+
355
+ experiment_id = "debug-" + secrets.token_hex(4)
356
+
357
+ yield {
358
+ "Status": "Queued",
359
+ "Position": debug,
360
+ "Student ID": student_id,
361
+ "Experiment ID": experiment_id,
362
+ "Well": "DEBUG-A1",
363
+ "Volumes": {"R": R, "Y": Y, "B": B}
364
+ }
365
+
366
+ time.sleep(5)
367
+
368
+ yield {
369
+ "Status": "Running",
370
+ "Student ID": student_id,
371
+ "Experiment ID": experiment_id,
372
+ "Well": "DEBUG-A1",
373
+ "Volumes": {"R": R, "Y": Y, "B": B}
374
+ }
375
+
376
+ time.sleep(5)
377
+
378
+ yield {
379
+ "Status": "Complete",
380
+ "Message": "Debug mode - simulated result (no actual experiment performed)",
381
+ "Student ID": student_id,
382
+ "Command": {
383
+ "R": R,
384
+ "Y": Y,
385
+ "B": B,
386
+ "well": "DEBUG-A1"
387
+ },
388
+ "Sensor Data": {
389
+ "ch583": 2800,
390
+ "ch670": 3000,
391
+ "ch510": 1700,
392
+ "ch410": 240,
393
+ "ch620": 3900,
394
+ "ch470": 1000,
395
+ "ch550": 2400,
396
+ "ch440": 900
397
+ },
398
+ "Experiment ID": experiment_id
399
+ }
400
+ return
401
+
402
 
403
  with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
404
  gr.Markdown("## OT-2 Liquid Color Matching Experiment Queue")
 
464
  update_status_btn.click(
465
  update_queue_display,
466
  None,
467
+ queue_status,
468
+ api_name="update_queue_display"
469
  )
470
 
471
  demo.load(
 
474
  queue_status
475
  )
476
 
477
+ debug_btn = gr.Button("Debug Submit", visible=False)
478
+ debug_btn.click(
479
+ debug_experiment,
480
+ inputs=[student_id_input, r_slider, y_slider, b_slider],
481
+ outputs=result_output,
482
+ api_name="debug"
483
+ )
484
+
485
 
486
  demo.queue
487