Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ def gen_pulsive_noise(count, min_val, max_val):
|
|
| 18 |
pulse = random.randint(min_val, max_val)
|
| 19 |
|
| 20 |
return pulse
|
| 21 |
-
def simulation(input_noise, output_noise, min, max, std, mean, min_pul, max_pul, kp, ki):
|
| 22 |
vrs = {}
|
| 23 |
fmu = 'Pharmacokinetics_4_comportmental_model_PI_ref_FMU_base4_OAAS_lnx.fmu'
|
| 24 |
model_description = read_model_description(fmu)
|
|
@@ -59,6 +59,7 @@ def simulation(input_noise, output_noise, min, max, std, mean, min_pul, max_pul,
|
|
| 59 |
infusion_rate = 200
|
| 60 |
i = 0
|
| 61 |
target = 30
|
|
|
|
| 62 |
# simulation loop
|
| 63 |
while time < stop_time:
|
| 64 |
|
|
@@ -76,8 +77,9 @@ def simulation(input_noise, output_noise, min, max, std, mean, min_pul, max_pul,
|
|
| 76 |
bis += add_noise(min, max, std, mean)
|
| 77 |
p = bis - target
|
| 78 |
i = i + p
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
if output_noise:
|
| 82 |
infusion_rate += gen_pulsive_noise(time, min_pul, max_pul)
|
| 83 |
|
|
@@ -130,9 +132,10 @@ with gr.Blocks() as demo:
|
|
| 130 |
with gr.Blocks():
|
| 131 |
kp_slider = gr.inputs.Slider(minimum=0, maximum=19, default=4, label="kp")
|
| 132 |
ki_slider = gr.inputs.Slider(minimum=0, maximum=1, default=0.01, label="ki")
|
|
|
|
| 133 |
button = gr.Button("Simulate")
|
| 134 |
with gr.Column(scale=5):
|
| 135 |
plot1 = gr.Plot(label="BIS evolution")
|
| 136 |
plot2 = gr.Plot(label="Infusion evolution")
|
| 137 |
-
button.click(simulation, inputs=[input_noise, output_noise, min_gaussian, max_gaussian, std_gaussian, mean_gaussian, min_pul, max_pul, kp_slider, ki_slider], outputs=[plot1, plot2])
|
| 138 |
demo.launch()
|
|
|
|
| 18 |
pulse = random.randint(min_val, max_val)
|
| 19 |
|
| 20 |
return pulse
|
| 21 |
+
def simulation(input_noise, output_noise, min, max, std, mean, min_pul, max_pul, kp, ki, kd):
|
| 22 |
vrs = {}
|
| 23 |
fmu = 'Pharmacokinetics_4_comportmental_model_PI_ref_FMU_base4_OAAS_lnx.fmu'
|
| 24 |
model_description = read_model_description(fmu)
|
|
|
|
| 59 |
infusion_rate = 200
|
| 60 |
i = 0
|
| 61 |
target = 30
|
| 62 |
+
last_error = 0
|
| 63 |
# simulation loop
|
| 64 |
while time < stop_time:
|
| 65 |
|
|
|
|
| 77 |
bis += add_noise(min, max, std, mean)
|
| 78 |
p = bis - target
|
| 79 |
i = i + p
|
| 80 |
+
d = p - last_error
|
| 81 |
+
last_error = p
|
| 82 |
+
infusion_rate = np.clip(kp*p + ki*i + kd*d, 0, 200)
|
| 83 |
if output_noise:
|
| 84 |
infusion_rate += gen_pulsive_noise(time, min_pul, max_pul)
|
| 85 |
|
|
|
|
| 132 |
with gr.Blocks():
|
| 133 |
kp_slider = gr.inputs.Slider(minimum=0, maximum=19, default=4, label="kp")
|
| 134 |
ki_slider = gr.inputs.Slider(minimum=0, maximum=1, default=0.01, label="ki")
|
| 135 |
+
kd_slider = gr.inputs.Slider(minimum=0, maximum=1, default=0.01, label="kd")
|
| 136 |
button = gr.Button("Simulate")
|
| 137 |
with gr.Column(scale=5):
|
| 138 |
plot1 = gr.Plot(label="BIS evolution")
|
| 139 |
plot2 = gr.Plot(label="Infusion evolution")
|
| 140 |
+
button.click(simulation, inputs=[input_noise, output_noise, min_gaussian, max_gaussian, std_gaussian, mean_gaussian, min_pul, max_pul, kp_slider, ki_slider, kd_slider], outputs=[plot1, plot2])
|
| 141 |
demo.launch()
|