JadAssaf
commited on
Commit
·
4d58ea1
1
Parent(s):
bb661fe
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %%
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
loaded_rf_2way = joblib.load("STPI_2WAY_RandomForest.joblib")
|
| 5 |
+
loaded_rf_3way = joblib.load("STPI_3WAY_RandomForest.joblib")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def STPI(t_0_5_MaxValue,t_1_0_MaxValue,t_2_0_MaxValue,Acc_0_5__1_0_MaxValue,Abs_Diff_t_0_5_MaxValue,Abs_Diff_t_1_0_MaxValue,Abs_Diff_t_2_0_MaxValue):
|
| 9 |
+
X = [t_0_5_MaxValue,t_1_0_MaxValue,t_2_0_MaxValue,Acc_0_5__1_0_MaxValue,Abs_Diff_t_0_5_MaxValue,Abs_Diff_t_1_0_MaxValue,Abs_Diff_t_2_0_MaxValue]
|
| 10 |
+
outcome_decoded = ['Normal','Keratoconic','Suspect']
|
| 11 |
+
file_object = open('stpi_data.txt', 'a')
|
| 12 |
+
file_object.write(str(t_0_5_MaxValue))
|
| 13 |
+
file_object.write(';')
|
| 14 |
+
file_object.write(str(t_1_0_MaxValue))
|
| 15 |
+
file_object.write(';')
|
| 16 |
+
file_object.write(str(t_2_0_MaxValue))
|
| 17 |
+
file_object.write(';')
|
| 18 |
+
file_object.write(str(Acc_0_5__1_0_MaxValue))
|
| 19 |
+
file_object.write(';')
|
| 20 |
+
file_object.write(str(Abs_Diff_t_0_5_MaxValue))
|
| 21 |
+
file_object.write(';')
|
| 22 |
+
file_object.write(str(Abs_Diff_t_1_0_MaxValue))
|
| 23 |
+
file_object.write(';')
|
| 24 |
+
file_object.write(str(Abs_Diff_t_2_0_MaxValue))
|
| 25 |
+
file_object.write('\n')
|
| 26 |
+
file_object.close()
|
| 27 |
+
|
| 28 |
+
result_2way = loaded_rf_2way.predict([X])
|
| 29 |
+
print('The patient is ', outcome_decoded[int(result_2way)], 'through the 2way method')
|
| 30 |
+
|
| 31 |
+
if result_2way == 0:
|
| 32 |
+
result_3way = loaded_rf_3way.predict([X])
|
| 33 |
+
print('The patient is ', outcome_decoded[int(result_3way)], 'through the 3way method')
|
| 34 |
+
return "The patient is ", outcome_decoded[int(result_3way)], "through the 3way method"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
return "The patient is ", outcome_decoded[int(result_2way)], "through the 2way method"
|
| 38 |
+
|
| 39 |
+
iface = gr.Interface(fn=STPI,
|
| 40 |
+
title='STPI Calculator',
|
| 41 |
+
description='Calculates the STPI through summarized tomographic parameters. Beta version by Jad Assaf MD and Prof. Shady Awwad',
|
| 42 |
+
inputs=["number", "number","number", "number","number", "number","number"],
|
| 43 |
+
outputs="text")
|
| 44 |
+
iface.launch(share=True)
|
| 45 |
+
# %%
|