Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import joblib
|
|
| 3 |
import pandas as pd
|
| 4 |
import datasets
|
| 5 |
import json
|
|
|
|
| 6 |
|
| 7 |
# Load the model
|
| 8 |
pipe = joblib.load("./model.pkl")
|
|
@@ -32,18 +33,44 @@ outputs = [gr.Dataframe(row_count=(2, "dynamic"), col_count=(1, "fixed"), label=
|
|
| 32 |
#predictions = pipe.predict(data)
|
| 33 |
#return pd.DataFrame(predictions, columns=["Depression"])
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def infer(inputs):
|
| 36 |
data = pd.DataFrame(inputs, columns=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Add missing columns with default values (e.g., 0)
|
| 38 |
for col in all_headers:
|
| 39 |
if col not in data.columns:
|
| 40 |
data[col] = 0
|
|
|
|
| 41 |
# Ensure the order of columns matches the training data
|
| 42 |
data = data[all_headers]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
predictions = pipe.predict(data)
|
| 44 |
return pd.DataFrame(predictions, columns=["Depression"])
|
| 45 |
|
| 46 |
|
|
|
|
| 47 |
gr.Interface(
|
| 48 |
fn=infer,
|
| 49 |
inputs=inputs,
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import datasets
|
| 5 |
import json
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
# Load the model
|
| 9 |
pipe = joblib.load("./model.pkl")
|
|
|
|
| 33 |
#predictions = pipe.predict(data)
|
| 34 |
#return pd.DataFrame(predictions, columns=["Depression"])
|
| 35 |
|
| 36 |
+
#code to fix missing columns with na
|
| 37 |
+
#def infer(inputs):
|
| 38 |
+
#data = pd.DataFrame(inputs, columns=headers)
|
| 39 |
+
# Add missing columns with default values (e.g., 0)
|
| 40 |
+
#for col in all_headers:
|
| 41 |
+
#if col not in data.columns:
|
| 42 |
+
#data[col] = 0
|
| 43 |
+
# Ensure the order of columns matches the training data
|
| 44 |
+
#data = data[all_headers]
|
| 45 |
+
#predictions = pipe.predict(data)
|
| 46 |
+
#return pd.DataFrame(predictions, columns=["Depression"])
|
| 47 |
+
|
| 48 |
+
|
| 49 |
def infer(inputs):
|
| 50 |
data = pd.DataFrame(inputs, columns=headers)
|
| 51 |
+
|
| 52 |
+
# Replace empty strings with NaN
|
| 53 |
+
data = data.replace('', np.nan)
|
| 54 |
+
|
| 55 |
# Add missing columns with default values (e.g., 0)
|
| 56 |
for col in all_headers:
|
| 57 |
if col not in data.columns:
|
| 58 |
data[col] = 0
|
| 59 |
+
|
| 60 |
# Ensure the order of columns matches the training data
|
| 61 |
data = data[all_headers]
|
| 62 |
+
|
| 63 |
+
# Fill NaN values with default values (e.g., 0)
|
| 64 |
+
data = data.fillna(0)
|
| 65 |
+
|
| 66 |
+
# Convert all data to float
|
| 67 |
+
data = data.astype(float)
|
| 68 |
+
|
| 69 |
predictions = pipe.predict(data)
|
| 70 |
return pd.DataFrame(predictions, columns=["Depression"])
|
| 71 |
|
| 72 |
|
| 73 |
+
|
| 74 |
gr.Interface(
|
| 75 |
fn=infer,
|
| 76 |
inputs=inputs,
|