File size: 3,113 Bytes
f5a3c6c
121745d
e41131e
 
 
 
 
121745d
e41131e
121745d
 
 
 
 
f5a3c6c
 
 
 
e41131e
f5a3c6c
e41131e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2521e8
 
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
80
#!pip install gradio --upgrade  # Upgrade to the latest version of Gradio
#!pip install huggingface_hub joblib

import gradio as gr
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
import os

# Load the Hugging Face token from the environment variable
token = os.getenv("HF_TOKEN")

if token is None:
    raise ValueError("Hugging Face token not found. Please set the 'HF_TOKEN' environment variable.")

# Download the model and scaler from the Hugging Face Hub using the token
model_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="logistic_regression_model.joblib", use_auth_token=token)
scaler_path = hf_hub_download(repo_id="rama0519/DiabeticLogistic123", filename="scaler.joblib", use_auth_token=token)

# Load the model and scaler
model = joblib.load(model_path)
scaler = joblib.load(scaler_path)

# 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 interface
#interface.launch()
interface.launch(share=True)