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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -9,18 +9,34 @@ import pickle
9
  with open('label_encoder.pkl', 'rb') as f:
10
  label_encoder = pickle.load(f)
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # UI Components for user input
13
  input_Gender = gr.Radio(["male", "female"], label="Gender")
14
- input_Race = gr.Dropdown([], label="Race") # Use empty list as placeholder
15
- input_Age = gr.Dropdown([], label='Age') # Use empty list as placeholder
16
  input_Height = gr.Number(label='Height (cm)')
17
  input_Weight = gr.Number(label='Weight (kg)')
18
  input_Diabetes = gr.Radio([0.0, 1.0], label='Diabetes')
19
  input_Simvastatin = gr.Radio([0.0, 1.0], label='Simvastatin (Zocor)')
20
  input_Amiodarone = gr.Radio([0.0, 1.0], label='Amiodarone (Cordarone)')
21
  input_INR_reported = gr.Number(label='INR on Reported Therapeutic Dose of Warfarin')
22
- input_Cyp2C9_genotypes = gr.Dropdown([], label='Cyp2C9 genotypes') # Use empty list as placeholder
23
- input_VKORC1_genotypes = gr.Radio([], label='VKORC1 genotypes') # Use empty list as placeholder
24
  input_model = gr.Dropdown(['Decision Tree Regression', 'Support Vector Regression', 'Random Forest Regression', 'Deep Learning'], label='Model Selection')
25
 
26
  # Output textbox to display predicted dose
@@ -28,17 +44,6 @@ output_warfarin_dosage = gr.Textbox(label='Therapeutic Dose of Warfarin')
28
 
29
  # Prediction function with renamed input variables
30
  def predict_dosage(gender, race, age, height, weight, diabetes, simvastatin, amiodarone, inr, cyp2c9, vkorc1, selected_model):
31
- import numpy as np
32
- from joblib import load
33
- from tensorflow.keras.models import load_model
34
- import tensorflow as tf
35
-
36
- # Optional debug function to inspect data before prediction
37
- def print_input_debug(transformed_input, final_array):
38
- print("Transformed input shape:", transformed_input.shape)
39
- print("Final input shape:", final_array.shape)
40
- print("Input data type:", final_array.dtype)
41
-
42
  try:
43
  # Load the selected model
44
  if selected_model == 'Deep Learning':
@@ -87,7 +92,6 @@ def predict_dosage(gender, race, age, height, weight, diabetes, simvastatin, ami
87
 
88
  # Convert to NumPy array for model input
89
  input_array = np.array(transformed_input, dtype=np.float32)
90
- print_input_debug(transformed_input, input_array)
91
 
92
  # Predict using appropriate model type
93
  if selected_model == 'Deep Learning':
 
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
 
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
 
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':