Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,71 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
import pandas as pd
|
5 |
-
import joblib
|
6 |
-
from huggingface_hub import hf_hub_download
|
7 |
-
|
8 |
-
# Load the model and scaler from Hugging Face Hub
|
9 |
-
model_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="logistic_regression_model.joblib")
|
10 |
-
scaler_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="scaler.joblib")
|
11 |
-
|
12 |
-
model = joblib.load(model_path)
|
13 |
-
scaler = joblib.load(scaler_path)
|
14 |
-
|
15 |
-
# Define reasonable ranges for each input parameter
|
16 |
-
ranges = {
|
17 |
-
'Pregnancies': (0, 20),
|
18 |
-
'Glucose': (50, 250),
|
19 |
-
'BloodPressure': (40, 140),
|
20 |
-
'SkinThickness': (0, 100),
|
21 |
-
'Insulin': (0, 900),
|
22 |
-
'BMI': (10, 60),
|
23 |
-
'DiabetesPedigreeFunction': (0.0, 2.5),
|
24 |
-
'Age': (18, 100)
|
25 |
-
}
|
26 |
-
|
27 |
-
# Define the prediction function
|
28 |
-
def predict_diabetes(pregnancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age):
|
29 |
-
data = pd.DataFrame({
|
30 |
-
'Pregnancies': [pregnancies],
|
31 |
-
'Glucose': [glucose],
|
32 |
-
'BloodPressure': [blood_pressure],
|
33 |
-
'SkinThickness': [skin_thickness],
|
34 |
-
'Insulin': [insulin],
|
35 |
-
'BMI': [bmi],
|
36 |
-
'DiabetesPedigreeFunction': [diabetes_pedigree_function],
|
37 |
-
'Age': [age]
|
38 |
-
})
|
39 |
-
|
40 |
-
data_scaled = scaler.transform(data)
|
41 |
-
prediction = model.predict(data_scaled)
|
42 |
-
|
43 |
-
# Convert prediction to "Diabetic" (1) or "Not Diabetic" (0)
|
44 |
-
if prediction[0] == 1:
|
45 |
-
prediction_text = "Diabetic"
|
46 |
-
else:
|
47 |
-
prediction_text = "Not Diabetic"
|
48 |
-
|
49 |
-
return prediction_text
|
50 |
-
|
51 |
-
# Create the Gradio interface
|
52 |
-
# Use gr.Slider to allow for setting min and max values
|
53 |
-
interface = gr.Interface(
|
54 |
-
fn=predict_diabetes,
|
55 |
-
inputs=[
|
56 |
-
gr.Slider(label="Pregnancies", minimum=ranges['Pregnancies'][0], maximum=ranges['Pregnancies'][1]),
|
57 |
-
gr.Slider(label="Glucose", minimum=ranges['Glucose'][0], maximum=ranges['Glucose'][1]),
|
58 |
-
gr.Slider(label="BloodPressure", minimum=ranges['BloodPressure'][0], maximum=ranges['BloodPressure'][1]),
|
59 |
-
gr.Slider(label="SkinThickness", minimum=ranges['SkinThickness'][0], maximum=ranges['SkinThickness'][1]),
|
60 |
-
gr.Slider(label="Insulin", minimum=ranges['Insulin'][0], maximum=ranges['Insulin'][1]),
|
61 |
-
gr.Slider(label="BMI", minimum=ranges['BMI'][0], maximum=ranges['BMI'][1]),
|
62 |
-
gr.Slider(label="DiabetesPedigreeFunction", minimum=ranges['DiabetesPedigreeFunction'][0], maximum=ranges['DiabetesPedigreeFunction'][1]),
|
63 |
-
gr.Slider(label="Age", minimum=ranges['Age'][0], maximum=ranges['Age'][1])
|
64 |
-
],
|
65 |
-
outputs=gr.Textbox(label="Prediction"),
|
66 |
-
title="Diabetes Prediction",
|
67 |
-
description="Enter the medical details to predict if the patient is diabetic or not."
|
68 |
-
)
|
69 |
-
|
70 |
-
# Launch the interface
|
71 |
interface.launch()
|
|
|
1 |
+
#!pip install gradio --upgrade # Upgrade to the latest version of Gradio
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import joblib
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
+
|
8 |
+
# Load the model and scaler from Hugging Face Hub
|
9 |
+
model_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="logistic_regression_model.joblib")
|
10 |
+
scaler_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="scaler.joblib")
|
11 |
+
|
12 |
+
model = joblib.load(model_path)
|
13 |
+
scaler = joblib.load(scaler_path)
|
14 |
+
|
15 |
+
# Define reasonable ranges for each input parameter
|
16 |
+
ranges = {
|
17 |
+
'Pregnancies': (0, 20),
|
18 |
+
'Glucose': (50, 250),
|
19 |
+
'BloodPressure': (40, 140),
|
20 |
+
'SkinThickness': (0, 100),
|
21 |
+
'Insulin': (0, 900),
|
22 |
+
'BMI': (10, 60),
|
23 |
+
'DiabetesPedigreeFunction': (0.0, 2.5),
|
24 |
+
'Age': (18, 100)
|
25 |
+
}
|
26 |
+
|
27 |
+
# Define the prediction function
|
28 |
+
def predict_diabetes(pregnancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age):
|
29 |
+
data = pd.DataFrame({
|
30 |
+
'Pregnancies': [pregnancies],
|
31 |
+
'Glucose': [glucose],
|
32 |
+
'BloodPressure': [blood_pressure],
|
33 |
+
'SkinThickness': [skin_thickness],
|
34 |
+
'Insulin': [insulin],
|
35 |
+
'BMI': [bmi],
|
36 |
+
'DiabetesPedigreeFunction': [diabetes_pedigree_function],
|
37 |
+
'Age': [age]
|
38 |
+
})
|
39 |
+
|
40 |
+
data_scaled = scaler.transform(data)
|
41 |
+
prediction = model.predict(data_scaled)
|
42 |
+
|
43 |
+
# Convert prediction to "Diabetic" (1) or "Not Diabetic" (0)
|
44 |
+
if prediction[0] == 1:
|
45 |
+
prediction_text = "Diabetic"
|
46 |
+
else:
|
47 |
+
prediction_text = "Not Diabetic"
|
48 |
+
|
49 |
+
return prediction_text
|
50 |
+
|
51 |
+
# Create the Gradio interface
|
52 |
+
# Use gr.Slider to allow for setting min and max values
|
53 |
+
interface = gr.Interface(
|
54 |
+
fn=predict_diabetes,
|
55 |
+
inputs=[
|
56 |
+
gr.Slider(label="Pregnancies", minimum=ranges['Pregnancies'][0], maximum=ranges['Pregnancies'][1]),
|
57 |
+
gr.Slider(label="Glucose", minimum=ranges['Glucose'][0], maximum=ranges['Glucose'][1]),
|
58 |
+
gr.Slider(label="BloodPressure", minimum=ranges['BloodPressure'][0], maximum=ranges['BloodPressure'][1]),
|
59 |
+
gr.Slider(label="SkinThickness", minimum=ranges['SkinThickness'][0], maximum=ranges['SkinThickness'][1]),
|
60 |
+
gr.Slider(label="Insulin", minimum=ranges['Insulin'][0], maximum=ranges['Insulin'][1]),
|
61 |
+
gr.Slider(label="BMI", minimum=ranges['BMI'][0], maximum=ranges['BMI'][1]),
|
62 |
+
gr.Slider(label="DiabetesPedigreeFunction", minimum=ranges['DiabetesPedigreeFunction'][0], maximum=ranges['DiabetesPedigreeFunction'][1]),
|
63 |
+
gr.Slider(label="Age", minimum=ranges['Age'][0], maximum=ranges['Age'][1])
|
64 |
+
],
|
65 |
+
outputs=gr.Textbox(label="Prediction"),
|
66 |
+
title="Diabetes Prediction",
|
67 |
+
description="Enter the medical details to predict if the patient is diabetic or not."
|
68 |
+
)
|
69 |
+
|
70 |
+
# Launch the interface
|
71 |
interface.launch()
|