Spaces:
Runtime error
Runtime error
final changes
Browse files
app.py
CHANGED
|
@@ -359,6 +359,127 @@ def temp_automation_default(temperature, experiment, state, option):
|
|
| 359 |
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 360 |
else:
|
| 361 |
print("Invalid state")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
# Define the interface components
|
| 364 |
with gr.Blocks() as demo:
|
|
@@ -411,8 +532,109 @@ with gr.Blocks() as demo:
|
|
| 411 |
fn=temp_automation_default,
|
| 412 |
inputs=[temperature_slider, experiment_input, temp_state, temp_option]
|
| 413 |
)
|
| 414 |
-
|
| 415 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
with gr.Tab("Custom"):
|
| 418 |
# Input components
|
|
|
|
| 359 |
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 360 |
else:
|
| 361 |
print("Invalid state")
|
| 362 |
+
|
| 363 |
+
def od_default(experiment, state):
|
| 364 |
+
global client
|
| 365 |
+
|
| 366 |
+
if state == "start":
|
| 367 |
+
payload = {
|
| 368 |
+
"command": "start_od_reading",
|
| 369 |
+
"experiment": experiment,
|
| 370 |
+
"reactor": PIOREACTOR
|
| 371 |
+
}
|
| 372 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 373 |
+
elif state == "stop":
|
| 374 |
+
payload = {
|
| 375 |
+
"command": "stop_od_reading",
|
| 376 |
+
"experiment": experiment,
|
| 377 |
+
"reactor": PIOREACTOR
|
| 378 |
+
}
|
| 379 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 380 |
+
else:
|
| 381 |
+
print("Invalid state")
|
| 382 |
+
|
| 383 |
+
def grf_default(experiment, state):
|
| 384 |
+
global client
|
| 385 |
+
|
| 386 |
+
if state == "start":
|
| 387 |
+
payload = {
|
| 388 |
+
"command": "start_growth_rate",
|
| 389 |
+
"experiment": experiment,
|
| 390 |
+
"reactor": PIOREACTOR
|
| 391 |
+
}
|
| 392 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 393 |
+
elif state == "stop":
|
| 394 |
+
payload = {
|
| 395 |
+
"command": "stop_growth_rate",
|
| 396 |
+
"experiment": experiment,
|
| 397 |
+
"reactor": PIOREACTOR
|
| 398 |
+
}
|
| 399 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 400 |
+
else:
|
| 401 |
+
print("Invalid state")
|
| 402 |
+
|
| 403 |
+
def led1fn_default(led1, experiment):
|
| 404 |
+
global client
|
| 405 |
+
|
| 406 |
+
payload = {
|
| 407 |
+
"command": "set_led_intensity",
|
| 408 |
+
"experiment": experiment,
|
| 409 |
+
"reactor": PIOREACTOR,
|
| 410 |
+
"led": "A",
|
| 411 |
+
"brightness": led1
|
| 412 |
+
}
|
| 413 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 414 |
+
|
| 415 |
+
def led2fn_default(led2, experiment):
|
| 416 |
+
global client
|
| 417 |
+
|
| 418 |
+
payload = {
|
| 419 |
+
"command": "set_led_intensity",
|
| 420 |
+
"experiment": experiment,
|
| 421 |
+
"reactor": PIOREACTOR,
|
| 422 |
+
"led": "B",
|
| 423 |
+
"brightness": led2
|
| 424 |
+
}
|
| 425 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 426 |
+
|
| 427 |
+
def led3fn_default(led3, experiment):
|
| 428 |
+
global client
|
| 429 |
+
|
| 430 |
+
payload = {
|
| 431 |
+
"command": "set_led_intensity",
|
| 432 |
+
"experiment": experiment,
|
| 433 |
+
"reactor": PIOREACTOR,
|
| 434 |
+
"led": "C",
|
| 435 |
+
"brightness": led3
|
| 436 |
+
}
|
| 437 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 438 |
+
|
| 439 |
+
def led4fn_default(led4, experiment):
|
| 440 |
+
global client
|
| 441 |
+
|
| 442 |
+
payload = {
|
| 443 |
+
"command": "set_led_intensity",
|
| 444 |
+
"experiment": experiment,
|
| 445 |
+
"reactor": PIOREACTOR,
|
| 446 |
+
"led": "D",
|
| 447 |
+
"brightness": led4
|
| 448 |
+
}
|
| 449 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 450 |
+
|
| 451 |
+
def add_media_default(media, experiment):
|
| 452 |
+
global client
|
| 453 |
+
|
| 454 |
+
payload = {
|
| 455 |
+
"command": "pump_add_media",
|
| 456 |
+
"experiment": experiment,
|
| 457 |
+
"reactor": PIOREACTOR,
|
| 458 |
+
"volume": media
|
| 459 |
+
}
|
| 460 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 461 |
+
|
| 462 |
+
def remove_waste_default(waste, experiment):
|
| 463 |
+
global client
|
| 464 |
+
|
| 465 |
+
payload = {
|
| 466 |
+
"command": "pump_remove_media",
|
| 467 |
+
"experiment": experiment,
|
| 468 |
+
"reactor": PIOREACTOR,
|
| 469 |
+
"volume": waste
|
| 470 |
+
}
|
| 471 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 472 |
+
|
| 473 |
+
def cycle_media_default(cycle, experiment):
|
| 474 |
+
global client
|
| 475 |
+
|
| 476 |
+
payload = {
|
| 477 |
+
"command": "circulate_media",
|
| 478 |
+
"experiment": experiment,
|
| 479 |
+
"reactor": PIOREACTOR,
|
| 480 |
+
"duration": cycle
|
| 481 |
+
}
|
| 482 |
+
client.publish(f"pioreactor/control", json.dumps(payload))
|
| 483 |
|
| 484 |
# Define the interface components
|
| 485 |
with gr.Blocks() as demo:
|
|
|
|
| 532 |
fn=temp_automation_default,
|
| 533 |
inputs=[temperature_slider, experiment_input, temp_state, temp_option]
|
| 534 |
)
|
|
|
|
| 535 |
|
| 536 |
+
with gr.Blocks():
|
| 537 |
+
with gr.Row():
|
| 538 |
+
with gr.Column():
|
| 539 |
+
gr.Markdown("# OD Reading")
|
| 540 |
+
od_state = gr.Radio(choices=["start", "stop"], label="State")
|
| 541 |
+
od_button = gr.Button("Send Command")
|
| 542 |
+
|
| 543 |
+
od_button.click(
|
| 544 |
+
fn=od_default,
|
| 545 |
+
inputs=[experiment_input, od_state]
|
| 546 |
+
)
|
| 547 |
+
|
| 548 |
+
with gr.Column():
|
| 549 |
+
gr.Markdown("# Growth Rate")
|
| 550 |
+
gr_state = gr.Radio(choices=["start", "stop"], label="State")
|
| 551 |
+
gr_button = gr.Button("Send Command")
|
| 552 |
+
|
| 553 |
+
gr_button.click(
|
| 554 |
+
fn=grf_default,
|
| 555 |
+
inputs=[experiment_input, gr_state]
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
with gr.Blocks():
|
| 559 |
+
gr.Markdown("# LEDS")
|
| 560 |
+
|
| 561 |
+
with gr.Row():
|
| 562 |
+
with gr.Column():
|
| 563 |
+
gr.Markdown("### Channel A")
|
| 564 |
+
led1 = gr.Slider(minimum=0, maximum=100, step=1, label="Intensity")
|
| 565 |
+
led1_button = gr.Button("Send Command")
|
| 566 |
+
|
| 567 |
+
led1_button.click(
|
| 568 |
+
fn=led1fn_default,
|
| 569 |
+
inputs=[led1, experiment_input]
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
with gr.Column():
|
| 573 |
+
gr.Markdown("### Channel B")
|
| 574 |
+
led2 = gr.Slider(minimum=0, maximum=100, step=1, label="Intensity")
|
| 575 |
+
led2_button = gr.Button("Send Command")
|
| 576 |
+
|
| 577 |
+
led2_button.click(
|
| 578 |
+
fn=led2fn_default,
|
| 579 |
+
inputs=[led2, experiment_input]
|
| 580 |
+
)
|
| 581 |
+
|
| 582 |
+
with gr.Column():
|
| 583 |
+
gr.Markdown("### Channel C")
|
| 584 |
+
led3 = gr.Slider(minimum=0, maximum=100, step=1, label="Intensity")
|
| 585 |
+
led3_button = gr.Button("Send Command")
|
| 586 |
+
|
| 587 |
+
led3_button.click(
|
| 588 |
+
fn=led3fn_default,
|
| 589 |
+
inputs=[led3, experiment_input]
|
| 590 |
+
)
|
| 591 |
+
|
| 592 |
+
with gr.Column():
|
| 593 |
+
gr.Markdown("### Channel D")
|
| 594 |
+
led4 = gr.Slider(minimum=0, maximum=100, step=1, label="Intensity")
|
| 595 |
+
led4_button = gr.Button("Send Command")
|
| 596 |
+
|
| 597 |
+
led4_button.click(
|
| 598 |
+
fn=led4fn_default,
|
| 599 |
+
inputs=[led4, experiment_input]
|
| 600 |
+
)
|
| 601 |
+
|
| 602 |
+
with gr.Blocks():
|
| 603 |
+
gr.Markdown("# Dosing")
|
| 604 |
+
|
| 605 |
+
with gr.Row():
|
| 606 |
+
with gr.Column():
|
| 607 |
+
gr.Markdown("### Add Media")
|
| 608 |
+
|
| 609 |
+
add_media_ml = gr.Number(label="Media (mL)", step=1, minimum=0, maximum=14)
|
| 610 |
+
add_media_button = gr.Button("Send Command")
|
| 611 |
+
|
| 612 |
+
add_media_button.click(
|
| 613 |
+
fn=add_media_default,
|
| 614 |
+
inputs=[add_media_ml, experiment_input]
|
| 615 |
+
)
|
| 616 |
+
|
| 617 |
+
with gr.Column():
|
| 618 |
+
gr.Markdown("### Remove Waste")
|
| 619 |
+
|
| 620 |
+
remove_waste_ml = gr.Number(label="Waste (mL)", step=1, minimum=0, maximum=20)
|
| 621 |
+
remove_waste_button = gr.Button("Send Command")
|
| 622 |
+
|
| 623 |
+
remove_waste_button.click(
|
| 624 |
+
fn=remove_waste_default,
|
| 625 |
+
inputs=[remove_waste_ml, experiment_input]
|
| 626 |
+
)
|
| 627 |
+
|
| 628 |
+
with gr.Column():
|
| 629 |
+
gr.Markdown("### Cycle Media")
|
| 630 |
+
|
| 631 |
+
cycle_media_sec = gr.Number(label="Cycle (s)", step=1, minimum=0, maximum=60)
|
| 632 |
+
cycle_media_button = gr.Button("Send Command")
|
| 633 |
+
|
| 634 |
+
cycle_media_button.click(
|
| 635 |
+
fn=cycle_media_default,
|
| 636 |
+
inputs=[cycle_media_sec, experiment_input]
|
| 637 |
+
)
|
| 638 |
|
| 639 |
with gr.Tab("Custom"):
|
| 640 |
# Input components
|