Update app.py
Browse files
app.py
CHANGED
|
@@ -2,40 +2,47 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
| 5 |
-
import numpy as np
|
| 6 |
import pandas as pd
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Load your ML model (replace 'model.pkl' with your model file)
|
| 11 |
with open("model.pkl", "rb") as model_file:
|
| 12 |
model = pickle.load(model_file)
|
| 13 |
|
| 14 |
-
# Define
|
| 15 |
-
def
|
| 16 |
"""
|
| 17 |
-
Predict
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
# Set up Gradio interface
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
-
gr.Markdown("##
|
| 26 |
-
gr.Markdown("Enter
|
| 27 |
-
|
| 28 |
with gr.Row():
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Launch the app
|
| 40 |
if __name__ == "__main__":
|
| 41 |
demo.launch()
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
# Load the model
|
|
|
|
|
|
|
| 8 |
with open("model.pkl", "rb") as model_file:
|
| 9 |
model = pickle.load(model_file)
|
| 10 |
|
| 11 |
+
# Define the prediction function
|
| 12 |
+
def predict_diabetes_risk(pregnancies, glucose, blood_pressure, insulin, bmi, age):
|
| 13 |
"""
|
| 14 |
+
Predict diabetes risk based on user inputs.
|
| 15 |
"""
|
| 16 |
+
# Prepare input data
|
| 17 |
+
input_data = np.array([[pregnancies, glucose, blood_pressure, insulin, bmi, age]])
|
| 18 |
+
prediction = model.predict(input_data) # Assuming the model has a `predict` method
|
| 19 |
+
probability = model.predict_proba(input_data)[0][1] # If available, get prediction probability
|
| 20 |
+
risk_level = "High Risk" if prediction[0] == 1 else "Low Risk"
|
| 21 |
+
return f"Risk Level: {risk_level} (Probability: {probability:.2%})"
|
| 22 |
|
| 23 |
+
# Set up the Gradio interface
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("## Diabetes Risk Predictor")
|
| 26 |
+
gr.Markdown("Enter the following details to predict your risk of diabetes.")
|
| 27 |
+
|
| 28 |
with gr.Row():
|
| 29 |
+
pregnancies = gr.Number(label="Pregnancies", value=0)
|
| 30 |
+
glucose = gr.Number(label="Glucose Level", value=0)
|
| 31 |
+
blood_pressure = gr.Number(label="Blood Pressure Level", value=0)
|
| 32 |
+
insulin = gr.Number(label="Insulin Level", value=0)
|
| 33 |
+
bmi = gr.Number(label="BMI (Body Mass Index)", value=0)
|
| 34 |
+
age = gr.Number(label="Age", value=0)
|
| 35 |
+
|
| 36 |
+
predict_button = gr.Button("Predict Risk")
|
| 37 |
+
output = gr.Textbox(label="Prediction Result")
|
| 38 |
+
|
| 39 |
+
predict_button.click(
|
| 40 |
+
predict_diabetes_risk,
|
| 41 |
+
inputs=[pregnancies, glucose, blood_pressure, insulin, bmi, age],
|
| 42 |
+
outputs=output,
|
| 43 |
+
)
|
| 44 |
|
| 45 |
# Launch the app
|
| 46 |
if __name__ == "__main__":
|
| 47 |
demo.launch()
|
| 48 |
+
|