Spaces:
Running
Running
try to animate lvad
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
|
| 4 |
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -800,7 +800,7 @@ def generate_example():
|
|
| 800 |
return video, animated, Rm, Ra, Emax, Emin, Vd, Tc, start_v
|
| 801 |
|
| 802 |
|
| 803 |
-
def lvad_plots(Rm, Ra, Emax, Emin, Vd, Tc, start_v, beta):
|
| 804 |
|
| 805 |
ncycle = 10000
|
| 806 |
|
|
@@ -829,18 +829,50 @@ def lvad_plots(Rm, Ra, Emax, Emin, Vd, Tc, start_v, beta):
|
|
| 829 |
|
| 830 |
#compute new pv loops and ef with lvad added:
|
| 831 |
new_ef, pao_ed, pao_es, CO, MAP, Vlvs, Plvs = f_lvad(Rs, Rm, Ra, Rc, Ca, Cs, Cr, Ls, Emin, Vd, Tc, start_v, Emax, c, slope0, w0, x60, y00, y01, y02, y03, y04)
|
| 832 |
-
|
|
|
|
| 833 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 838 |
plt.legend(loc='upper left', framealpha=1)
|
| 839 |
plt.ylim((0,220))
|
| 840 |
plt.xlim((0,250))
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 844 |
|
| 845 |
title = "<h1 style='text-align: center; margin-bottom: 1rem'> Med-Real2Sim: Non-Invasive Medical Digital Twins using Physics-Informed Self-Supervised Learning </h1>"
|
| 846 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
os.system('pip uninstall -y gradio')
|
| 3 |
+
os.system('pip install gradio==5.0.1')
|
| 4 |
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 800 |
return video, animated, Rm, Ra, Emax, Emin, Vd, Tc, start_v
|
| 801 |
|
| 802 |
|
| 803 |
+
def lvad_plots(Rm, Ra, Emax, Emin, Vd, Tc, start_v, beta, loop_simulated=True):
|
| 804 |
|
| 805 |
ncycle = 10000
|
| 806 |
|
|
|
|
| 829 |
|
| 830 |
#compute new pv loops and ef with lvad added:
|
| 831 |
new_ef, pao_ed, pao_es, CO, MAP, Vlvs, Plvs = f_lvad(Rs, Rm, Ra, Rc, Ca, Cs, Cr, Ls, Emin, Vd, Tc, start_v, Emax, c, slope0, w0, x60, y00, y01, y02, y03, y04)
|
| 832 |
+
|
| 833 |
+
# Create the figure and the loop that we will manipulate
|
| 834 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 835 |
+
plt.ylim((0,220))
|
| 836 |
+
plt.xlim((0,250))
|
| 837 |
+
start = (N-2)*60000
|
| 838 |
+
end = (N)*60000
|
| 839 |
+
if loop_simulated:
|
| 840 |
+
line1 = ax.plot(Vlv0[start:(start+1)], Plv0[start:(start+1)], lw=1, color='b',label='No LVAD')
|
| 841 |
+
point1 = ax.scatter(Vlv0[start:(start+1)], Plv0[start:(start+1)], c="b", s=5)#, label='End Diastole')
|
| 842 |
+
line2 = ax.plot(Vlvs[start:(start+1)], Plvs[start:(start+1)], color=(78/255, 192/255, 44/255), label=f"LVAD, ω(0)= {round(w0,2)}r/min")
|
| 843 |
+
point2 = ax.scatter(Vlvs[start:(start+1)], Plvs[start:(start+1)], c="b", s=5)#, label='End Diastole')
|
| 844 |
+
#point = ax.scatter(volumes[start:(start+1)], pressures[start:(start+1)], c="b", s=5, label='End Systole')
|
| 845 |
+
else:
|
| 846 |
+
line = ax.plot(volumes[start:end], pressures[start:end], lw=1, color='b')
|
| 847 |
+
line1 = ax.plot(Vlv0, Plv0, color='blue', label='No LVAD') #blue
|
| 848 |
+
line2 = ax.plot(Vlvs, Plvs, color=(78/255, 192/255, 44/255), label=f"LVAD, ω(0)= {round(w0,2)}r/min") #green
|
| 849 |
+
|
| 850 |
+
ax.set_xlabel('LV Volume (ml)')
|
| 851 |
+
ax.set_ylabel('LV Pressure (mmHg)')
|
| 852 |
+
|
| 853 |
+
# adjust the main plot to make room for the sliders
|
| 854 |
+
# fig.subplots_adjust(left=0.25, bottom=0.25)
|
| 855 |
+
|
| 856 |
+
def update(frame):
|
| 857 |
+
# update to add more of the loop
|
| 858 |
+
end = (N-2)*60000+1000 * frame
|
| 859 |
+
x = volumes[start:end]
|
| 860 |
+
y = pressures[start:end]
|
| 861 |
+
ax.plot(x, y, lw=1, c='b')
|
| 862 |
+
|
| 863 |
+
|
| 864 |
plt.legend(loc='upper left', framealpha=1)
|
| 865 |
plt.ylim((0,220))
|
| 866 |
plt.xlim((0,250))
|
| 867 |
+
|
| 868 |
+
if loop_simulated:
|
| 869 |
+
# plt.title('', fontsize=16)
|
| 870 |
+
anim = animation.FuncAnimation(fig, partial(update), frames=100, interval=30)
|
| 871 |
+
anim.save("simulated_lvad.mp4")
|
| 872 |
+
anim_plot = "simulated_lvad.mp4"
|
| 873 |
+
return anim_plot, round(ef_nolvad,2), round(new_ef,2), round(co_nolvad,2), round(CO, 2)
|
| 874 |
+
else:
|
| 875 |
+
return plt, round(ef_nolvad,2), round(new_ef,2), round(co_nolvad,2), round(CO, 2)
|
| 876 |
|
| 877 |
title = "<h1 style='text-align: center; margin-bottom: 1rem'> Med-Real2Sim: Non-Invasive Medical Digital Twins using Physics-Informed Self-Supervised Learning </h1>"
|
| 878 |
|