Spaces:
Sleeping
Sleeping
File size: 6,720 Bytes
e2aa6fe 74a9449 8ee5b2e e2aa6fe b8331ca e2aa6fe 8ee5b2e 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 126a60b c5f57c5 8ee5b2e 126a60b 8ee5b2e |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
'''import gradio as gr
import pickle
import pandas as pd
# Load the saved model
with open("model_AD.pkl", "rb") as f:
model = pickle.load(f)
def predict_pcos(input_features):
# Convert input features into a DataFrame (assuming 8 features here)
input_data = pd.DataFrame([input_features], columns=["Age (yrs)", "BMI", "Weight (Kg)", "Cycle length(days)", "Follicle No. (L)", "Follicle No. (R)", "AMH(ng/mL)", "beta-HCG(mIU/mL)"])
# Predict using the loaded model
prediction = model.predict(input_data)
return "PCOS Positive" if prediction[0] == 1 else "PCOS Negative"
# Define Gradio inputs and outputs
iface = gr.Interface(
fn=predict_pcos,
inputs=[
gr.inputs.Number(label="Age (yrs)"),
gr.inputs.Number(label="BMI"),
gr.inputs.Number(label="Weight (Kg)"),
gr.inputs.Number(label="Cycle length(days)"),
gr.inputs.Number(label="Follicle No. (L)"),
gr.inputs.Number(label="Follicle No. (R)"),
gr.inputs.Number(label="AMH(ng/mL)"),
gr.inputs.Number(label="beta-HCG(mIU/mL)")
],
outputs="text",
title="PCOS Detection",
description="Predicts PCOS based on user-provided medical data."
)
# Launch the Gradio interface
iface.launch()
import gradio as gr
import pickle
import numpy as np
# Load the trained model
with open("model_AD.pkl", "rb") as f:
model = pickle.load(f)
def predict_pcos(age, weight, height, bmi, pulse_rate, cycle_length):
input_data = np.array([[age, weight, height, bmi, pulse_rate, cycle_length]])
prediction = model.predict(input_data)
return "Positive" if prediction[0] == 1 else "Negative"
# Define the Gradio interface
interface = gr.Interface(
fn=predict_pcos,
inputs=[
gr.Number(label="Age (yrs)"),
gr.Number(label="Weight (Kg)"),
gr.Number(label="Height (Cm)"),
gr.Number(label="BMI"),
gr.Number(label="Pulse rate(bpm)"),
gr.Number(label="Cycle length(days)")
],
outputs=gr.Textbox(label="PCOS Prediction"),
title="PCOS Detection Model",
description="Predicts the likelihood of PCOS based on user input features."
)
# Launch the Gradio app
interface.launch()
'''
import gradio as gr
import pickle
import numpy as np
# Load the model
with open('model_AD.pkl', 'rb') as f:
loaded_model = pickle.load(f)
# Define the prediction function
def predict_pcos(
age, weight, height, bmi, blood_group, pulse_rate, rr, hb, cycle_ri,
cycle_length, marriage_status, pregnant, no_of_abortions, fsh, lh, fsh_lh,
hip, waist, waist1, tsh, prl, vit_d3, prg, rbs, weight_gain, hair_growth,
skin_darkening, hair_loss, pimples, fast_food, reg_exercise, bp_systolic,
bp_diastolic, follicle_no_l, follicle_no_r, avg_f_size_l, avg_f_size_r, endometrium):
# Prepare the input data as a single-row array
input_data = np.array([[
age, weight, height, bmi, blood_group, pulse_rate, rr, hb, cycle_ri,
cycle_length, marriage_status, pregnant, no_of_abortions, fsh, lh, fsh_lh,
hip, waist, waist1, tsh, prl, vit_d3, prg, rbs, weight_gain, hair_growth,
skin_darkening, hair_loss, pimples, fast_food, reg_exercise, bp_systolic,
bp_diastolic, follicle_no_l, follicle_no_r, avg_f_size_l, avg_f_size_r, endometrium
]])
# Get prediction
prediction = loaded_model.predict(input_data)[0]
return "PCOS Detected" if prediction == 1 else "No PCOS"
# Define the Gradio interface
inputs = [
gr.Number(label="Age (yrs)"),
gr.Number(label="Weight (Kg)"),
gr.Number(label="Height (Cm)"),
gr.Number(label="BMI"),
gr.Number(label="Blood Group"), # Convert categorical data appropriately if needed
gr.Number(label="Pulse rate (bpm)"),
gr.Number(label="RR (breaths/min)"),
gr.Number(label="Hb (g/dl)"),
gr.Number(label="Cycle (R/I)"),
gr.Number(label="Cycle length (days)"),
gr.Number(label="Marriage Status (Yrs)"),
gr.Number(label="Pregnant (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="No. of abortions"),
gr.Number(label="FSH (mIU/mL)"),
gr.Number(label="LH (mIU/mL)"),
gr.Number(label="FSH/LH"),
gr.Number(label="Hip (inch)"),
gr.Number(label="Waist (inch)"),
gr.Number(label="Waist1 (inch)"),
gr.Number(label="TSH (mIU/L)"),
gr.Number(label="PRL (ng/mL)"),
gr.Number(label="Vit D3 (ng/mL)"),
gr.Number(label="PRG (ng/mL)"),
gr.Number(label="RBS (mg/dl)"),
gr.Number(label="Weight gain (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Hair growth (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Skin darkening (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Hair loss (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Pimples (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Fast food (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="Regular Exercise (Y/N)"), # 1 for Yes, 0 for No
gr.Number(label="BP Systolic (mmHg)"),
gr.Number(label="BP Diastolic (mmHg)"),
gr.Number(label="Follicle No. (L)"),
gr.Number(label="Follicle No. (R)"),
gr.Number(label="Avg. F size (L) (mm)"),
gr.Number(label="Avg. F size (R) (mm)"),
gr.Number(label="Endometrium (mm)")
]
outputs = gr.Textbox(label="PCOS Prediction")
custom_css = """
body {
background-color: #eafaf8;
color: #333333;
font-family: Arial, sans-serif;
}
.gradio-container {
background: #ffffff;
border: 2px solid #d4efdf;
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.input, .output {
font-size: 16px;
color: #2e4053;
}
.gr-button {
background-color: #76d7c4;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
font-size: 14px;
font-weight: bold;
cursor: pointer;
border-radius: 8px;
transition: background-color 0.3s ease;
}
.gr-button:hover {
background-color: #48c9b0;
}
.gr-input, .gr-textbox {
border: 1px solid #a9dfbf;
border-radius: 5px;
padding: 8px;
font-size: 14px;
}
.gr-title {
font-size: 24px;
font-weight: bold;
color: #1abc9c;
text-align: center;
margin-bottom: 10px;
}
.gr-description {
font-size: 16px;
color: #5d6d7e;
text-align: center;
margin-bottom: 20px;
}
"""
# Create and launch the app
app = gr.Interface(
fn=predict_pcos,
inputs=inputs,
outputs=outputs,
title="PCOS Prediction Model",
description="Enter the patient's information to predict PCOS.",
css=custom_css
)
app.launch()
|