kpal002 commited on
Commit
684d272
·
verified ·
1 Parent(s): 5ca686d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -31
app.py CHANGED
@@ -245,40 +245,43 @@ def process_pdf(uploaded_files, llm_model, n_criteria = num_criteria):
245
 
246
  # Evaluate with OpenAI model
247
  total_score, criteria_met, score_percentage, score_list, reasoning = pdf_criteria_query.evaluate_with_llm(registration_result, peer_journal_result, eq_journal_result, queries)
248
-
249
- # Define the path to your CSV file
250
- csv_file_path = 'storing_output.csv'
251
-
252
-
253
- # Create a dictionary for the new row
254
- new_row = {
255
- 'Id': id_number,
256
- 'Title': title,
257
- 'Author': author_result
258
- }
259
- new_row.update({f'score_cr_{i}': score for i, score in enumerate(score_list, 1)})
260
- new_row.update({f'reasoning_cr_{i}': reasoning for i, reasoning in enumerate(reasoning, 1)})
261
-
262
- # Convert new_row dictionary to a DataFrame for easy appending
263
- new_row_df = pd.DataFrame([new_row])
264
- print(new_row_df)
265
 
266
- # Check if the CSV file exists
267
- if os.path.exists(csv_file_path):
268
- # Load the existing data
269
- df = pd.read_csv(csv_file_path)
270
- else:
271
- # Or create a new DataFrame if the file does not exist
272
- columns = ['Id', 'Title', 'Author'] + [f'score_cr_{i}' for i in range(1, 10)] + [f'reasoning_cr_{i}' for i in range(1, 10)]
273
- df = pd.DataFrame(columns=columns)
274
-
275
- # Append the new data using pd.concat
276
- df = pd.concat([df, new_row_df], ignore_index=True)
277
 
278
- # Save the updated DataFrame back to CSV
279
- df.to_csv(csv_file_path, index=False)
280
 
281
- print(f"Updated data saved to {csv_file_path}.")
 
 
 
282
 
283
  # Convert reasoning list to plain text
284
  #reasoning_text = "\n".join([f"{idx + 1}. {reason}" for idx, reason in enumerate(reasoning)])
 
245
 
246
  # Evaluate with OpenAI model
247
  total_score, criteria_met, score_percentage, score_list, reasoning = pdf_criteria_query.evaluate_with_llm(registration_result, peer_journal_result, eq_journal_result, queries)
248
+ try:
249
+ # Define the path to your CSV file
250
+ csv_file_path = 'storing_output.csv'
251
+
252
+
253
+ # Create a dictionary for the new row
254
+ new_row = {
255
+ 'Id': id_number,
256
+ 'Title': title,
257
+ 'Author': author_result
258
+ }
259
+ new_row.update({f'score_cr_{i}': score for i, score in enumerate(score_list, 1)})
260
+ new_row.update({f'reasoning_cr_{i}': reasoning for i, reasoning in enumerate(reasoning, 1)})
261
+
262
+ # Convert new_row dictionary to a DataFrame for easy appending
263
+ new_row_df = pd.DataFrame([new_row])
264
+ print(new_row_df)
265
 
266
+ # Check if the CSV file exists
267
+ if os.path.exists(csv_file_path):
268
+ # Load the existing data
269
+ df = pd.read_csv(csv_file_path)
270
+ else:
271
+ # Or create a new DataFrame if the file does not exist
272
+ columns = ['Id', 'Title', 'Author'] + [f'score_cr_{i}' for i in range(1, 10)] + [f'reasoning_cr_{i}' for i in range(1, 10)]
273
+ df = pd.DataFrame(columns=columns)
274
+
275
+ # Append the new data using pd.concat
276
+ df = pd.concat([df, new_row_df], ignore_index=True)
277
 
278
+ # Save the updated DataFrame back to CSV
279
+ df.to_csv(csv_file_path, index=False)
280
 
281
+ print(f"Updated data saved to {csv_file_path}.")
282
+
283
+ except Exception as e:
284
+ print(f"An error occurred: {e}")
285
 
286
  # Convert reasoning list to plain text
287
  #reasoning_text = "\n".join([f"{idx + 1}. {reason}" for idx, reason in enumerate(reasoning)])