silvaKenpachi commited on
Commit
33659a3
·
verified ·
1 Parent(s): e01a5da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -93,35 +93,36 @@ outputs = [gr.Dataframe(
93
  #})
94
 
95
  def infer(inputs):
 
96
  data = pd.DataFrame(inputs, columns=headers)
97
 
98
- # Store the Name column first, before any processing
99
- names = data['Name'].copy()
100
 
101
- # Replace empty strings with NaN
102
- data = data.replace('', np.nan)
 
103
 
104
  # Add missing columns with default values
105
  for col in all_headers:
106
- if col not in data.columns:
107
- data[col] = 0
108
 
109
  # Ensure the order of columns matches the training data
110
- data = data[all_headers]
111
 
112
- # Fill NaN values
113
- data = data.fillna(0)
114
 
115
- # Convert numeric columns to float, excluding 'Name'
116
- numeric_columns = [col for col in all_headers if col != 'Name']
117
- data[numeric_columns] = data[numeric_columns].astype(float)
118
 
119
  # Make predictions
120
- predictions = pipe.predict(data)
121
 
122
- # Create output DataFrame with stored names and predictions
123
  return pd.DataFrame({
124
- 'Name': names,
125
  'Depression': predictions
126
  })
127
 
 
93
  #})
94
 
95
  def infer(inputs):
96
+ # Create DataFrame from inputs
97
  data = pd.DataFrame(inputs, columns=headers)
98
 
99
+ # Create a copy of the input DataFrame to preserve original data
100
+ prediction_data = data.copy()
101
 
102
+ # Replace empty strings with NaN for numeric columns only
103
+ numeric_columns = [col for col in all_headers if col != 'Name']
104
+ prediction_data[numeric_columns] = prediction_data[numeric_columns].replace('', np.nan)
105
 
106
  # Add missing columns with default values
107
  for col in all_headers:
108
+ if col not in prediction_data.columns:
109
+ prediction_data[col] = 0
110
 
111
  # Ensure the order of columns matches the training data
112
+ prediction_data = prediction_data[all_headers]
113
 
114
+ # Fill NaN values in numeric columns only
115
+ prediction_data[numeric_columns] = prediction_data[numeric_columns].fillna(0)
116
 
117
+ # Convert numeric columns to float
118
+ prediction_data[numeric_columns] = prediction_data[numeric_columns].astype(float)
 
119
 
120
  # Make predictions
121
+ predictions = pipe.predict(prediction_data)
122
 
123
+ # Create output DataFrame using original names
124
  return pd.DataFrame({
125
+ 'Name': data['Name'],
126
  'Depression': predictions
127
  })
128