Update app.py
Browse files
app.py
CHANGED
@@ -24,114 +24,6 @@ def extract_text_from_pdf(pdf_path):
|
|
24 |
except Exception as e:
|
25 |
return f"Error extracting text from PDF: {str(e)}"
|
26 |
|
27 |
-
# Function to generate PRISMA flowchart HTML
|
28 |
-
def generate_prisma_chart(num_studies):
|
29 |
-
return f"""
|
30 |
-
<div class="prisma-section" style="margin: 40px 0; text-align: center;">
|
31 |
-
<h2>PRISMA Flow Diagram</h2>
|
32 |
-
<div class="prisma-flowchart" style="
|
33 |
-
display: inline-block;
|
34 |
-
position: relative;
|
35 |
-
padding: 30px 0;
|
36 |
-
text-align: left;
|
37 |
-
font-size: 14px;
|
38 |
-
">
|
39 |
-
<!-- Identification -->
|
40 |
-
<div style="display: flex; align-items: center; margin-bottom: 30px;">
|
41 |
-
<div style="
|
42 |
-
border: 2px solid #4a00e0;
|
43 |
-
padding: 15px 25px;
|
44 |
-
border-radius: 8px;
|
45 |
-
background: #f8f5ff;
|
46 |
-
width: 220px;
|
47 |
-
text-align: center;
|
48 |
-
">
|
49 |
-
<strong>Identification</strong><br>
|
50 |
-
Databases (n = 0)<br>
|
51 |
-
Registers (n = 0)<br>
|
52 |
-
Other sources (n = {num_studies})
|
53 |
-
</div>
|
54 |
-
<div style="margin-left: 20px;">→</div>
|
55 |
-
</div>
|
56 |
-
|
57 |
-
<!-- Screening -->
|
58 |
-
<div style="display: flex; align-items: center; margin-bottom: 30px; margin-left: 50px;">
|
59 |
-
<div style="
|
60 |
-
border: 2px solid #4a00e0;
|
61 |
-
padding: 15px 25px;
|
62 |
-
border-radius: 8px;
|
63 |
-
background: #f8f5ff;
|
64 |
-
width: 220px;
|
65 |
-
text-align: center;
|
66 |
-
">
|
67 |
-
<strong>Screening</strong><br>
|
68 |
-
Records screened (n = {num_studies})<br>
|
69 |
-
Excluded (n = 0)
|
70 |
-
</div>
|
71 |
-
<div style="margin-left: 20px;">→</div>
|
72 |
-
</div>
|
73 |
-
|
74 |
-
<!-- Eligibility -->
|
75 |
-
<div style="display: flex; align-items: center; margin-bottom: 30px; margin-left: 100px;">
|
76 |
-
<div style="
|
77 |
-
border: 2px solid #4a00e0;
|
78 |
-
padding: 15px 25px;
|
79 |
-
border-radius: 8px;
|
80 |
-
background: #f8f5ff;
|
81 |
-
width: 220px;
|
82 |
-
text-align: center;
|
83 |
-
">
|
84 |
-
<strong>Eligibility</strong><br>
|
85 |
-
Full-text assessed (n = {num_studies})<br>
|
86 |
-
Excluded (n = 0)
|
87 |
-
</div>
|
88 |
-
<div style="margin-left: 20px;">→</div>
|
89 |
-
</div>
|
90 |
-
|
91 |
-
<!-- Included -->
|
92 |
-
<div style="margin-left: 150px;">
|
93 |
-
<div style="
|
94 |
-
border: 2px solid #4a00e0;
|
95 |
-
padding: 15px 25px;
|
96 |
-
border-radius: 8px;
|
97 |
-
background: #f8f5ff;
|
98 |
-
width: 220px;
|
99 |
-
text-align: center;
|
100 |
-
">
|
101 |
-
<strong>Included</strong><br>
|
102 |
-
Studies included (n = {num_studies})
|
103 |
-
</div>
|
104 |
-
</div>
|
105 |
-
|
106 |
-
<!-- Connecting lines -->
|
107 |
-
<div style="
|
108 |
-
position: absolute;
|
109 |
-
left: 240px;
|
110 |
-
top: 50px;
|
111 |
-
width: 20px;
|
112 |
-
height: 80%;
|
113 |
-
border-left: 2px dashed #4a00e0;
|
114 |
-
"></div>
|
115 |
-
<div style="
|
116 |
-
position: absolute;
|
117 |
-
left: 290px;
|
118 |
-
top: 130px;
|
119 |
-
width: 20px;
|
120 |
-
height: 60%;
|
121 |
-
border-left: 2px dashed #4a00e0;
|
122 |
-
"></div>
|
123 |
-
<div style="
|
124 |
-
position: absolute;
|
125 |
-
left: 340px;
|
126 |
-
top: 210px;
|
127 |
-
width: 20px;
|
128 |
-
height: 40%;
|
129 |
-
border-left: 2px dashed #4a00e0;
|
130 |
-
"></div>
|
131 |
-
</div>
|
132 |
-
</div>
|
133 |
-
"""
|
134 |
-
|
135 |
# Function to interact with OpenAI API for systematic review
|
136 |
def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
137 |
if not api_key:
|
@@ -228,17 +120,6 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
228 |
|
229 |
# Get the AI response
|
230 |
review_content = response["choices"][0]["message"]["content"]
|
231 |
-
|
232 |
-
# Generate PRISMA chart
|
233 |
-
num_studies = len(pdf_files)
|
234 |
-
prisma_chart = generate_prisma_chart(num_studies)
|
235 |
-
|
236 |
-
# Insert PRISMA chart after the abstract or methodology section
|
237 |
-
if "Methodology</h2>" in review_content:
|
238 |
-
review_content = review_content.replace("Methodology</h2>",
|
239 |
-
f"Methodology</h2>{prisma_chart}")
|
240 |
-
else:
|
241 |
-
review_content = prisma_chart + review_content
|
242 |
|
243 |
# Apply professional academic paper styling
|
244 |
styled_html = f"""
|
@@ -363,29 +244,6 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
363 |
font-size: 12px;
|
364 |
color: #777;
|
365 |
}}
|
366 |
-
/* PRISMA Flowchart Styling */
|
367 |
-
.prisma-section {{
|
368 |
-
margin: 40px 0;
|
369 |
-
text-align: center;
|
370 |
-
}}
|
371 |
-
|
372 |
-
.prisma-flowchart {{
|
373 |
-
display: inline-block;
|
374 |
-
position: relative;
|
375 |
-
padding: 30px 0;
|
376 |
-
text-align: left;
|
377 |
-
font-size: 14px;
|
378 |
-
}}
|
379 |
-
|
380 |
-
.prisma-flowchart div[style*="border: 2px solid"] {{
|
381 |
-
transition: all 0.3s ease;
|
382 |
-
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
383 |
-
}}
|
384 |
-
|
385 |
-
.prisma-flowchart div[style*="border: 2px solid"]:hover {{
|
386 |
-
transform: translateY(-3px);
|
387 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
388 |
-
}}
|
389 |
@media print {{
|
390 |
body {{
|
391 |
background-color: white;
|
|
|
24 |
except Exception as e:
|
25 |
return f"Error extracting text from PDF: {str(e)}"
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Function to interact with OpenAI API for systematic review
|
28 |
def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
29 |
if not api_key:
|
|
|
120 |
|
121 |
# Get the AI response
|
122 |
review_content = response["choices"][0]["message"]["content"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
# Apply professional academic paper styling
|
125 |
styled_html = f"""
|
|
|
244 |
font-size: 12px;
|
245 |
color: #777;
|
246 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
@media print {{
|
248 |
body {{
|
249 |
background-color: white;
|