File size: 2,931 Bytes
4a8f1b3
2c9bc90
 
 
 
 
4a8f1b3
 
 
 
 
 
 
 
 
 
 
2c9bc90
4a8f1b3
 
2c9bc90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a8f1b3
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Import necessary libraries
import gradio as gr
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download

# Function to download model and scaler from Hugging Face Hub
def download_model():
    # Download the model and scaler
    model_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="logistic_regression_model.joblib")
    scaler_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="scaler.joblib")
    
    # Load the model and scaler
    model = joblib.load(model_path)
    scaler = joblib.load(scaler_path)
    
    return model, scaler

# Load model and scaler
model, scaler = download_model()

# Define reasonable ranges for each input parameter
ranges = {
    'Pregnancies': (0, 20),
    'Glucose': (50, 250),
    'BloodPressure': (40, 140),
    'SkinThickness': (0, 100),
    'Insulin': (0, 900),
    'BMI': (10, 60),
    'DiabetesPedigreeFunction': (0.0, 2.5),
    'Age': (18, 100)
}

# Define the prediction function
def predict_diabetes(pregnancies, glucose, blood_pressure, skin_thickness, insulin, bmi, diabetes_pedigree_function, age):
    data = pd.DataFrame({
        'Pregnancies': [pregnancies],
        'Glucose': [glucose],
        'BloodPressure': [blood_pressure],
        'SkinThickness': [skin_thickness],
        'Insulin': [insulin],
        'BMI': [bmi],
        'DiabetesPedigreeFunction': [diabetes_pedigree_function],
        'Age': [age]
    })

    data_scaled = scaler.transform(data)
    prediction = model.predict(data_scaled)

    # Convert prediction to "Diabetic" (1) or "Not Diabetic" (0)
    if prediction[0] == 1:
        prediction_text = "Diabetic"
    else:
        prediction_text = "Not Diabetic"

    return prediction_text

# Create the Gradio interface
interface = gr.Interface(
    fn=predict_diabetes,
    inputs=[
        gr.Slider(label="Pregnancies", minimum=ranges['Pregnancies'][0], maximum=ranges['Pregnancies'][1]),
        gr.Slider(label="Glucose", minimum=ranges['Glucose'][0], maximum=ranges['Glucose'][1]),
        gr.Slider(label="BloodPressure", minimum=ranges['BloodPressure'][0], maximum=ranges['BloodPressure'][1]),
        gr.Slider(label="SkinThickness", minimum=ranges['SkinThickness'][0], maximum=ranges['SkinThickness'][1]),
        gr.Slider(label="Insulin", minimum=ranges['Insulin'][0], maximum=ranges['Insulin'][1]),
        gr.Slider(label="BMI", minimum=ranges['BMI'][0], maximum=ranges['BMI'][1]),
        gr.Slider(label="DiabetesPedigreeFunction", minimum=ranges['DiabetesPedigreeFunction'][0], maximum=ranges['DiabetesPedigreeFunction'][1]),
        gr.Slider(label="Age", minimum=ranges['Age'][0], maximum=ranges['Age'][1])
    ],
    outputs=gr.Textbox(label="Prediction"),
    title="Diabetes Prediction",
    description="Enter the medical details to predict if the patient is diabetic or not."
)

# Launch the Gradio interface
if __name__ == "__main__":
    interface.launch()