Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -88,7 +88,7 @@ Our extensive experiments show that ME²-BERT outperforms existing state-of-the-
|
|
88 |
Use this web app app to predict moral foundations (CARE/HARM, FAIRNESS/CHEATING, AUTHORITY/SUBVERSION, LOYALTY/BETRAYAL, PURITY/DEGRADATION)
|
89 |
by entering a text or by uploading a csv file with at least a 'text' column.
|
90 |
|
91 |
-
|
92 |
"""
|
93 |
)
|
94 |
|
@@ -117,15 +117,13 @@ if st.session_state["prediction_result"]:
|
|
117 |
st.write("**Predicted moral foundations:**")
|
118 |
st.json(st.session_state["prediction_result"])
|
119 |
|
120 |
-
|
121 |
-
# ---------------------------------------------------------------
|
122 |
st.markdown("## CSV File Upload")
|
123 |
st.write("You can upload a space-separated CSV file with a 'text' column. The file must have at most 50 rows.")
|
124 |
|
125 |
uploaded_file = st.file_uploader("Upload CSV (space-separated)", type=["csv"])
|
126 |
if uploaded_file is not None:
|
127 |
df = pd.read_csv(uploaded_file, sep=' ')
|
128 |
-
# Controllo numero di righe
|
129 |
if len(df) > 50:
|
130 |
st.error("The CSV file must have at most 50 rows.")
|
131 |
else:
|
@@ -136,22 +134,21 @@ if uploaded_file is not None:
|
|
136 |
text_list = df['text'].tolist()
|
137 |
predictions = predict_moralities(text_list)
|
138 |
|
139 |
-
|
140 |
st.write("### Predictions for each row:")
|
141 |
for i, row_text in enumerate(text_list):
|
142 |
st.write(f"Row {i+1}: {row_text}")
|
143 |
st.json(predictions[i])
|
144 |
|
145 |
-
# Creiamo un DataFrame con text e predizioni per permettere download e copia
|
146 |
results_for_download = []
|
147 |
for txt, preds in zip(text_list, predictions):
|
148 |
row_data = {"text": txt}
|
149 |
-
row_data.update(preds)
|
150 |
results_for_download.append(row_data)
|
151 |
|
152 |
df_results = pd.DataFrame(results_for_download)
|
153 |
|
154 |
-
|
155 |
csv_buffer = io.StringIO()
|
156 |
df_results.to_csv(csv_buffer, index=False)
|
157 |
csv_data = csv_buffer.getvalue()
|
|
|
88 |
Use this web app app to predict moral foundations (CARE/HARM, FAIRNESS/CHEATING, AUTHORITY/SUBVERSION, LOYALTY/BETRAYAL, PURITY/DEGRADATION)
|
89 |
by entering a text or by uploading a csv file with at least a 'text' column.
|
90 |
|
91 |
+
[Paper](https://aclanthology.org/2025.coling-main.638.pdf) | [Source code](https://github.com/lorenzozangari/ME2-BERT)
|
92 |
"""
|
93 |
)
|
94 |
|
|
|
117 |
st.write("**Predicted moral foundations:**")
|
118 |
st.json(st.session_state["prediction_result"])
|
119 |
|
120 |
+
|
|
|
121 |
st.markdown("## CSV File Upload")
|
122 |
st.write("You can upload a space-separated CSV file with a 'text' column. The file must have at most 50 rows.")
|
123 |
|
124 |
uploaded_file = st.file_uploader("Upload CSV (space-separated)", type=["csv"])
|
125 |
if uploaded_file is not None:
|
126 |
df = pd.read_csv(uploaded_file, sep=' ')
|
|
|
127 |
if len(df) > 50:
|
128 |
st.error("The CSV file must have at most 50 rows.")
|
129 |
else:
|
|
|
134 |
text_list = df['text'].tolist()
|
135 |
predictions = predict_moralities(text_list)
|
136 |
|
137 |
+
|
138 |
st.write("### Predictions for each row:")
|
139 |
for i, row_text in enumerate(text_list):
|
140 |
st.write(f"Row {i+1}: {row_text}")
|
141 |
st.json(predictions[i])
|
142 |
|
|
|
143 |
results_for_download = []
|
144 |
for txt, preds in zip(text_list, predictions):
|
145 |
row_data = {"text": txt}
|
146 |
+
row_data.update(preds)
|
147 |
results_for_download.append(row_data)
|
148 |
|
149 |
df_results = pd.DataFrame(results_for_download)
|
150 |
|
151 |
+
|
152 |
csv_buffer = io.StringIO()
|
153 |
df_results.to_csv(csv_buffer, index=False)
|
154 |
csv_data = csv_buffer.getvalue()
|