Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import getpass
|
|
5 |
import logging
|
6 |
import openai
|
7 |
import asyncio
|
|
|
8 |
from typing import Any, List, Tuple, Dict
|
9 |
import gradio as gr
|
10 |
import llama_index
|
@@ -169,7 +170,8 @@ def process_pdf(uploaded_files, llm_model, n_criteria = num_criteria):
|
|
169 |
for i, uploaded_file in enumerate(uploaded_files):
|
170 |
# Process the PDF file
|
171 |
file_name_without_extension = os.path.splitext(os.path.basename(uploaded_file))[0]
|
172 |
-
|
|
|
173 |
|
174 |
pdf_processor = PDFProcessor_Unstructured(pdf_processing_config)
|
175 |
merged_chunks, tables, title = pdf_processor.process_pdf_file(uploaded_file)
|
@@ -243,8 +245,38 @@ def process_pdf(uploaded_files, llm_model, n_criteria = num_criteria):
|
|
243 |
registration_result = nlp_methods.check_registration()
|
244 |
|
245 |
# Evaluate with OpenAI model
|
246 |
-
total_score, criteria_met, score_percentage, reasoning = pdf_criteria_query.evaluate_with_llm(registration_result, peer_journal_result, eq_journal_result, queries)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
# Convert reasoning list to plain text
|
249 |
#reasoning_text = "\n".join([f"{idx + 1}. {reason}" for idx, reason in enumerate(reasoning)])
|
250 |
|
|
|
5 |
import logging
|
6 |
import openai
|
7 |
import asyncio
|
8 |
+
import pandas as pd
|
9 |
from typing import Any, List, Tuple, Dict
|
10 |
import gradio as gr
|
11 |
import llama_index
|
|
|
170 |
for i, uploaded_file in enumerate(uploaded_files):
|
171 |
# Process the PDF file
|
172 |
file_name_without_extension = os.path.splitext(os.path.basename(uploaded_file))[0]
|
173 |
+
|
174 |
+
id_number = re.search(r"Id_(\d+)\.", file_name_without_extension)
|
175 |
|
176 |
pdf_processor = PDFProcessor_Unstructured(pdf_processing_config)
|
177 |
merged_chunks, tables, title = pdf_processor.process_pdf_file(uploaded_file)
|
|
|
245 |
registration_result = nlp_methods.check_registration()
|
246 |
|
247 |
# Evaluate with OpenAI model
|
248 |
+
total_score, criteria_met, score_percentage, score_list, reasoning = pdf_criteria_query.evaluate_with_llm(registration_result, peer_journal_result, eq_journal_result, queries)
|
249 |
+
|
250 |
+
# Define the path to your CSV file
|
251 |
+
csv_file_path = 'storing_output.csv'
|
252 |
+
|
253 |
+
|
254 |
+
# Create a dictionary for the new row
|
255 |
+
new_row = {
|
256 |
+
'Id': id_number,
|
257 |
+
'Title': title,
|
258 |
+
'Author': author_result
|
259 |
+
}
|
260 |
+
|
261 |
+
new_row.update({f'score_cr_{i}': score for i, score in enumerate(scores, 1)})
|
262 |
+
new_row.update({f'reasoning_cr_{i}': reasoning for i, reasoning in enumerate(reasonings, 1)})
|
263 |
|
264 |
+
# Check if the CSV file exists
|
265 |
+
if os.path.exists(csv_file_path):
|
266 |
+
# Load the existing data
|
267 |
+
df = pd.read_csv(csv_file_path)
|
268 |
+
else:
|
269 |
+
# Or create a new DataFrame if the file does not exist
|
270 |
+
df = pd.DataFrame(columns=['Id'] + [f'score_cr_{i}' for i in range(1, 10)] + [f'reasoning_cr_{i}' for i in range(1, 10)])
|
271 |
+
|
272 |
+
# Append the new data
|
273 |
+
df = df.append(new_row, ignore_index=True)
|
274 |
+
|
275 |
+
# Save the updated DataFrame back to CSV
|
276 |
+
df.to_csv(csv_file_path, index=False)
|
277 |
+
|
278 |
+
print(f"Updated data saved to {csv_file_path}.")
|
279 |
+
|
280 |
# Convert reasoning list to plain text
|
281 |
#reasoning_text = "\n".join([f"{idx + 1}. {reason}" for idx, reason in enumerate(reasoning)])
|
282 |
|