linx5o commited on
Commit
bf20631
·
1 Parent(s): 0ba48f8

added to custom

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py CHANGED
@@ -429,6 +429,50 @@ def pinch_default(experiment, state):
429
  else:
430
  print("Invalid state")
431
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
 
433
  def od_default(experiment, state):
434
  global client
@@ -1313,6 +1357,34 @@ with gr.Blocks() as demo:
1313
  )
1314
 
1315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1316
 
1317
  # Launch the interface
1318
  demo.launch()
 
429
  else:
430
  print("Invalid state")
431
 
432
+ def relay(experiment, host, port, username, password, pioreactor, state):
433
+ global client_custom
434
+ if client_custom is None:
435
+ custom_client(host, port, username, password)
436
+
437
+ if state == "start":
438
+ payload = {
439
+ "command": "start_relay",
440
+ "experiment": experiment,
441
+ "reactor": pioreactor
442
+ }
443
+ client_custom.publish(f"pioreactor/control", json.dumps(payload))
444
+ elif state == "stop":
445
+ payload = {
446
+ "command": "stop_relay",
447
+ "experiment": experiment,
448
+ "reactor": pioreactor
449
+ }
450
+ client_custom.publish(f"pioreactor/control", json.dumps(payload))
451
+ else:
452
+ print("Invalid state")
453
+
454
+ def pinch(experiment, host, port, username, password, pioreactor, state):
455
+ global client_custom
456
+ if client_custom is None:
457
+ custom_client(host, port, username, password)
458
+
459
+ if state == "open":
460
+ payload = {
461
+ "command": "relay_on",
462
+ "experiment": experiment,
463
+ "reactor": pioreactor
464
+ }
465
+ client_custom.publish(f"pioreactor/control", json.dumps(payload))
466
+ elif state == "close":
467
+ payload = {
468
+ "command": "relay_off",
469
+ "experiment": experiment,
470
+ "reactor": pioreactor
471
+ }
472
+ client_custom.publish(f"pioreactor/control", json.dumps(payload))
473
+ else:
474
+ print("Invalid state")
475
+
476
 
477
  def od_default(experiment, state):
478
  global client
 
1357
  )
1358
 
1359
 
1360
+ with gr.Blocks():
1361
+ gr.Markdown("# Pinch Valve")
1362
+
1363
+ gr.Markdown("Ensure that relay is running in Status. If not, start the automation before using the pinch valve.")
1364
+
1365
+ with gr.Row():
1366
+ with gr.Column():
1367
+ gr.Markdown("### Relay Automation")
1368
+
1369
+ relay_state = gr.Radio(choices=["start", "stop"], label="State", value="start")
1370
+ relay_button = gr.Button("Send Command")
1371
+
1372
+ relay_button.click(
1373
+ fn=relay,
1374
+ inputs=[host_input, port_input, username_input, password_input, pioreactor_input, experiment_input, relay_state]
1375
+ )
1376
+
1377
+ with gr.Column():
1378
+ gr.Markdown("### Pinch Valve")
1379
+
1380
+ pinch_state = gr.Radio(choices=["open", "close"], label="State", value="open")
1381
+ pinch_button = gr.Button("Send Command")
1382
+
1383
+ pinch_button.click(
1384
+ fn=pinch,
1385
+ inputs=[host_input, port_input, username_input, password_input, pioreactor_input, experiment_input, pinch_state]
1386
+ )
1387
+
1388
 
1389
  # Launch the interface
1390
  demo.launch()