Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,38 @@
|
|
| 1 |
-
import
|
| 2 |
import numpy as np
|
| 3 |
import joblib
|
| 4 |
from sklearn import datasets
|
| 5 |
|
| 6 |
-
#
|
| 7 |
diabetes = datasets.load_diabetes()
|
| 8 |
-
feature_names = diabetes.feature_names
|
| 9 |
|
| 10 |
-
# Load model and scaler
|
| 11 |
model = joblib.load("lr.pkl")
|
| 12 |
scaler = joblib.load("scaler.pkl")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
x_scaled = scaler.transform(x)
|
| 18 |
|
| 19 |
y = model.predict(x_scaled)[0]
|
| 20 |
|
| 21 |
-
# If it's a classification model (LogisticRegression)
|
| 22 |
if hasattr(model, "predict_proba"):
|
| 23 |
-
proba = model.predict_proba(x_scaled)[0]
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
else:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
# 10 numeric inputs (same order as training)
|
| 32 |
-
inputs = [gr.Number(label=name) for name in feature_names]
|
| 33 |
-
|
| 34 |
-
demo = gr.Interface(
|
| 35 |
-
fn=predict,
|
| 36 |
-
inputs=inputs,
|
| 37 |
-
outputs=gr.Textbox(label="Result"),
|
| 38 |
-
title="Diabetes Prediction (load_diabetes + lr + scaler)",
|
| 39 |
-
description="Enter the 10 feature values in the same format used during training."
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
if __name__ == "__main__":
|
| 43 |
-
demo.launch()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
import joblib
|
| 4 |
from sklearn import datasets
|
| 5 |
|
| 6 |
+
# Get feature names from load_diabetes
|
| 7 |
diabetes = datasets.load_diabetes()
|
| 8 |
+
feature_names = diabetes.feature_names
|
| 9 |
|
| 10 |
+
# Load model and scaler
|
| 11 |
model = joblib.load("lr.pkl")
|
| 12 |
scaler = joblib.load("scaler.pkl")
|
| 13 |
|
| 14 |
+
st.title("Diabetes Prediction (load_diabetes + lr + scaler)")
|
| 15 |
+
st.write("This app uses a saved model (lr.pkl) and scaler (scaler.pkl) to make predictions.")
|
| 16 |
+
|
| 17 |
+
inputs = []
|
| 18 |
+
|
| 19 |
+
st.subheader("Enter feature values")
|
| 20 |
+
for name in feature_names:
|
| 21 |
+
val = st.number_input(f"{name}", value=0.0, format="%.4f")
|
| 22 |
+
inputs.append(val)
|
| 23 |
+
|
| 24 |
+
if st.button("Predict"):
|
| 25 |
+
x = np.array(inputs, dtype=float).reshape(1, -1)
|
| 26 |
x_scaled = scaler.transform(x)
|
| 27 |
|
| 28 |
y = model.predict(x_scaled)[0]
|
| 29 |
|
|
|
|
| 30 |
if hasattr(model, "predict_proba"):
|
| 31 |
+
proba = model.predict_proba(x_scaled)[0][1]
|
| 32 |
+
label = "Class 1 (Positive)" if int(y) == 1 else "Class 0 (Negative)"
|
| 33 |
+
st.subheader("Prediction")
|
| 34 |
+
st.write(label)
|
| 35 |
+
st.write(f"Probability of class 1: {proba:.3f}")
|
| 36 |
else:
|
| 37 |
+
st.subheader("Predicted Disease Progression Score")
|
| 38 |
+
st.write(f"{float(y):.2f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|