saad177 commited on
Commit
35e5b86
1 Parent(s): 23a078b

try to add stats

Browse files
Files changed (2) hide show
  1. app.py +130 -29
  2. requirements.txt +3 -1
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import hopsworks
3
  import joblib
4
  import pandas as pd
 
 
5
 
6
  project = hopsworks.login(project="SonyaStern_Lab1")
7
  fs = project.get_feature_store()
@@ -26,35 +28,134 @@ feature_view = fs.get_or_create_feature_view(
26
  diabetes_df = pd.DataFrame(diabetes_fg.read())
27
 
28
 
29
- def diabetes(age, bmi, hba1c_level, blood_glucose_level):
30
- print("Calling diabetes function")
31
- df = pd.DataFrame(
32
- [[age, bmi, hba1c_level, blood_glucose_level]],
33
- columns=["age", "bmi", "hba1c_level", "blood_glucose_level"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  )
35
- print("Predicting")
36
- print(df)
37
- res = model.predict(df)
38
- print(res)
39
- mean_for_age = diabetes_df[
40
- (diabetes_df["diabetes"] == 0) & (diabetes_df["age"] == age)
41
- ].mean()
42
- print("your bmi is:", bmi, "the mean for ur age is :", mean_for_age["bmi"])
43
- return res
44
-
45
-
46
- demo = gr.Interface(
47
- fn=diabetes,
48
- title="Diabetes Prediction",
49
- description="Fill these values with yours",
50
- allow_flagging="never",
51
- inputs=[
52
- gr.Number(label="age"),
53
- gr.Slider(10, 100, label="bmi", info="Body Mass Index"),
54
- gr.Slider(3.5, 9, label="hba1c_level", info="Glycated Haemoglobin"),
55
- gr.Slider(80, 300, label="blood_glucose_level", info="Blood Glucose Level"),
56
- ],
57
- outputs=gr.Number(label="diabetes"),
58
- )
59
 
60
  demo.launch(debug=True)
 
2
  import hopsworks
3
  import joblib
4
  import pandas as pd
5
+ import matplotlib.pyplot as plt
6
+ import numpy as np
7
 
8
  project = hopsworks.login(project="SonyaStern_Lab1")
9
  fs = project.get_feature_store()
 
28
  diabetes_df = pd.DataFrame(diabetes_fg.read())
29
 
30
 
31
+ # def plot_reference(age, bmi, hba1c_level, blood_glucose_level):
32
+ # mean_for_age = diabetes_df[
33
+ # (diabetes_df["diabetes"] == 0) & (diabetes_df["age"] == age)
34
+ # ].mean()
35
+ # print("your bmi is:", bmi, "the mean for ur age is :", mean_for_age["bmi"])
36
+ # categories = ["Age", "BMI", "HbA1c", "Blood Level"]
37
+ # fig, ax = plt.subplots()
38
+ # bar_width = 0.35
39
+ # indices = np.arange(len(categories))
40
+ # ax.bar(
41
+ # indices,
42
+ # [mean_for_age.bmi, mean_for_age.hba1c_level, mean_for_age.blood_glucose_level],
43
+ # bar_width,
44
+ # label="Reference",
45
+ # color="b",
46
+ # alpha=0.7,
47
+ # )
48
+ # ax.bar(
49
+ # indices + bar_width,
50
+ # [bmi, hba1c_level, blood_glucose_level],
51
+ # bar_width,
52
+ # label="User",
53
+ # color="r",
54
+ # alpha=0.7,
55
+ # )
56
+
57
+ # ax.set_xlabel("Variables")
58
+ # ax.set_ylabel("Values")
59
+ # ax.set_title("Comparison of Reference and User Values")
60
+ # ax.set_xticks(indices + bar_width / 2)
61
+ # ax.set_xticklabels(categories)
62
+
63
+
64
+ # def diabetes(age, bmi, hba1c_level, blood_glucose_level):
65
+ # print("Calling diabetes function")
66
+ # df = pd.DataFrame(
67
+ # [[age, bmi, hba1c_level, blood_glucose_level]],
68
+ # columns=["age", "bmi", "hba1c_level", "blood_glucose_level"],
69
+ # )
70
+ # print("Predicting")
71
+ # print(df)
72
+ # res = model.predict(df)
73
+ # print(res)
74
+ # return res
75
+
76
+
77
+ with gr.Blocks() as demo:
78
+ with gr.Row():
79
+ gr.HTML(value="<h1 style='text-align: center;'>Diabetes prediction</h1>")
80
+ with gr.Row():
81
+ with gr.Column():
82
+ age_input = gr.Number(label="age")
83
+ bmi_input = gr.Slider(10, 100, label="bmi", info="Body Mass Index")
84
+ hba1c_input = gr.Slider(
85
+ 3.5, 9, label="hba1c_level", info="Glycated Haemoglobin"
86
+ )
87
+ blood_glucose_input = gr.Slider(
88
+ 80, 300, label="blood_glucose_level", info="Blood Glucose Level"
89
+ )
90
+ btn = gr.Button("Submit")
91
+ with gr.Column():
92
+ output = gr.Text(label="Model prediction")
93
+ plot = gr.Plot()
94
+
95
+ def submit_inputs(age_input, bmi_input, hba1c_input, blood_glucose_input):
96
+ df = pd.DataFrame(
97
+ [[age_input, bmi_input, hba1c_input, blood_glucose_input]],
98
+ columns=["age", "bmi", "hba1c_level", "blood_glucose_level"],
99
+ )
100
+ res = model.predict(df)
101
+
102
+ mean_for_age = diabetes_df[
103
+ (diabetes_df["diabetes"] == 0) & (diabetes_df["age"] == age_input)
104
+ ].mean()
105
+
106
+ print(
107
+ "your bmi is:", bmi_input, "the mean for ur age is :", mean_for_age["bmi"]
108
+ )
109
+ categories = ["Age", "BMI", "HbA1c", "Blood Level"]
110
+ fig, ax = plt.subplots()
111
+ bar_width = 0.35
112
+ indices = np.arange(len(categories))
113
+ ax.bar(
114
+ indices,
115
+ [
116
+ mean_for_age.bmi,
117
+ mean_for_age.hba1c_level,
118
+ mean_for_age.blood_glucose_level,
119
+ ],
120
+ bar_width,
121
+ label="Reference",
122
+ color="b",
123
+ alpha=0.7,
124
+ )
125
+ ax.bar(
126
+ indices + bar_width,
127
+ [bmi_input, hba1c_input, blood_glucose_input],
128
+ bar_width,
129
+ label="User",
130
+ color="r",
131
+ alpha=0.7,
132
+ )
133
+
134
+ ax.set_xlabel("Variables")
135
+ ax.set_ylabel("Values")
136
+ ax.set_title("Comparison of Reference and User Values")
137
+ ax.set_xticks(indices + bar_width / 2)
138
+ ax.set_xticklabels(categories)
139
+
140
+ return res, fig
141
+
142
+ btn.submit(
143
+ submit_inputs,
144
+ [age_input, bmi_input, hba1c_input, blood_glucose_input],
145
+ [output, plot],
146
  )
147
+ # demo = gr.Interface(
148
+ # fn=diabetes,
149
+ # title="Diabetes Prediction",
150
+ # description="Fill these values with yours",
151
+ # allow_flagging="never",
152
+ # inputs=[
153
+ # gr.Number(label="age"),
154
+ # gr.Slider(10, 100, label="bmi", info="Body Mass Index"),
155
+ # gr.Slider(3.5, 9, label="hba1c_level", info="Glycated Haemoglobin"),
156
+ # gr.Slider(80, 300, label="blood_glucose_level", info="Blood Glucose Level"),
157
+ # ],
158
+ # outputs=gr.Number(label="diabetes"),
159
+ # )
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  demo.launch(debug=True)
requirements.txt CHANGED
@@ -2,4 +2,6 @@ gradio
2
  hopsworks
3
  joblib
4
  pandas
5
- scikit-learn==1.1.1
 
 
 
2
  hopsworks
3
  joblib
4
  pandas
5
+ scikit-learn==1.1.1
6
+ matplotlib
7
+ numpy