File size: 2,033 Bytes
4d58ea1
 
 
 
 
 
 
 
 
c6be718
4d58ea1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
028ab22
4d58ea1
 
028ab22
4d58ea1
 
 
0e82f30
4d58ea1
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# %%
import gradio as gr
import joblib
loaded_rf_2way = joblib.load("STPI_2WAY_RandomForest.joblib")
loaded_rf_3way = joblib.load("STPI_3WAY_RandomForest.joblib")


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):
    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]
    print(X)
    outcome_decoded = ['Normal','Keratoconic','Suspect']
    file_object = open('stpi_data.txt', 'a')
    file_object.write(str(t_0_5_MaxValue))
    file_object.write(';')
    file_object.write(str(t_1_0_MaxValue))
    file_object.write(';')
    file_object.write(str(t_2_0_MaxValue))
    file_object.write(';')
    file_object.write(str(Acc_0_5__1_0_MaxValue))
    file_object.write(';')
    file_object.write(str(Abs_Diff_t_0_5_MaxValue))
    file_object.write(';')
    file_object.write(str(Abs_Diff_t_1_0_MaxValue))
    file_object.write(';')
    file_object.write(str(Abs_Diff_t_2_0_MaxValue))
    file_object.write('\n')
    file_object.close()

    result_2way = loaded_rf_2way.predict([X])
    print('The patient is ', outcome_decoded[int(result_2way)], 'through the 2way method')

    if result_2way == 0:
        result_3way = loaded_rf_3way.predict([X])
        print('The patient is ', outcome_decoded[int(result_3way)], 'through the 3way method')
        return "The patient is " + outcome_decoded[int(result_3way)] + " using the 3way method and is "  + outcome_decoded[int(result_2way)] + "through the 2way method"

        
    return "The patient is " + outcome_decoded[int(result_2way)] + " using the 2way method"

iface = gr.Interface(fn=STPI, 
title='STPI Calculator',
description='Calculates the STPI through summarized tomographic parameters. Beta version by Prof. Shady Awwad, Jad Assaf MD and Jawad Kaisania.',
inputs=["number", "number","number", "number","number", "number","number"],
outputs="text")
iface.launch(share=True)
# %%