Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,13 +65,40 @@ outputs = [gr.Dataframe(
|
|
| 65 |
#return pd.DataFrame(predictions, columns=["Depression"])
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def infer(inputs):
|
| 69 |
data = pd.DataFrame(inputs, columns=headers)
|
| 70 |
|
| 71 |
# Replace empty strings with NaN
|
| 72 |
data = data.replace('', np.nan)
|
| 73 |
|
| 74 |
-
# Add missing columns with default values
|
| 75 |
for col in all_headers:
|
| 76 |
if col not in data.columns:
|
| 77 |
data[col] = 0
|
|
@@ -79,21 +106,26 @@ def infer(inputs):
|
|
| 79 |
# Ensure the order of columns matches the training data
|
| 80 |
data = data[all_headers]
|
| 81 |
|
| 82 |
-
# Fill NaN values
|
| 83 |
data = data.fillna(0)
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
| 88 |
predictions = pipe.predict(data)
|
| 89 |
-
|
|
|
|
| 90 |
return pd.DataFrame({
|
| 91 |
-
'Name':
|
| 92 |
'Depression': predictions
|
| 93 |
})
|
| 94 |
|
| 95 |
|
| 96 |
-
|
| 97 |
gr.Interface(
|
| 98 |
fn=infer,
|
| 99 |
inputs=inputs,
|
|
|
|
| 65 |
#return pd.DataFrame(predictions, columns=["Depression"])
|
| 66 |
|
| 67 |
|
| 68 |
+
#def infer(inputs):
|
| 69 |
+
#data = pd.DataFrame(inputs, columns=headers)
|
| 70 |
+
|
| 71 |
+
# Replace empty strings with NaN
|
| 72 |
+
#data = data.replace('', np.nan)
|
| 73 |
+
|
| 74 |
+
# Add missing columns with default values (e.g., 0)
|
| 75 |
+
#for col in all_headers:
|
| 76 |
+
#if col not in data.columns:
|
| 77 |
+
#data[col] = 0
|
| 78 |
+
|
| 79 |
+
# Ensure the order of columns matches the training data
|
| 80 |
+
#data = data[all_headers]
|
| 81 |
+
|
| 82 |
+
# Fill NaN values with default values (e.g., 0)
|
| 83 |
+
#data = data.fillna(0)
|
| 84 |
+
|
| 85 |
+
# Convert all data to float
|
| 86 |
+
#data = data.astype(float)
|
| 87 |
+
|
| 88 |
+
#predictions = pipe.predict(data)
|
| 89 |
+
#return pd.DataFrame(predictions, columns=["Name", "Depression"])
|
| 90 |
+
#return pd.DataFrame({
|
| 91 |
+
#'Name': data['Name'],
|
| 92 |
+
#'Depression': predictions
|
| 93 |
+
#})
|
| 94 |
+
|
| 95 |
def infer(inputs):
|
| 96 |
data = pd.DataFrame(inputs, columns=headers)
|
| 97 |
|
| 98 |
# Replace empty strings with NaN
|
| 99 |
data = data.replace('', np.nan)
|
| 100 |
|
| 101 |
+
# Add missing columns with default values
|
| 102 |
for col in all_headers:
|
| 103 |
if col not in data.columns:
|
| 104 |
data[col] = 0
|
|
|
|
| 106 |
# Ensure the order of columns matches the training data
|
| 107 |
data = data[all_headers]
|
| 108 |
|
| 109 |
+
# Fill NaN values
|
| 110 |
data = data.fillna(0)
|
| 111 |
|
| 112 |
+
# Store the Name column before conversion
|
| 113 |
+
names = data['Name'].copy()
|
| 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 original names and predictions
|
| 123 |
return pd.DataFrame({
|
| 124 |
+
'Name': names,
|
| 125 |
'Depression': predictions
|
| 126 |
})
|
| 127 |
|
| 128 |
|
|
|
|
| 129 |
gr.Interface(
|
| 130 |
fn=infer,
|
| 131 |
inputs=inputs,
|