Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +38 -0
- random_forest_model.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model = joblib.load("random_forest_model.pkl")
|
| 7 |
+
|
| 8 |
+
# Prediction function
|
| 9 |
+
def predict_insulin(age, gender, height, weight, bmi, smoking, alcoholic, dm_years, hba1c, fbs, ppbs):
|
| 10 |
+
gender = 1 if gender.lower() == "male" else 0
|
| 11 |
+
smoking = 1 if smoking.lower() == "yes" else 0
|
| 12 |
+
alcoholic = 1 if alcoholic.lower() == "yes" else 0
|
| 13 |
+
|
| 14 |
+
features = np.array([[age, gender, height, weight, bmi, smoking, alcoholic, dm_years, hba1c, fbs, ppbs]])
|
| 15 |
+
prediction = model.predict(features)[0]
|
| 16 |
+
|
| 17 |
+
return "Needs Insulin" if prediction == 1 else "No Insulin Needed"
|
| 18 |
+
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=predict_insulin,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.Number(label="Age"),
|
| 23 |
+
gr.Radio(["Male", "Female"], label="Gender"),
|
| 24 |
+
gr.Number(label="Height (cm)"),
|
| 25 |
+
gr.Number(label="Weight (kg)"),
|
| 26 |
+
gr.Number(label="BMI"),
|
| 27 |
+
gr.Radio(["Yes", "No"], label="Smoking"),
|
| 28 |
+
gr.Radio(["Yes", "No"], label="Alcoholic"),
|
| 29 |
+
gr.Number(label="Diabetes Duration (Years)"),
|
| 30 |
+
gr.Number(label="HbA1c"),
|
| 31 |
+
gr.Number(label="FBS"),
|
| 32 |
+
gr.Number(label="PPBS")
|
| 33 |
+
],
|
| 34 |
+
outputs=gr.Text(label="Prediction"),
|
| 35 |
+
title="Insulin Dependency Predictor"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
iface.launch()
|
random_forest_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5b4daa62fd7160929e783f0b1deafe8087a1a2a1aeee4e536b7250acc6303958
|
| 3 |
+
size 75385
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
scikit-learn
|
| 3 |
+
numpy
|
| 4 |
+
joblib
|