SmartDetector / app.py
Gargi16's picture
Update app.py
c5f57c5 verified
'''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()