DocSrvNyk commited on
Commit
8366cb4
·
1 Parent(s): 2732163

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +52 -0
main.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import joblib
4
+
5
+ # Define a function for the Gradio interface
6
+ def predict_risk(Age, hOCP, hMisCrg, hHRT, CA125, HE4, FBS, USG):
7
+ # Load the trained model
8
+ model = joblib.load('RDF_OvCa_Final.joblib')
9
+
10
+ # Create a DataFrame with the input data
11
+ input_data = pd.DataFrame({
12
+ 'Age': [Age],
13
+ 'hOCP': [hOCP],
14
+ 'hMisCrg': [hMisCrg],
15
+ 'hHRT': [hHRT],
16
+ 'CA125': [CA125],
17
+ 'HE4': [HE4],
18
+ 'FBS': [FBS],
19
+ 'USG': [USG]
20
+ })
21
+
22
+ # Predict the probability of malignancy (class 1)
23
+ probability = model.predict_proba(input_data)[:, 1][0]
24
+
25
+ # Scale the risk score to -1 to +1
26
+ risk_score = 2 * probability - 1
27
+
28
+ # Determine the predicted status
29
+ status = "malignant" if probability >= cutoff else "benign"
30
+
31
+ result = f"The OvaCa Risk Score is {risk_score:.2f}. Based on it, the probability is more of {status} ({1 if status == 'malignant' else 0})."
32
+
33
+ return result
34
+
35
+ # Define the Gradio interface
36
+ iface = gr.Interface(
37
+ fn=predict_risk,
38
+ inputs=[
39
+ gr.inputs.Number(label="Age of patient in years"),
40
+ gr.inputs.Radio([0, 1], label="History of OCP intake (0: No 1: Yes)"),
41
+ gr.inputs.Radio([0, 1], label="History of Miscarriage (0: No 1: Yes)"),
42
+ gr.inputs.Radio([0, 1], label="History of HRT (0: No 1: Yes)"),
43
+ gr.inputs.Number(label="Serum CA125 level"),
44
+ gr.inputs.Number(label="Serum HE4 level"),
45
+ gr.inputs.Number(label="Serum Fasting Blood Sugar Level"),
46
+ gr.inputs.Radio([0, 1], label="USG Finding (0: Absent or Single Finding 1: More Than 1 Findings)")
47
+ ],
48
+ outputs=gr.outputs.Textbox(label="Result (Risk Score on a Scale of -1 to +1, where >0 ~ Malignant)")
49
+ )
50
+
51
+ # Launch the Gradio interface
52
+ iface.launch()