asmaa1 commited on
Commit
6ff936b
·
verified ·
1 Parent(s): 22cad87

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import gradio as gr
3
+
4
+ # Load the saved model
5
+ gbc = joblib.load('diabetes_model.pkl')
6
+
7
+ def prediction(a, b, c, d, e, f, g, h):
8
+ try:
9
+ # Create a DataFrame for the new input
10
+ new_data = [[a, b, c, d, e, f, g, h]]
11
+
12
+ # Make a prediction
13
+ result = gbc.predict(new_data)
14
+
15
+ # Print the inputs
16
+ input_data = {
17
+ "Pregnancies": a,
18
+ "Glucose": b,
19
+ "BloodPressure": c,
20
+ "SkinThickness": d,
21
+ "Insulin": e,
22
+ "BMI": f,
23
+ "DiabetesPedigreeFunction": g,
24
+ "Age": h,
25
+ }
26
+
27
+ print("User Input:", input_data) # Print inputs to the console
28
+
29
+ # Determine the prediction message
30
+ if result[0] == 0:
31
+ prediction_message = "Based on your results, you are not diabetic. Maintain a healthy lifestyle and regular check-ups."
32
+ else:
33
+ prediction_message = "Your results indicate that you are diabetic. Please consult with a healthcare professional for further guidance and management."
34
+
35
+ # Return both the prediction and the image URL
36
+ return prediction_message, image_url
37
+ except Exception as e:
38
+ return f"Error: {str(e)}", None # Return None for the image in case of error
39
+
40
+ # Example values
41
+ example_inputs = [6, 148.0, 72.0, 35.0, 79.799479, 33.6, 0.627, 50]
42
+
43
+ # Image URL (replace this with a direct image URL)
44
+ image_url = "pngtree-world-diabetes-day-raising-awareness-for-a-healthier-future-png-image_14138135.png"
45
+
46
+ # Create the Gradio interface with a soft theme
47
+ app = gr.Interface(
48
+ fn=prediction,
49
+ inputs=[
50
+ gr.Number(label="Pregnancies", value=example_inputs[0]),
51
+ gr.Number(label="Glucose", value=example_inputs[1]),
52
+ gr.Number(label="BloodPressure", value=example_inputs[2]),
53
+ gr.Number(label="SkinThickness", value=example_inputs[3]),
54
+ gr.Number(label="Insulin", value=example_inputs[4]),
55
+ gr.Number(label="BMI", value=example_inputs[5]),
56
+ gr.Number(label="DiabetesPedigreeFunction", value=example_inputs[6]),
57
+ gr.Number(label="Age", value=example_inputs[7])
58
+ ],
59
+ outputs=[gr.Text(label="Prediction"), gr.Image(value=image_url, label="Image", show_label=True)],
60
+ title="Diabetes Prediction",
61
+ theme=gr.themes.Soft()
62
+ )
63
+
64
+ # Launch the app
65
+ app.launch()