saad177 commited on
Commit
4b8158a
1 Parent(s): 9ab4c69

add user data saving

Browse files
Files changed (1) hide show
  1. app.py +33 -8
app.py CHANGED
@@ -15,11 +15,11 @@ model_dir = model.download()
15
  model = joblib.load(model_dir + "/diabetes_model.pkl")
16
  print("Model downloaded")
17
 
18
- diabetes_fg = fs.get_feature_group(name="diabetes", version=1)
19
  query = diabetes_fg.select_all()
20
  # feature_view = fs.get_or_create_feature_view(name="diabetes",
21
  feature_view = fs.get_or_create_feature_view(
22
- name="diabetes",
23
  version=1,
24
  description="Read from Diabetes dataset",
25
  labels=["diabetes"],
@@ -40,11 +40,11 @@ with gr.Blocks() as demo:
40
  blood_glucose_input = gr.Slider(
41
  80, 300, label="blood_glucose_level", info="Blood Glucose Level"
42
  )
43
- gr.Radio(
44
- ["yes", "no"],
45
- label="if you already know that you have diabetes, select yes, else select no",
46
  )
47
- gr.Checkbox(
48
  info="I consent that my personal data will be saved and potentially be used for the model training",
49
  label="accept",
50
  )
@@ -53,7 +53,14 @@ with gr.Blocks() as demo:
53
  output = gr.Text(label="Model prediction")
54
  plot = gr.Plot()
55
 
56
- def submit_inputs(age_input, bmi_input, hba1c_input, blood_glucose_input):
 
 
 
 
 
 
 
57
  df = pd.DataFrame(
58
  [[age_input, bmi_input, hba1c_input, blood_glucose_input]],
59
  columns=["age", "bmi", "hba1c_level", "blood_glucose_level"],
@@ -99,11 +106,29 @@ with gr.Blocks() as demo:
99
  ax.set_xticklabels(categories)
100
 
101
  ## save user's data in hopsworks
 
 
 
 
 
 
 
 
 
 
 
102
  return res, fig
103
 
104
  btn.click(
105
  submit_inputs,
106
- inputs=[age_input, bmi_input, hba1c_input, blood_glucose_input],
 
 
 
 
 
 
 
107
  outputs=[output, plot],
108
  )
109
 
 
15
  model = joblib.load(model_dir + "/diabetes_model.pkl")
16
  print("Model downloaded")
17
 
18
+ diabetes_fg = fs.get_feature_group(name="diabetes_gan", version=1)
19
  query = diabetes_fg.select_all()
20
  # feature_view = fs.get_or_create_feature_view(name="diabetes",
21
  feature_view = fs.get_or_create_feature_view(
22
+ name="diabetes_gan",
23
  version=1,
24
  description="Read from Diabetes dataset",
25
  labels=["diabetes"],
 
40
  blood_glucose_input = gr.Slider(
41
  80, 300, label="blood_glucose_level", info="Blood Glucose Level"
42
  )
43
+ existent_info_input = gr.Radio(
44
+ ["yes", "no", "Don't know"],
45
+ label="Do you already know if you have diabetes? (This will not be used for the prediction)",
46
  )
47
+ consent_input = gr.Checkbox(
48
  info="I consent that my personal data will be saved and potentially be used for the model training",
49
  label="accept",
50
  )
 
53
  output = gr.Text(label="Model prediction")
54
  plot = gr.Plot()
55
 
56
+ def submit_inputs(
57
+ age_input,
58
+ bmi_input,
59
+ hba1c_input,
60
+ blood_glucose_input,
61
+ existent_info_input,
62
+ consent_input,
63
+ ):
64
  df = pd.DataFrame(
65
  [[age_input, bmi_input, hba1c_input, blood_glucose_input]],
66
  columns=["age", "bmi", "hba1c_level", "blood_glucose_level"],
 
106
  ax.set_xticklabels(categories)
107
 
108
  ## save user's data in hopsworks
109
+ if consent_input == True:
110
+ user_data_fg = fs.get_or_create_feature_view(
111
+ name="user_diabetes_data",
112
+ version=1,
113
+ primary_key=["age", "bmi", "hba1c_level", "blood_glucose_level"],
114
+ description="Submitted user data",
115
+ )
116
+ user_data_df = df.copy()
117
+ user_data_df["diabetes"] = existent_info_input
118
+ user_data_fg.insert(user_data_df)
119
+ print("inserted new user data to hopsworks", user_data_df)
120
  return res, fig
121
 
122
  btn.click(
123
  submit_inputs,
124
+ inputs=[
125
+ age_input,
126
+ bmi_input,
127
+ hba1c_input,
128
+ blood_glucose_input,
129
+ existent_info_input,
130
+ consent_input,
131
+ ],
132
  outputs=[output, plot],
133
  )
134