Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,7 @@ data_open['processed_text_mopen'] = data_open[['Demo_M', 'Question']].agg(' '.jo
|
|
46 |
labels = ["Peacemaker", "Loyalist", "Achiever", "Reformer", "Individualist", "Helper", "Challenger", "Investigator", "Enthusiast"]
|
47 |
|
48 |
# Function to predict personality and log the predictions
|
49 |
-
def predict_and_log(data, prediction_column, process_text_column, custom_labels=None):
|
50 |
for index, row in data.iterrows():
|
51 |
processed_text = row[process_text_column]
|
52 |
if custom_labels:
|
@@ -55,12 +55,14 @@ def predict_and_log(data, prediction_column, process_text_column, custom_labels=
|
|
55 |
result = classifier(processed_text, labels)
|
56 |
highest_score_label = result['labels'][0]
|
57 |
data.at[index, prediction_column] = highest_score_label
|
58 |
-
|
|
|
|
|
59 |
|
60 |
# Predict and log results for each DataFrame
|
61 |
-
predict_and_log(data, 'Predicted', 'processed_text', ['MAX1', 'MAX2', 'MAX3'])
|
62 |
-
predict_and_log(data_open, 'Predicted_F', 'processed_text_open')
|
63 |
-
predict_and_log(data_open, 'Predicted_M', 'processed_text_mopen')
|
64 |
|
65 |
# Optionally display a confirmation message
|
66 |
st.write("Predictions have been logged. Check your logs for details.")
|
|
|
46 |
labels = ["Peacemaker", "Loyalist", "Achiever", "Reformer", "Individualist", "Helper", "Challenger", "Investigator", "Enthusiast"]
|
47 |
|
48 |
# Function to predict personality and log the predictions
|
49 |
+
def predict_and_log(data, prediction_column, process_text_column, true_label_column=None, custom_labels=None):
|
50 |
for index, row in data.iterrows():
|
51 |
processed_text = row[process_text_column]
|
52 |
if custom_labels:
|
|
|
55 |
result = classifier(processed_text, labels)
|
56 |
highest_score_label = result['labels'][0]
|
57 |
data.at[index, prediction_column] = highest_score_label
|
58 |
+
true_label = row[true_label_column] if true_label_column else 'Not available'
|
59 |
+
data_id = row['id']
|
60 |
+
logging.info(f"Row {data_id}: True Label - {true_label}, Predicted - {highest_score_label}")
|
61 |
|
62 |
# Predict and log results for each DataFrame
|
63 |
+
predict_and_log(data, 'Predicted', 'processed_text', true_label_column='True_label', custom_labels=['MAX1', 'MAX2', 'MAX3'])
|
64 |
+
predict_and_log(data_open, 'Predicted_F', 'processed_text_open', true_label_column='True_label')
|
65 |
+
predict_and_log(data_open, 'Predicted_M', 'processed_text_mopen', true_label_column='True_label')
|
66 |
|
67 |
# Optionally display a confirmation message
|
68 |
st.write("Predictions have been logged. Check your logs for details.")
|