Gargi16 commited on
Commit
8ee5b2e
·
verified ·
1 Parent(s): b8331ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -1
app.py CHANGED
@@ -35,7 +35,7 @@ iface = gr.Interface(
35
 
36
  # Launch the Gradio interface
37
  iface.launch()
38
- '''
39
  import gradio as gr
40
  import pickle
41
  import numpy as np
@@ -67,3 +67,87 @@ interface = gr.Interface(
67
 
68
  # Launch the Gradio app
69
  interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  # Launch the Gradio interface
37
  iface.launch()
38
+
39
  import gradio as gr
40
  import pickle
41
  import numpy as np
 
67
 
68
  # Launch the Gradio app
69
  interface.launch()
70
+ '''
71
+ import gradio as gr
72
+ import pickle
73
+ import numpy as np
74
+
75
+ # Load the model
76
+ with open('model_AD.pkl', 'rb') as f:
77
+ loaded_model = pickle.load(f)
78
+
79
+ # Define the prediction function
80
+ def predict_pcos(
81
+ age, weight, height, bmi, blood_group, pulse_rate, rr, hb, cycle_ri,
82
+ cycle_length, marriage_status, pregnant, no_of_abortions, fsh, lh, fsh_lh,
83
+ hip, waist, waist1, tsh, prl, vit_d3, prg, rbs, weight_gain, hair_growth,
84
+ skin_darkening, hair_loss, pimples, fast_food, reg_exercise, bp_systolic,
85
+ bp_diastolic, follicle_no_l, follicle_no_r, avg_f_size_l, avg_f_size_r, endometrium):
86
+
87
+ # Prepare the input data as a single-row array
88
+ input_data = np.array([[
89
+ age, weight, height, bmi, blood_group, pulse_rate, rr, hb, cycle_ri,
90
+ cycle_length, marriage_status, pregnant, no_of_abortions, fsh, lh, fsh_lh,
91
+ hip, waist, waist1, tsh, prl, vit_d3, prg, rbs, weight_gain, hair_growth,
92
+ skin_darkening, hair_loss, pimples, fast_food, reg_exercise, bp_systolic,
93
+ bp_diastolic, follicle_no_l, follicle_no_r, avg_f_size_l, avg_f_size_r, endometrium
94
+ ]])
95
+
96
+ # Get prediction
97
+ prediction = loaded_model.predict(input_data)[0]
98
+ return "PCOS Detected" if prediction == 1 else "No PCOS"
99
+
100
+ # Define the Gradio interface
101
+ inputs = [
102
+ gr.Number(label="Age (yrs)"),
103
+ gr.Number(label="Weight (Kg)"),
104
+ gr.Number(label="Height (Cm)"),
105
+ gr.Number(label="BMI"),
106
+ gr.Number(label="Blood Group"), # Convert categorical data appropriately if needed
107
+ gr.Number(label="Pulse rate (bpm)"),
108
+ gr.Number(label="RR (breaths/min)"),
109
+ gr.Number(label="Hb (g/dl)"),
110
+ gr.Number(label="Cycle (R/I)"),
111
+ gr.Number(label="Cycle length (days)"),
112
+ gr.Number(label="Marriage Status (Yrs)"),
113
+ gr.Number(label="Pregnant (Y/N)"), # 1 for Yes, 0 for No
114
+ gr.Number(label="No. of abortions"),
115
+ gr.Number(label="FSH (mIU/mL)"),
116
+ gr.Number(label="LH (mIU/mL)"),
117
+ gr.Number(label="FSH/LH"),
118
+ gr.Number(label="Hip (inch)"),
119
+ gr.Number(label="Waist (inch)"),
120
+ gr.Number(label="Waist1 (inch)"),
121
+ gr.Number(label="TSH (mIU/L)"),
122
+ gr.Number(label="PRL (ng/mL)"),
123
+ gr.Number(label="Vit D3 (ng/mL)"),
124
+ gr.Number(label="PRG (ng/mL)"),
125
+ gr.Number(label="RBS (mg/dl)"),
126
+ gr.Number(label="Weight gain (Y/N)"), # 1 for Yes, 0 for No
127
+ gr.Number(label="Hair growth (Y/N)"), # 1 for Yes, 0 for No
128
+ gr.Number(label="Skin darkening (Y/N)"), # 1 for Yes, 0 for No
129
+ gr.Number(label="Hair loss (Y/N)"), # 1 for Yes, 0 for No
130
+ gr.Number(label="Pimples (Y/N)"), # 1 for Yes, 0 for No
131
+ gr.Number(label="Fast food (Y/N)"), # 1 for Yes, 0 for No
132
+ gr.Number(label="Regular Exercise (Y/N)"), # 1 for Yes, 0 for No
133
+ gr.Number(label="BP Systolic (mmHg)"),
134
+ gr.Number(label="BP Diastolic (mmHg)"),
135
+ gr.Number(label="Follicle No. (L)"),
136
+ gr.Number(label="Follicle No. (R)"),
137
+ gr.Number(label="Avg. F size (L) (mm)"),
138
+ gr.Number(label="Avg. F size (R) (mm)"),
139
+ gr.Number(label="Endometrium (mm)")
140
+ ]
141
+
142
+ outputs = gr.Textbox(label="PCOS Prediction")
143
+
144
+ # Create and launch the app
145
+ app = gr.Interface(
146
+ fn=predict_pcos,
147
+ inputs=inputs,
148
+ outputs=outputs,
149
+ title="PCOS Prediction Model",
150
+ description="Enter the patient's information to predict PCOS."
151
+ )
152
+
153
+ app.launch()