shukdevdatta123 commited on
Commit
c502997
·
verified ·
1 Parent(s): d8e926d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -43
app.py CHANGED
@@ -24,41 +24,113 @@ 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 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>
60
  """
61
- return prisma_html
62
 
63
  # Function to interact with OpenAI API for systematic review
64
  def generate_systematic_review(pdf_files, review_question, include_tables=True):
@@ -132,18 +204,6 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
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:
@@ -168,8 +228,19 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
168
 
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">
@@ -292,6 +363,29 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
292
  font-size: 12px;
293
  color: #777;
294
  }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  @media print {{
296
  body {{
297
  background-color: white;
@@ -306,8 +400,6 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
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>
 
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):
 
204
  pdf_texts.append(pdf_text)
205
  pdf_names.append(pdf_name)
206
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  # Prepare the user prompt with the review question and instructions
208
  table_instruction = ""
209
  if include_tables:
 
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"""
245
  <!DOCTYPE html>
246
  <html lang="en">
 
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;
 
400
  <body>
401
  <div class="paper-container">
402
  {review_content}
 
 
403
  </div>
404
  </body>
405
  </html>