linx5o commited on
Commit
c92b425
1 Parent(s): 726acea

duplicate method

Browse files
Files changed (1) hide show
  1. app.py +77 -11
app.py CHANGED
@@ -10,13 +10,6 @@ USERNAME = os.environ.get("username")
10
  PASSWORD = os.environ.get("password")
11
  PIOREACTOR = os.environ.get("pioreactor")
12
 
13
-
14
- HOST_gr = gr.Textbox(label="Host", value=HOST, visible=False)
15
- PORT_gr = gr.Number(label="Port", value=PORT, visible=False)
16
- USERNAME_gr = gr.Textbox(label="Username", value=USERNAME, visible=False)
17
- PASSWORD_gr = gr.Textbox(label="Password", value=PASSWORD, visible=False)
18
- PIOREACTOR_gr = gr.Textbox(label="Pioreactor", value=PIOREACTOR, visible=False)
19
-
20
  client = None
21
  client_custom = None
22
 
@@ -292,12 +285,85 @@ def void_client():
292
  client_custom = None
293
  print("Client disconnected")
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  # Define the interface components
296
  with gr.Blocks() as demo:
297
  with gr.Tab("Default"):
298
  experiment_input = gr.Textbox(label="Experiment", value="Ed")
299
  experiment_input.input(fn=void_client)
300
 
 
 
301
  with gr.Blocks():
302
  gr.Markdown("# Stirring")
303
  rpm = gr.Slider(minimum=0, maximum=2000, step=50, label="RPM")
@@ -308,8 +374,8 @@ with gr.Blocks() as demo:
308
  st = gr.Button("Send Command")
309
 
310
  st.click(
311
- fn=stirring,
312
- inputs=[rpm, HOST_gr, PORT_gr, USERNAME_gr, PASSWORD_gr, PIOREACTOR_gr, experiment_input, stir_state]
313
  )
314
 
315
  with gr.Blocks():
@@ -338,8 +404,8 @@ with gr.Blocks() as demo:
338
  )
339
 
340
  temp.click(
341
- fn=temp_automation,
342
- inputs=[temperature_slider, HOST_gr, PORT_gr, USERNAME_gr, PASSWORD_gr, PIOREACTOR_gr, experiment_input, temp_state, temp_option]
343
  )
344
 
345
 
 
10
  PASSWORD = os.environ.get("password")
11
  PIOREACTOR = os.environ.get("pioreactor")
12
 
 
 
 
 
 
 
 
13
  client = None
14
  client_custom = None
15
 
 
285
  client_custom = None
286
  print("Client disconnected")
287
 
288
+ def stirring_default(rpm, experiment, state, client):
289
+ if state == "start":
290
+ payload = {
291
+ "command": "start_stirring",
292
+ "experiment": experiment,
293
+ "reactor": PIOREACTOR,
294
+ "rpm": rpm
295
+ }
296
+ client.publish(f"pioreactor/control", json.dumps(payload))
297
+ elif state == "stop":
298
+ payload = {
299
+ "command": "stop_stirring",
300
+ "experiment": experiment,
301
+ "reactor": PIOREACTOR
302
+ }
303
+ client.publish(f"pioreactor/control", json.dumps(payload))
304
+ elif state == "update":
305
+ payload = {
306
+ "command": "update_stirring_rpm",
307
+ "experiment": experiment,
308
+ "reactor": PIOREACTOR,
309
+ "rpm": rpm
310
+ }
311
+ client.publish(f"pioreactor/control", json.dumps(payload))
312
+ else:
313
+ print("Invalid state")
314
+
315
+ def temp_automation_default(temperature, experiment, state, option, client):
316
+ payload_options = "thermostat" if option == "Heat To Temp" else "only_record_temperature"
317
+
318
+ if state == "start":
319
+ payload = {
320
+ "command": "set_temperature_automation",
321
+ "experiment": experiment,
322
+ "reactor": PIOREACTOR,
323
+ "temp": temperature,
324
+ "automation": payload_options
325
+ }
326
+ client.publish(f"pioreactor/control", json.dumps(payload))
327
+ elif state == "stop":
328
+ payload = {
329
+ "command": "temp_update",
330
+ "experiment": experiment,
331
+ "reactor": PIOREACTOR,
332
+ "settings": {
333
+ "$state": "disconnected"
334
+ }
335
+ }
336
+ client.publish(f"pioreactor/control", json.dumps(payload))
337
+ elif state == "update":
338
+ payload = {
339
+ "command": "temp_update",
340
+ "experiment": experiment,
341
+ "reactor": PIOREACTOR,
342
+ "settings": {
343
+ "target_temperature": temperature
344
+ }
345
+ }
346
+ client.publish(f"pioreactor/control", json.dumps(payload))
347
+ elif state == "restart":
348
+ payload = {
349
+ "command": "temp_restart",
350
+ "experiment": experiment,
351
+ "reactor": PIOREACTOR,
352
+ "automation": payload_options,
353
+ "temp": temperature
354
+ }
355
+ client.publish(f"pioreactor/control", json.dumps(payload))
356
+ else:
357
+ print("Invalid state")
358
+
359
  # Define the interface components
360
  with gr.Blocks() as demo:
361
  with gr.Tab("Default"):
362
  experiment_input = gr.Textbox(label="Experiment", value="Ed")
363
  experiment_input.input(fn=void_client)
364
 
365
+ client = create_client(HOST, PORT, USERNAME, PASSWORD)
366
+
367
  with gr.Blocks():
368
  gr.Markdown("# Stirring")
369
  rpm = gr.Slider(minimum=0, maximum=2000, step=50, label="RPM")
 
374
  st = gr.Button("Send Command")
375
 
376
  st.click(
377
+ fn=stirring_default,
378
+ inputs=[rpm, experiment_input, stir_state, client]
379
  )
380
 
381
  with gr.Blocks():
 
404
  )
405
 
406
  temp.click(
407
+ fn=temp_automation_default,
408
+ inputs=[temperature_slider, experiment_input, temp_state, temp_option, client]
409
  )
410
 
411