marirena commited on
Commit
4755faa
·
verified ·
1 Parent(s): dc9e8e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -41
app.py CHANGED
@@ -26,9 +26,9 @@ data1 = {'ratio':[0.053910],
26
  'illuminance':[10646.052788] ,
27
  'Kitchen_night_illuminance':[76.282996],
28
  'Lounge_night_illuminance':[83.069952] ,
29
- 'Bathroom_night_temperature':[20.639559],
30
  'Bathroom_evening_temperature':[21.449295],
31
- 'Bathroom_night_activity':[19.367503],
32
  'number_transitions':[222.017461],
33
  'temperature_ratio':[2.004192],
34
  'awake_ratio':[0.207502],
@@ -48,8 +48,8 @@ data2 = {'ratio' :[0.030281],
48
  'illuminance': [7337.315382],
49
  'Kitchen_night_illuminance': [54.300962],
50
  'Lounge_night_illuminance' :[116.355455],
51
- 'Bathroom_night_temperature':[2.007301],
52
- 'Bathroom_evening_temperature':[2.087516],
53
  'Bathroom_night_activity':[35.206093] ,
54
  'number_transitions':[94.177603],
55
  'temperature_ratio':[4.045142],
@@ -100,7 +100,7 @@ top_features= ['ratio',
100
  'illuminance',
101
  'Kitchen_night_illuminance',
102
  'Lounge_night_illuminance',
103
- 'Bathroom_night_temperature',
104
  'Bathroom_evening_temperature',
105
  'Bathroom_night_activity',
106
  'number_transitions',
@@ -121,10 +121,10 @@ def update_sliders(example_df):
121
  Lounge_night_illuminance = example_data['Lounge_night_illuminance'].astype(float).iloc[-1]
122
  ratio = example_data['ratio'].astype(float).iloc[-1]
123
  Kitchen_night_temperature= example_data['Kitchen_night_temperature'].astype(float).iloc[-1]
124
- Bathroom_night_temperature= example_data['Bathroom_night_temperature'].astype(float).iloc[-1]
125
  Bathroom_evening_temperature= example_data['Bathroom_evening_temperature'].astype(float).iloc[-1]
126
  temperature_ratio = example_data['temperature_ratio'].astype(float).iloc[-1]
127
- return Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
128
 
129
 
130
  # %%
@@ -133,7 +133,7 @@ blue = sns.color_palette()[0]
133
  red = sns.color_palette()[1]
134
 
135
  # %%
136
- def predict(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio):
137
  example_data = example_df
138
  example_df_norm = normalize(example_data, mean_df, std_df, top_features)
139
  feature_values = example_df_norm[top_features].iloc[0]
@@ -198,7 +198,7 @@ def predict(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance,
198
  else:
199
  statement= "The temperature in the bathroom in the evening was lower than usual."
200
  statements.append(statement)
201
- elif feature == "Bathroom_night_temperature":
202
  if feature_direction == "positive":
203
  statement= "The temperature in the bathroom in the night was higher than usual."
204
  statements.append(statement)
@@ -320,7 +320,7 @@ def predict(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance,
320
  import shap
321
  import matplotlib.pyplot as plt
322
 
323
- def interpret(example_df,Lounge_night_illuminance, Kitchen_night_illuminance, Kitchen_afternoon_illuminance, ratio, temperature_ratio, Bathroom_night_temperature, Bathroom_evening_temperature, Kitchen_night_temperature):
324
  # Read the example data
325
  example_data = example_df
326
 
@@ -395,13 +395,13 @@ def interpret(example_df,Lounge_night_illuminance, Kitchen_night_illuminance, Ki
395
 
396
 
397
  # %%
398
- def update_data(example_df, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio):
399
  example_data = example_df
400
  example_data['Lounge_night_illuminance'].iloc[0] = Lounge_night_illuminance
401
  example_data['Kitchen_night_illuminance'].iloc[0] = Kitchen_night_illuminance
402
  example_data['Kitchen_afternoon_illuminance'].iloc[0] = Kitchen_afternoon_illuminance
403
  example_data['ratio'].iloc[0] = ratio
404
- example_data['Bathroom_night_temperature'].iloc[0] = Bathroom_night_temperature
405
  example_data['Bathroom_evening_temperature'].iloc[0] = Bathroom_evening_temperature
406
  example_data['Kitchen_night_temperature'].iloc[0] = Kitchen_night_temperature
407
  example_data['temperature_ratio'].iloc[0] = temperature_ratio
@@ -475,7 +475,7 @@ def update_data(example_df, Kitchen_afternoon_illuminance, Lounge_night_illumina
475
  else:
476
  statement= "The temperature in the bathroom in the evening was lower than usual."
477
  statements.append(statement)
478
- elif feature == "Bathroom_night_temperature":
479
  if feature_direction == "positive":
480
  statement= "The temperature in the bathroom in the night was higher than usual."
481
  statements.append(statement)
@@ -517,7 +517,7 @@ def update_data(example_df, Kitchen_afternoon_illuminance, Lounge_night_illumina
517
  else:
518
  statement="The indoor light exposure in the kitchen at night was lower than usual."
519
  statements.append(statement)
520
- elif feature == "Bathroom_night_temperature":
521
  if feature_direction == "positive":
522
  statement="The temperature in the bathroom at night was higher than usual."
523
  statements.append(statement)
@@ -679,7 +679,7 @@ def generate_data():
679
  df['Kitchen_afternoon_illuminance'] = np.random.uniform(0, 5000)
680
  df['ratio'] = np.random.uniform(0, 15)
681
  df['temperature_ratio'] = np.random.uniform(-1.5, 1.5)
682
- df['Bathroom_night_temperature'] = np.random.uniform(0, 40) # Random value between 0 and 40
683
  df['Bathroom_evening_temperature'] = np.random.uniform(0, 40)
684
  df['Kitchen_night_temperature'] = np.random.uniform(0, 40)
685
  df['number_transitions'] = np.random.uniform(0,500)
@@ -692,11 +692,11 @@ def generate_data():
692
  Lounge_night_illuminance = df['Lounge_night_illuminance'].astype(float).iloc[-1]
693
  ratio = df['ratio'].astype(float).iloc[-1]
694
  Kitchen_night_temperature= df['Kitchen_night_temperature'].astype(float).iloc[-1]
695
- Bathroom_night_temperature= df['Bathroom_night_temperature'].astype(float).iloc[-1]
696
  Bathroom_evening_temperature= df['Bathroom_evening_temperature'].astype(float).iloc[-1]
697
  temperature_ratio = df['temperature_ratio'].astype(float).iloc[-1]
698
 
699
- return df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
700
 
701
  # %%
702
  import pandas as pd
@@ -709,7 +709,7 @@ def return_original(example_df):
709
  Kitchen_afternoon_illuminance = example_data['Kitchen_afternoon_illuminance'].astype(float).iloc[-1]
710
  ratio = example_data['ratio'].astype(float).iloc[-1]
711
  temperature_ratio = example_data['temperature_ratio'].astype(float).iloc[-1]
712
- Bathroom_night_temperature= example_data['Bathroom_night_temperature'].astype(float).iloc[-1]
713
  Bathroom_evening_temperature= example_data['Bathroom_evening_temperature'].astype(float).iloc[-1]
714
  Kitchen_night_temperature= example_data['Kitchen_night_temperature'].astype(float).iloc[-1]
715
  example_df_norm = normalize(example_data, mean_df, std_df, top_features)
@@ -783,12 +783,12 @@ def return_original(example_df):
783
  else:
784
  statement= "The temperature in the bathroom in the evening was lower than usual."
785
  statements.append(statement)
786
- elif feature == "Bathroom_night_temperature":
787
  if feature_direction == "positive":
788
- statement= "The temperature in the bathroom in the night was higher than usual."
789
  statements.append(statement)
790
  else:
791
- statement= "The temperature in the bathroom in the night was lower than usual."
792
  statements.append(statement)
793
  elif feature == "Kitchen_afternoon_illuminance":
794
  if feature_direction == "positive":
@@ -937,7 +937,7 @@ def return_original(example_df):
937
  plt.yticks(fontsize=28)
938
  plt.tight_layout()
939
 
940
- return {"Agitated": float(proba[0][1]), "Non-agitated": float(proba[0][0])}, formatted_statements, plot,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
941
 
942
 
943
  # Plotting for negative class predictions (class label 0)
@@ -964,18 +964,18 @@ def return_original(example_df):
964
  plt.yticks(fontsize=28)
965
  plt.tight_layout()
966
 
967
- return {"Agitated": float(proba[0][1]), "Non-agitated": float(proba[0][0])}, formatted_statements, plot, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
968
 
969
 
970
 
971
- def save_file(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio):
972
  example_data = example_df
973
  example_data['Lounge_night_illuminance'] = Lounge_night_illuminance
974
  example_data['Kitchen_night_illuminance'] = Kitchen_night_illuminance
975
  example_data['Kitchen_afternoon_illuminance'] = Kitchen_afternoon_illuminance
976
  example_data['ratio'] = ratio
977
  example_data['temperature_ratio'] = temperature_ratio
978
- example_data['Bathroom_night_temperature'] = Bathroom_night_temperature
979
  example_data['Bathroom_evening_temperature'] = Bathroom_evening_temperature
980
  example_data['Kitchen_night_temperature'] = Kitchen_night_temperature
981
  current_path = os.getcwd()
@@ -1003,7 +1003,7 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="md", primary_hue="red", sec
1003
  with gr.Row():
1004
  with gr.Column():
1005
  generate = gr.Button(value="Generate synthetic patient data")
1006
- csv_file = gr.DataFrame(headers=['ratio', 'sunset_minutes', 'Kitchen_night_temperature', 'uvindex', 'visibility','illuminance','Kitchen_night_illuminance','Lounge_night_illuminance','Bathroom_night_temperature','Bathroom_evening_temperature', 'Bathroom_night_activity', 'number_transitions', 'temperature_ratio', 'awake_ratio','rr_min','To_bed', 'Lounge_afternoon_activity','rr_average',"rr_min_std",'Kitchen_afternoon_illuminance'],row_count=1 , col_count=20, datatype = "number", interactive=False)
1007
  modif = gr.Button(value="Change the modifiable parameters to see how agitation risk changes")
1008
  gr.Markdown("""<p style="margin-top: 20px; font-size: 16px; font-weight: bold;"> Light exposure </p>""")
1009
  Kitchen_afternoon_illuminance = gr.Slider(label="Mean afternoon illuminance in kitchen", minimum=0, maximum=3000, step=100)
@@ -1011,7 +1011,7 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="md", primary_hue="red", sec
1011
  Lounge_night_illuminance = gr.Slider(label="Mean night illuminance in lounge", minimum=0, maximum=3000, step=100, every=True)
1012
  ratio = gr.Slider(label="Ratio (indoor:outdoor illuminance)", minimum=0, maximum=0.35, step=0.1)
1013
  gr.Markdown("""<p style="margin-top: 20px; font-size: 16px; font-weight: bold;"> Ambient temperature </p>""")
1014
- Bathroom_night_temperature = gr.Slider(label="Mean night temperature in bathroom", minimum=-10, maximum=45, step=0.5)
1015
  Bathroom_evening_temperature = gr.Slider(label="Mean evening temperature in bathroom", minimum=-10, maximum=45, step=0.5)
1016
  Kitchen_night_temperature = gr.Slider(label="Mean night temperature in kitchen", minimum=-10, maximum=45, step=0.5)
1017
  temperature_ratio = gr.Slider(label="Ratio (indoor:outdoor temperature)", minimum=-500, maximum=60, step=0.1)
@@ -1026,21 +1026,21 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="md", primary_hue="red", sec
1026
  plot = gr.Plot(scale=2, label="Interpretation")
1027
 
1028
  with gr.Row():
1029
- generate.click(generate_data, outputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio])
1030
- Lounge_night_illuminance.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text, plot])
1031
- Kitchen_night_illuminance.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text, plot])
1032
- Kitchen_afternoon_illuminance.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1033
- Bathroom_night_temperature.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1034
- ratio.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1035
- temperature_ratio.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1036
- Bathroom_night_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1037
- Bathroom_evening_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1038
- Kitchen_night_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1039
 
1040
  predict_btn.click(
1041
  predict,
1042
  inputs=[
1043
- csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
1044
  ],
1045
  outputs=[label,html_text]
1046
  )
@@ -1048,7 +1048,7 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="md", primary_hue="red", sec
1048
  interpret_btn.click(
1049
  interpret,
1050
  inputs=[
1051
- csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio
1052
  ],
1053
  outputs=[plot],
1054
  )
@@ -1058,12 +1058,12 @@ with gr.Blocks(theme=gr.themes.Default(spacing_size="md", primary_hue="red", sec
1058
  inputs=[
1059
  csv_file
1060
  ],
1061
- outputs=[label,html_text, plot, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio],
1062
  )
1063
 
1064
  flag.click(
1065
  save_file,
1066
- inputs= [csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Bathroom_night_temperature, Bathroom_evening_temperature, temperature_ratio],
1067
  )
1068
  with gr.Row():
1069
  gr.Markdown("<img src='https://ukdri.ac.uk/assets/img/logo.svg' alt='UKDRI' width='250' style='margin-top: 50px;'>")
 
26
  'illuminance':[10646.052788] ,
27
  'Kitchen_night_illuminance':[76.282996],
28
  'Lounge_night_illuminance':[83.069952] ,
29
+ 'Kitchen_morning_temperature' :[83.069952] ,
30
  'Bathroom_evening_temperature':[21.449295],
31
+ 'Bathroom_night_activity':[19.367503],
32
  'number_transitions':[222.017461],
33
  'temperature_ratio':[2.004192],
34
  'awake_ratio':[0.207502],
 
48
  'illuminance': [7337.315382],
49
  'Kitchen_night_illuminance': [54.300962],
50
  'Lounge_night_illuminance' :[116.355455],
51
+ 'Bathroom_evening_temperature':[2.087516],
52
+ 'Kitchen_morning_temperature': [54.300962],
53
  'Bathroom_night_activity':[35.206093] ,
54
  'number_transitions':[94.177603],
55
  'temperature_ratio':[4.045142],
 
100
  'illuminance',
101
  'Kitchen_night_illuminance',
102
  'Lounge_night_illuminance',
103
+ 'Bathroom_morning_temperature',
104
  'Bathroom_evening_temperature',
105
  'Bathroom_night_activity',
106
  'number_transitions',
 
121
  Lounge_night_illuminance = example_data['Lounge_night_illuminance'].astype(float).iloc[-1]
122
  ratio = example_data['ratio'].astype(float).iloc[-1]
123
  Kitchen_night_temperature= example_data['Kitchen_night_temperature'].astype(float).iloc[-1]
124
+ Kitchen_morning_temperature= example_data['Kitchen_morning_temperature'].astype(float).iloc[-1]
125
  Bathroom_evening_temperature= example_data['Bathroom_evening_temperature'].astype(float).iloc[-1]
126
  temperature_ratio = example_data['temperature_ratio'].astype(float).iloc[-1]
127
+ return Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
128
 
129
 
130
  # %%
 
133
  red = sns.color_palette()[1]
134
 
135
  # %%
136
+ def predict(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio):
137
  example_data = example_df
138
  example_df_norm = normalize(example_data, mean_df, std_df, top_features)
139
  feature_values = example_df_norm[top_features].iloc[0]
 
198
  else:
199
  statement= "The temperature in the bathroom in the evening was lower than usual."
200
  statements.append(statement)
201
+ elif feature == "Kitchen_morning_temperature":
202
  if feature_direction == "positive":
203
  statement= "The temperature in the bathroom in the night was higher than usual."
204
  statements.append(statement)
 
320
  import shap
321
  import matplotlib.pyplot as plt
322
 
323
+ def interpret(example_df,Lounge_night_illuminance, Kitchen_night_illuminance, Kitchen_afternoon_illuminance, ratio, temperature_ratio, Kitchen_morning_temperature, Bathroom_evening_temperature, Kitchen_night_temperature):
324
  # Read the example data
325
  example_data = example_df
326
 
 
395
 
396
 
397
  # %%
398
+ def update_data(example_df, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio):
399
  example_data = example_df
400
  example_data['Lounge_night_illuminance'].iloc[0] = Lounge_night_illuminance
401
  example_data['Kitchen_night_illuminance'].iloc[0] = Kitchen_night_illuminance
402
  example_data['Kitchen_afternoon_illuminance'].iloc[0] = Kitchen_afternoon_illuminance
403
  example_data['ratio'].iloc[0] = ratio
404
+ example_data['Kitchen_morning_temperature'].iloc[0] = Kitchen_morning_temperature
405
  example_data['Bathroom_evening_temperature'].iloc[0] = Bathroom_evening_temperature
406
  example_data['Kitchen_night_temperature'].iloc[0] = Kitchen_night_temperature
407
  example_data['temperature_ratio'].iloc[0] = temperature_ratio
 
475
  else:
476
  statement= "The temperature in the bathroom in the evening was lower than usual."
477
  statements.append(statement)
478
+ elif feature == "Kitchen_morning_temperature":
479
  if feature_direction == "positive":
480
  statement= "The temperature in the bathroom in the night was higher than usual."
481
  statements.append(statement)
 
517
  else:
518
  statement="The indoor light exposure in the kitchen at night was lower than usual."
519
  statements.append(statement)
520
+ elif feature == "Kitchen_morning_temperature":
521
  if feature_direction == "positive":
522
  statement="The temperature in the bathroom at night was higher than usual."
523
  statements.append(statement)
 
679
  df['Kitchen_afternoon_illuminance'] = np.random.uniform(0, 5000)
680
  df['ratio'] = np.random.uniform(0, 15)
681
  df['temperature_ratio'] = np.random.uniform(-1.5, 1.5)
682
+ df['Kitchen_morning_temperature'] = np.random.uniform(0, 40) # Random value between 0 and 40
683
  df['Bathroom_evening_temperature'] = np.random.uniform(0, 40)
684
  df['Kitchen_night_temperature'] = np.random.uniform(0, 40)
685
  df['number_transitions'] = np.random.uniform(0,500)
 
692
  Lounge_night_illuminance = df['Lounge_night_illuminance'].astype(float).iloc[-1]
693
  ratio = df['ratio'].astype(float).iloc[-1]
694
  Kitchen_night_temperature= df['Kitchen_night_temperature'].astype(float).iloc[-1]
695
+ Kitchen_morning_temperature= df['Kitchen_morning_temperature'].astype(float).iloc[-1]
696
  Bathroom_evening_temperature= df['Bathroom_evening_temperature'].astype(float).iloc[-1]
697
  temperature_ratio = df['temperature_ratio'].astype(float).iloc[-1]
698
 
699
+ return df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
700
 
701
  # %%
702
  import pandas as pd
 
709
  Kitchen_afternoon_illuminance = example_data['Kitchen_afternoon_illuminance'].astype(float).iloc[-1]
710
  ratio = example_data['ratio'].astype(float).iloc[-1]
711
  temperature_ratio = example_data['temperature_ratio'].astype(float).iloc[-1]
712
+ Kitchen_morning_temperature= example_data['Kitchen_morning_temperature'].astype(float).iloc[-1]
713
  Bathroom_evening_temperature= example_data['Bathroom_evening_temperature'].astype(float).iloc[-1]
714
  Kitchen_night_temperature= example_data['Kitchen_night_temperature'].astype(float).iloc[-1]
715
  example_df_norm = normalize(example_data, mean_df, std_df, top_features)
 
783
  else:
784
  statement= "The temperature in the bathroom in the evening was lower than usual."
785
  statements.append(statement)
786
+ elif feature == "Kitchen_morning_temperature":
787
  if feature_direction == "positive":
788
+ statement= "The temperature in the kitchen in the morning was higher than usual."
789
  statements.append(statement)
790
  else:
791
+ statement= "The temperature in the kitchen in the morning was lower than usual."
792
  statements.append(statement)
793
  elif feature == "Kitchen_afternoon_illuminance":
794
  if feature_direction == "positive":
 
937
  plt.yticks(fontsize=28)
938
  plt.tight_layout()
939
 
940
+ return {"Agitated": float(proba[0][1]), "Non-agitated": float(proba[0][0])}, formatted_statements, plot,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
941
 
942
 
943
  # Plotting for negative class predictions (class label 0)
 
964
  plt.yticks(fontsize=28)
965
  plt.tight_layout()
966
 
967
+ return {"Agitated": float(proba[0][1]), "Non-agitated": float(proba[0][0])}, formatted_statements, plot, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
968
 
969
 
970
 
971
+ def save_file(example_df,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio):
972
  example_data = example_df
973
  example_data['Lounge_night_illuminance'] = Lounge_night_illuminance
974
  example_data['Kitchen_night_illuminance'] = Kitchen_night_illuminance
975
  example_data['Kitchen_afternoon_illuminance'] = Kitchen_afternoon_illuminance
976
  example_data['ratio'] = ratio
977
  example_data['temperature_ratio'] = temperature_ratio
978
+ example_data['Kitchen_morning_temperature'] = Kitchen_morning_temperature
979
  example_data['Bathroom_evening_temperature'] = Bathroom_evening_temperature
980
  example_data['Kitchen_night_temperature'] = Kitchen_night_temperature
981
  current_path = os.getcwd()
 
1003
  with gr.Row():
1004
  with gr.Column():
1005
  generate = gr.Button(value="Generate synthetic patient data")
1006
+ csv_file = gr.DataFrame(headers=['ratio', 'sunset_minutes', 'Kitchen_night_temperature', 'uvindex', 'visibility','illuminance','Kitchen_night_illuminance','Lounge_night_illuminance','Kitchen_morning_temperature','Bathroom_evening_temperature', 'Bathroom_night_activity', 'number_transitions', 'temperature_ratio', 'awake_ratio','rr_min','To_bed', 'Lounge_afternoon_activity','rr_average',"rr_min_std",'Kitchen_afternoon_illuminance'],row_count=1 , col_count=20, datatype = "number", interactive=False)
1007
  modif = gr.Button(value="Change the modifiable parameters to see how agitation risk changes")
1008
  gr.Markdown("""<p style="margin-top: 20px; font-size: 16px; font-weight: bold;"> Light exposure </p>""")
1009
  Kitchen_afternoon_illuminance = gr.Slider(label="Mean afternoon illuminance in kitchen", minimum=0, maximum=3000, step=100)
 
1011
  Lounge_night_illuminance = gr.Slider(label="Mean night illuminance in lounge", minimum=0, maximum=3000, step=100, every=True)
1012
  ratio = gr.Slider(label="Ratio (indoor:outdoor illuminance)", minimum=0, maximum=0.35, step=0.1)
1013
  gr.Markdown("""<p style="margin-top: 20px; font-size: 16px; font-weight: bold;"> Ambient temperature </p>""")
1014
+ Kitchen_morning_temperature = gr.Slider(label="Mean morning temperature in kitchen", minimum=-10, maximum=45, step=0.5)
1015
  Bathroom_evening_temperature = gr.Slider(label="Mean evening temperature in bathroom", minimum=-10, maximum=45, step=0.5)
1016
  Kitchen_night_temperature = gr.Slider(label="Mean night temperature in kitchen", minimum=-10, maximum=45, step=0.5)
1017
  temperature_ratio = gr.Slider(label="Ratio (indoor:outdoor temperature)", minimum=-500, maximum=60, step=0.1)
 
1026
  plot = gr.Plot(scale=2, label="Interpretation")
1027
 
1028
  with gr.Row():
1029
+ generate.click(generate_data, outputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio])
1030
+ Lounge_night_illuminance.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text, plot])
1031
+ Kitchen_night_illuminance.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text, plot])
1032
+ Kitchen_afternoon_illuminance.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1033
+ Kitchen_morning_temperature.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1034
+ ratio.input(update_data, inputs=[csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1035
+ temperature_ratio.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1036
+ Kitchen_morning_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1037
+ Bathroom_evening_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1038
+ Kitchen_night_temperature.input(update_data, inputs=[csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio], outputs= [label,html_text,plot])
1039
 
1040
  predict_btn.click(
1041
  predict,
1042
  inputs=[
1043
+ csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
1044
  ],
1045
  outputs=[label,html_text]
1046
  )
 
1048
  interpret_btn.click(
1049
  interpret,
1050
  inputs=[
1051
+ csv_file, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio
1052
  ],
1053
  outputs=[plot],
1054
  )
 
1058
  inputs=[
1059
  csv_file
1060
  ],
1061
+ outputs=[label,html_text, plot, Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio],
1062
  )
1063
 
1064
  flag.click(
1065
  save_file,
1066
+ inputs= [csv_file,Kitchen_afternoon_illuminance, Lounge_night_illuminance, Kitchen_night_illuminance, ratio, Kitchen_night_temperature, Kitchen_morning_temperature, Bathroom_evening_temperature, temperature_ratio],
1067
  )
1068
  with gr.Row():
1069
  gr.Markdown("<img src='https://ukdri.ac.uk/assets/img/logo.svg' alt='UKDRI' width='250' style='margin-top: 50px;'>")