Update app.py
Browse files
app.py
CHANGED
@@ -25,105 +25,35 @@ def extract_text_from_pdf(pdf_path):
|
|
25 |
return f"Error extracting text from PDF: {str(e)}"
|
26 |
|
27 |
# Function to generate PRISMA flow chart HTML
|
28 |
-
def generate_prisma_flow_chart():
|
29 |
-
# Placeholder values for the PRISMA flow chart (as per the provided image)
|
30 |
-
records_db = 0 # Records from databases
|
31 |
-
records_other = 0 # Records from other sources
|
32 |
-
duplicates_removed = 0 # After duplicates removed
|
33 |
-
records_screened = 0 # Records screened
|
34 |
-
records_excluded_screening = 0 # Records excluded during screening
|
35 |
-
reports_sought = 0 # Reports sought for retrieval
|
36 |
-
reports_not_retrieved = 0 # Reports not retrieved
|
37 |
-
reports_assessed = 0 # Reports assessed for eligibility
|
38 |
-
reports_excluded_eligibility = 0 # Reports excluded during eligibility
|
39 |
-
studies_included = 0 # Studies included in review
|
40 |
-
|
41 |
-
# HTML and CSS for PRISMA flow chart
|
42 |
prisma_html = f"""
|
43 |
-
<div
|
44 |
-
<
|
45 |
-
<div style="
|
46 |
-
|
47 |
-
|
48 |
-
<div
|
49 |
-
|
50 |
-
Records identified from:<br>
|
51 |
-
Databases (n = {records_db})<br>
|
52 |
-
Registers (n = 0)
|
53 |
-
</div>
|
54 |
-
<div style="text-align: center; margin: 10px 0;">β</div>
|
55 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
56 |
-
Records removed before screening:<br>
|
57 |
-
Duplicate records (n = 0)<br>
|
58 |
-
Records marked as ineligible by automation tools (n = 0)<br>
|
59 |
-
Records removed for other reasons (n = 0)
|
60 |
-
</div>
|
61 |
-
<div style="text-align: center; margin: 10px 0;">β</div>
|
62 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
63 |
-
Records screened (n = {records_screened})
|
64 |
-
</div>
|
65 |
-
<div style="display: flex; justify-content: space-between; align-items: center;">
|
66 |
-
<div style="width: 50%; text-align: center; margin: 10px 0;">β</div>
|
67 |
-
<div style="width: 50%; background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
68 |
-
Records excluded (n = {records_excluded_screening})
|
69 |
-
</div>
|
70 |
-
</div>
|
71 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
72 |
-
Reports sought for retrieval (n = {reports_sought})
|
73 |
-
</div>
|
74 |
-
<div style="display: flex; justify-content: space-between; align-items: center;">
|
75 |
-
<div style="width: 50%; text-align: center; margin: 10px 0;">β</div>
|
76 |
-
<div style="width: 50%; background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
77 |
-
Reports not retrieved (n = {reports_not_retrieved})
|
78 |
-
</div>
|
79 |
-
</div>
|
80 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
81 |
-
Reports assessed for eligibility (n = {reports_assessed})
|
82 |
-
</div>
|
83 |
-
<div style="display: flex; justify-content: space-between; align-items: center;">
|
84 |
-
<div style="width: 50%; text-align: center; margin: 10px 0;">β</div>
|
85 |
-
<div style="width: 50%; background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
86 |
-
Reports excluded:<br>
|
87 |
-
Reason 1 (n = NA)<br>
|
88 |
-
Reason 2 (n = NA)
|
89 |
-
</div>
|
90 |
-
</div>
|
91 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
92 |
-
New studies included in review (n = {studies_included})<br>
|
93 |
-
Reports of new studies (n = 0)
|
94 |
-
</div>
|
95 |
</div>
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
<div
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
</div>
|
106 |
-
<div
|
107 |
-
|
108 |
-
|
109 |
-
</
|
110 |
-
<div
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
</div>
|
116 |
-
<div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
117 |
-
Reports assessed for eligibility (n = {reports_assessed})
|
118 |
-
</div>
|
119 |
-
<div style="display: flex; justify-content: space-between; align-items: center;">
|
120 |
-
<div style="width: 50%; text-align: center; margin: 10px 0;">β</div>
|
121 |
-
<div style="width: 50%; background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
|
122 |
-
Reports excluded:<br>
|
123 |
-
Reason 1 (n = NA)<br>
|
124 |
-
Reason 2 (n = NA)
|
125 |
-
</div>
|
126 |
-
</div>
|
127 |
</div>
|
128 |
</div>
|
129 |
</div>
|
@@ -145,7 +75,7 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
145 |
openai.api_key = api_key
|
146 |
|
147 |
# Create the system message with systematic review guidelines
|
148 |
-
system_prompt = """You are an expert academic assistant. Create a systematic review using academic research paper formatting. The Systematic Review must be in great
|
149 |
|
150 |
Step 1: Identify a Research Field
|
151 |
The first step in writing a systematic review paper is to identify a research field. This involves selecting a specific area of study that you are interested in and want to explore further.
|
@@ -202,6 +132,18 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
202 |
pdf_texts.append(pdf_text)
|
203 |
pdf_names.append(pdf_name)
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
# Prepare the user prompt with the review question and instructions
|
206 |
table_instruction = ""
|
207 |
if include_tables:
|
@@ -227,16 +169,7 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
227 |
# Get the AI response
|
228 |
review_content = response["choices"][0]["message"]["content"]
|
229 |
|
230 |
-
#
|
231 |
-
prisma_flow_chart = generate_prisma_flow_chart()
|
232 |
-
|
233 |
-
# Insert PRISMA flow chart into the review content (after the methodology section, assuming section 3 is methodology)
|
234 |
-
review_content = review_content.replace(
|
235 |
-
'<h2>4. Results</h2>',
|
236 |
-
'<h2>4. Results</h2>\n' + prisma_flow_chart
|
237 |
-
)
|
238 |
-
|
239 |
-
# Apply professional academic paper styling
|
240 |
styled_html = f"""
|
241 |
<!DOCTYPE html>
|
242 |
<html lang="en">
|
@@ -373,6 +306,8 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
373 |
<body>
|
374 |
<div class="paper-container">
|
375 |
{review_content}
|
|
|
|
|
376 |
</div>
|
377 |
</body>
|
378 |
</html>
|
@@ -564,7 +499,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
564 |
- Upload papers that are related to the same research topic or field
|
565 |
- Be specific in your review question to get more focused results
|
566 |
- The generated review will follow a systematic structure including research field identification, data extraction, analysis, and conclusions
|
567 |
-
- A PRISMA flow chart will be included in the review to visualize the study selection process
|
568 |
- The more papers you upload, the more comprehensive the review will be
|
569 |
- The review will be formatted as a professional academic paper with proper sections and citations
|
570 |
""")
|
|
|
25 |
return f"Error extracting text from PDF: {str(e)}"
|
26 |
|
27 |
# Function to generate PRISMA flow chart HTML
|
28 |
+
def generate_prisma_flow_chart(total_records_db, additional_records, duplicates_removed, screened_records, excluded_title_abstract, full_text_assessed, excluded_full_text, included_studies):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
prisma_html = f"""
|
30 |
+
<div style="text-align: center; margin: 20px auto; max-width: 800px;">
|
31 |
+
<h2>PRISMA Flow Diagram</h2>
|
32 |
+
<div style="border: 1px solid #000; padding: 10px; background-color: #f9f9f9;">
|
33 |
+
<div style="margin: 10px 0;">
|
34 |
+
<strong>Identification of studies via databases and registers</strong>
|
35 |
+
<div>Records identified from: Databases (n = {total_records_db})</div>
|
36 |
+
<div>Records removed before screening: Duplicates marked as ineligible by automation tools (n = {duplicates_removed})</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
</div>
|
38 |
+
<div style="margin: 10px 0;">
|
39 |
+
<strong>Screening</strong>
|
40 |
+
<div>Records screened (n = {screened_records})</div>
|
41 |
+
<div>Records excluded (n = {excluded_title_abstract})</div>
|
42 |
+
</div>
|
43 |
+
<div style="margin: 10px 0;">
|
44 |
+
<strong>Eligibility</strong>
|
45 |
+
<div>Reports sought for retrieval (n = {full_text_assessed})</div>
|
46 |
+
<div>Reports not retrieved (n = 0)</div>
|
47 |
+
<div>Reports assessed for eligibility (n = {full_text_assessed})</div>
|
48 |
+
<div>Reports excluded (n = {excluded_full_text})</div>
|
49 |
+
</div>
|
50 |
+
<div style="margin: 10px 0;">
|
51 |
+
<strong>Included</strong>
|
52 |
+
<div>New studies included in review (n = {included_studies})</div>
|
53 |
+
</div>
|
54 |
+
<div style="margin: 10px 0;">
|
55 |
+
<strong>Identification of studies via other methods</strong>
|
56 |
+
<div>Records identified from: Websites (n = 0), Organizations (n = 0), Citation searching (n = {additional_records})</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
</div>
|
58 |
</div>
|
59 |
</div>
|
|
|
75 |
openai.api_key = api_key
|
76 |
|
77 |
# Create the system message with systematic review guidelines
|
78 |
+
system_prompt = """You are an expert academic assistant. Create a systematic review using academic research paper formatting. The Systematic Review must be in great details. Structure it using these steps:
|
79 |
|
80 |
Step 1: Identify a Research Field
|
81 |
The first step in writing a systematic review paper is to identify a research field. This involves selecting a specific area of study that you are interested in and want to explore further.
|
|
|
132 |
pdf_texts.append(pdf_text)
|
133 |
pdf_names.append(pdf_name)
|
134 |
|
135 |
+
# Prepare PRISMA flow chart data (example values, adjust based on actual process)
|
136 |
+
total_records_db = len(pdf_files)
|
137 |
+
additional_records = 0
|
138 |
+
duplicates_removed = 0
|
139 |
+
screened_records = total_records_db
|
140 |
+
excluded_title_abstract = 0
|
141 |
+
full_text_assessed = total_records_db
|
142 |
+
excluded_full_text = 0
|
143 |
+
included_studies = total_records_db
|
144 |
+
|
145 |
+
prisma_chart = generate_prisma_flow_chart(total_records_db, additional_records, duplicates_removed, screened_records, excluded_title_abstract, full_text_assessed, excluded_full_text, included_studies)
|
146 |
+
|
147 |
# Prepare the user prompt with the review question and instructions
|
148 |
table_instruction = ""
|
149 |
if include_tables:
|
|
|
169 |
# Get the AI response
|
170 |
review_content = response["choices"][0]["message"]["content"]
|
171 |
|
172 |
+
# Apply professional academic paper styling with PRISMA chart in the middle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
styled_html = f"""
|
174 |
<!DOCTYPE html>
|
175 |
<html lang="en">
|
|
|
306 |
<body>
|
307 |
<div class="paper-container">
|
308 |
{review_content}
|
309 |
+
<!-- Insert PRISMA Flow Chart in the middle -->
|
310 |
+
{prisma_chart}
|
311 |
</div>
|
312 |
</body>
|
313 |
</html>
|
|
|
499 |
- Upload papers that are related to the same research topic or field
|
500 |
- Be specific in your review question to get more focused results
|
501 |
- The generated review will follow a systematic structure including research field identification, data extraction, analysis, and conclusions
|
|
|
502 |
- The more papers you upload, the more comprehensive the review will be
|
503 |
- The review will be formatted as a professional academic paper with proper sections and citations
|
504 |
""")
|