Moditha24 commited on
Commit
b662922
·
verified ·
1 Parent(s): ca4bef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -9,34 +9,21 @@ import pickle
9
  with open('label_encoder.pkl', 'rb') as f:
10
  label_encoder = pickle.load(f)
11
 
12
- # Load the ColumnTransformer (ensure that you have this preprocessing object)
13
- with open('column_transformer.pkl', 'rb') as f:
14
- ct = pickle.load(f)
15
-
16
- # Define the dropdown options based on data (assuming 'df' is your DataFrame)
17
- # You need to load 'df' or replace it with a dataset source.
18
- # Example:
19
- # df = pd.read_csv('your_data.csv') # Adjust this line as necessary
20
-
21
- # Define dropdown values dynamically from your dataset
22
- # Example for 'Race' and 'Cyp2C9 genotypes'
23
- race_options = list(dict(df['Race (Reported)'].value_counts()).keys())
24
- age_options = list(dict(df['Age'].value_counts()).keys())
25
- cyp2c9_genotypes_options = list(dict(df['Cyp2C9 genotypes'].value_counts()).keys())
26
- vkorc1_genotypes_options = list(dict(df['VKORC1 genotype: -1639 G>A (3673); chr16:31015190; rs9923231; C/T'].value_counts()).keys())
27
 
28
  # UI Components for user input
29
  input_Gender = gr.Radio(["male", "female"], label="Gender")
30
- input_Race = gr.Dropdown(race_options, label="Race")
31
- input_Age = gr.Dropdown(age_options, label='Age')
32
  input_Height = gr.Number(label='Height (cm)')
33
  input_Weight = gr.Number(label='Weight (kg)')
34
  input_Diabetes = gr.Radio([0.0, 1.0], label='Diabetes')
35
  input_Simvastatin = gr.Radio([0.0, 1.0], label='Simvastatin (Zocor)')
36
  input_Amiodarone = gr.Radio([0.0, 1.0], label='Amiodarone (Cordarone)')
37
  input_INR_reported = gr.Number(label='INR on Reported Therapeutic Dose of Warfarin')
38
- input_Cyp2C9_genotypes = gr.Dropdown(cyp2c9_genotypes_options, label='Cyp2C9 genotypes')
39
- input_VKORC1_genotypes = gr.Dropdown(vkorc1_genotypes_options, label='VKORC1 genotypes')
40
  input_model = gr.Dropdown(['Decision Tree Regression', 'Support Vector Regression', 'Random Forest Regression', 'Deep Learning'], label='Model Selection')
41
 
42
  # Output textbox to display predicted dose
@@ -44,6 +31,17 @@ output_warfarin_dosage = gr.Textbox(label='Therapeutic Dose of Warfarin')
44
 
45
  # Prediction function with renamed input variables
46
  def predict_dosage(gender, race, age, height, weight, diabetes, simvastatin, amiodarone, inr, cyp2c9, vkorc1, selected_model):
 
 
 
 
 
 
 
 
 
 
 
47
  try:
48
  # Load the selected model
49
  if selected_model == 'Deep Learning':
@@ -92,6 +90,7 @@ def predict_dosage(gender, race, age, height, weight, diabetes, simvastatin, ami
92
 
93
  # Convert to NumPy array for model input
94
  input_array = np.array(transformed_input, dtype=np.float32)
 
95
 
96
  # Predict using appropriate model type
97
  if selected_model == 'Deep Learning':
 
9
  with open('label_encoder.pkl', 'rb') as f:
10
  label_encoder = pickle.load(f)
11
 
12
+ # Assuming 'ct' is your ColumnTransformer (replace this with the actual loading code for your preprocessor)
13
+ # Make sure that 'ct' is properly loaded, or use the same transformation logic here.
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # UI Components for user input
16
  input_Gender = gr.Radio(["male", "female"], label="Gender")
17
+ input_Race = gr.Dropdown(list(dict(df['Race (Reported)'].value_counts()).keys()), label="Race")
18
+ input_Age = gr.Dropdown(list(dict(df['Age'].value_counts())), label='Age')
19
  input_Height = gr.Number(label='Height (cm)')
20
  input_Weight = gr.Number(label='Weight (kg)')
21
  input_Diabetes = gr.Radio([0.0, 1.0], label='Diabetes')
22
  input_Simvastatin = gr.Radio([0.0, 1.0], label='Simvastatin (Zocor)')
23
  input_Amiodarone = gr.Radio([0.0, 1.0], label='Amiodarone (Cordarone)')
24
  input_INR_reported = gr.Number(label='INR on Reported Therapeutic Dose of Warfarin')
25
+ input_Cyp2C9_genotypes = gr.Dropdown(list(dict(df['Cyp2C9 genotypes'].value_counts())), label='Cyp2C9 genotypes')
26
+ input_VKORC1_genotypes = gr.Radio(list(dict(df['VKORC1 genotype: -1639 G>A (3673); chr16:31015190; rs9923231; C/T'].value_counts())), label='VKORC1 genotypes')
27
  input_model = gr.Dropdown(['Decision Tree Regression', 'Support Vector Regression', 'Random Forest Regression', 'Deep Learning'], label='Model Selection')
28
 
29
  # Output textbox to display predicted dose
 
31
 
32
  # Prediction function with renamed input variables
33
  def predict_dosage(gender, race, age, height, weight, diabetes, simvastatin, amiodarone, inr, cyp2c9, vkorc1, selected_model):
34
+ import numpy as np
35
+ from joblib import load
36
+ from tensorflow.keras.models import load_model
37
+ import tensorflow as tf
38
+
39
+ # Optional debug function to inspect data before prediction
40
+ def print_input_debug(transformed_input, final_array):
41
+ print("Transformed input shape:", transformed_input.shape)
42
+ print("Final input shape:", final_array.shape)
43
+ print("Input data type:", final_array.dtype)
44
+
45
  try:
46
  # Load the selected model
47
  if selected_model == 'Deep Learning':
 
90
 
91
  # Convert to NumPy array for model input
92
  input_array = np.array(transformed_input, dtype=np.float32)
93
+ print_input_debug(transformed_input, input_array)
94
 
95
  # Predict using appropriate model type
96
  if selected_model == 'Deep Learning':