shukdevdatta123 commited on
Commit
a92935b
Β·
verified Β·
1 Parent(s): 05d1c2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +117 -1
app.py CHANGED
@@ -24,6 +24,112 @@ 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 interact with OpenAI API for systematic review
28
  def generate_systematic_review(pdf_files, review_question, include_tables=True):
29
  if not api_key:
@@ -39,7 +145,7 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
39
  openai.api_key = api_key
40
 
41
  # Create the system message with systematic review guidelines
42
- 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:
43
 
44
  Step 1: Identify a Research Field
45
  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.
@@ -121,6 +227,15 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
121
  # Get the AI response
122
  review_content = response["choices"][0]["message"]["content"]
123
 
 
 
 
 
 
 
 
 
 
124
  # Apply professional academic paper styling
125
  styled_html = f"""
126
  <!DOCTYPE html>
@@ -449,6 +564,7 @@ with gr.Blocks(css=custom_css) as demo:
449
  - Upload papers that are related to the same research topic or field
450
  - Be specific in your review question to get more focused results
451
  - The generated review will follow a systematic structure including research field identification, data extraction, analysis, and conclusions
 
452
  - The more papers you upload, the more comprehensive the review will be
453
  - The review will be formatted as a professional academic paper with proper sections and citations
454
  """)
 
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():
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 class="prisma-flowchart" style="margin: 40px 0; font-family: 'Times New Roman', Times, serif; font-size: 14px;">
44
+ <h3 style="text-align: center; margin-bottom: 20px;">PRISMA Flow Diagram</h3>
45
+ <div style="display: flex; justify-content: space-between;">
46
+ <!-- Left Side: Database Search -->
47
+ <div style="width: 45%;">
48
+ <div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
49
+ Identification of new studies via databases and registers<br>
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
+ <!-- Right Side: Other Methods -->
98
+ <div style="width: 45%;">
99
+ <div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
100
+ Identification of new studies via other methods<br>
101
+ Records identified from:<br>
102
+ Websites (n = 0)<br>
103
+ Organisations (n = 0)<br>
104
+ Citation searching (n = 0)
105
+ </div>
106
+ <div style="text-align: center; margin: 10px 0;">↓</div>
107
+ <div style="background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
108
+ Reports sought for retrieval (n = {reports_sought})
109
+ </div>
110
+ <div style="display: flex; justify-content: space-between; align-items: center;">
111
+ <div style="width: 50%; text-align: center; margin: 10px 0;">↓</div>
112
+ <div style="width: 50%; background-color: #f0f0f0; padding: 10px; border: 1px solid #ccc; text-align: center;">
113
+ Reports not retrieved (n = {reports_not_retrieved})
114
+ </div>
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>
130
+ """
131
+ return prisma_html
132
+
133
  # Function to interact with OpenAI API for systematic review
134
  def generate_systematic_review(pdf_files, review_question, include_tables=True):
135
  if not api_key:
 
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 detail. Structure it using these steps:
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.
 
227
  # Get the AI response
228
  review_content = response["choices"][0]["message"]["content"]
229
 
230
+ # Generate PRISMA flow chart
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>
 
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
  """)