Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 99 |
-
|
| 100 |
|
| 101 |
-
# Replace empty strings with NaN
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
# Add missing columns with default values
|
| 105 |
for col in all_headers:
|
| 106 |
-
if col not in
|
| 107 |
-
|
| 108 |
|
| 109 |
# Ensure the order of columns matches the training data
|
| 110 |
-
|
| 111 |
|
| 112 |
-
# Fill NaN values
|
| 113 |
-
|
| 114 |
|
| 115 |
-
# Convert numeric columns to float
|
| 116 |
-
numeric_columns = [
|
| 117 |
-
data[numeric_columns] = data[numeric_columns].astype(float)
|
| 118 |
|
| 119 |
# Make predictions
|
| 120 |
-
predictions = pipe.predict(
|
| 121 |
|
| 122 |
-
# Create output DataFrame
|
| 123 |
return pd.DataFrame({
|
| 124 |
-
'Name':
|
| 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 |
|