lorenzozan commited on
Commit
036c981
·
verified ·
1 Parent(s): a882d8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
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
- The link to the original paper is [here](https://aclanthology.org/2025.coling-main.638.pdf). The source code is available [here](https://github.com/lorenzozangari/ME2-BERT).
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
- # SEZIONE AGGIUNTA PER IL FILE CSV (MODIFICHE RICHIESTE)
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
- # Stampa row-by-row come da codice precedente
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) # Aggiunge CARE/HARM, FAIRNESS/CHEATING, ecc.
150
  results_for_download.append(row_data)
151
 
152
  df_results = pd.DataFrame(results_for_download)
153
 
154
- # Convertiamo in CSV in memoria
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()