Update app.py
Browse files
app.py
CHANGED
@@ -25,13 +25,13 @@ def extract_text_from_pdf(pdf_path):
|
|
25 |
# Function to interact with OpenAI API for systematic review
|
26 |
def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
27 |
if not api_key:
|
28 |
-
return "
|
29 |
|
30 |
if not pdf_files:
|
31 |
-
return "
|
32 |
|
33 |
if not review_question:
|
34 |
-
return "
|
35 |
|
36 |
try:
|
37 |
openai.api_key = api_key
|
@@ -110,53 +110,19 @@ def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
|
110 |
max_tokens=2048
|
111 |
)
|
112 |
|
113 |
-
#
|
114 |
review_content = response["choices"][0]["message"]["content"]
|
115 |
|
116 |
-
#
|
117 |
-
|
118 |
-
<h2>Systematic Review
|
119 |
-
<p><strong>Research Papers:</strong> {', '.join(pdf_names)}</p>
|
120 |
-
<h3>Review Process</h3>
|
121 |
-
<ul>
|
122 |
-
<li>Identified Research Field</li>
|
123 |
-
<li>Research Question Formulation</li>
|
124 |
-
<li>Protocol Creation</li>
|
125 |
-
<li>Literature Evaluation</li>
|
126 |
-
<li>Source Investigation</li>
|
127 |
-
<li>Data Collection</li>
|
128 |
-
<li>Data Extraction</li>
|
129 |
-
<li>Critical Analysis of Results</li>
|
130 |
-
<li>Interpretation of Derivations</li>
|
131 |
-
<li>Concluding Statements</li>
|
132 |
-
</ul>
|
133 |
-
<h3>Generated Review:</h3>
|
134 |
<p>{review_content}</p>
|
135 |
"""
|
136 |
-
|
137 |
-
# If tables are included in the review
|
138 |
-
if include_tables:
|
139 |
-
html_response += """
|
140 |
-
<h3>Comparison Tables</h3>
|
141 |
-
<table border="1">
|
142 |
-
<tr>
|
143 |
-
<th>Study</th>
|
144 |
-
<th>Key Findings</th>
|
145 |
-
<th>Comparison</th>
|
146 |
-
</tr>
|
147 |
-
<!-- Include tables here -->
|
148 |
-
<tr>
|
149 |
-
<td>Study 1</td>
|
150 |
-
<td>Summary of findings</td>
|
151 |
-
<td>Comparison with other studies</td>
|
152 |
-
</tr>
|
153 |
-
</table>
|
154 |
-
"""
|
155 |
|
156 |
-
return
|
157 |
|
158 |
except Exception as e:
|
159 |
-
return f"
|
160 |
|
161 |
# Function to save uploaded files
|
162 |
def save_uploaded_files(files):
|
@@ -178,7 +144,7 @@ with gr.Blocks() as demo:
|
|
178 |
gr.Markdown("# Systematic Review Generator for Research Papers")
|
179 |
|
180 |
with gr.Accordion("How to Use This App", open=True):
|
181 |
-
gr.Markdown("""
|
182 |
### Getting Started:
|
183 |
1. Enter your OpenAI API key in the field below and click "Set API Key"
|
184 |
2. Upload multiple PDF research papers (2 or more recommended)
|
@@ -208,7 +174,7 @@ with gr.Blocks() as demo:
|
|
208 |
generate_button = gr.Button("Generate Systematic Review", elem_id="generate_button")
|
209 |
|
210 |
# Output
|
211 |
-
review_output = gr.HTML(label="Systematic Review"
|
212 |
|
213 |
# Button actions
|
214 |
api_key_button.click(set_api_key, inputs=[api_key_input], outputs=[api_key_output])
|
@@ -216,7 +182,7 @@ with gr.Blocks() as demo:
|
|
216 |
# Generate systematic review
|
217 |
def process_files_and_generate_review(files, question, include_tables):
|
218 |
if not files:
|
219 |
-
return "
|
220 |
|
221 |
# Save uploaded files
|
222 |
saved_paths = save_uploaded_files(files)
|
|
|
25 |
# Function to interact with OpenAI API for systematic review
|
26 |
def generate_systematic_review(pdf_files, review_question, include_tables=True):
|
27 |
if not api_key:
|
28 |
+
return "Please enter your OpenAI API key first."
|
29 |
|
30 |
if not pdf_files:
|
31 |
+
return "Please upload at least one PDF file."
|
32 |
|
33 |
if not review_question:
|
34 |
+
return "Please enter a review question."
|
35 |
|
36 |
try:
|
37 |
openai.api_key = api_key
|
|
|
110 |
max_tokens=2048
|
111 |
)
|
112 |
|
113 |
+
# Format the response in HTML
|
114 |
review_content = response["choices"][0]["message"]["content"]
|
115 |
|
116 |
+
# Create a basic HTML structure
|
117 |
+
html_output = f"""
|
118 |
+
<h2>Systematic Review</h2>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
<p>{review_content}</p>
|
120 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
+
return html_output
|
123 |
|
124 |
except Exception as e:
|
125 |
+
return f"Error generating systematic review: {str(e)}"
|
126 |
|
127 |
# Function to save uploaded files
|
128 |
def save_uploaded_files(files):
|
|
|
144 |
gr.Markdown("# Systematic Review Generator for Research Papers")
|
145 |
|
146 |
with gr.Accordion("How to Use This App", open=True):
|
147 |
+
gr.Markdown("""
|
148 |
### Getting Started:
|
149 |
1. Enter your OpenAI API key in the field below and click "Set API Key"
|
150 |
2. Upload multiple PDF research papers (2 or more recommended)
|
|
|
174 |
generate_button = gr.Button("Generate Systematic Review", elem_id="generate_button")
|
175 |
|
176 |
# Output
|
177 |
+
review_output = gr.HTML(label="Systematic Review")
|
178 |
|
179 |
# Button actions
|
180 |
api_key_button.click(set_api_key, inputs=[api_key_input], outputs=[api_key_output])
|
|
|
182 |
# Generate systematic review
|
183 |
def process_files_and_generate_review(files, question, include_tables):
|
184 |
if not files:
|
185 |
+
return "Please upload at least one PDF file."
|
186 |
|
187 |
# Save uploaded files
|
188 |
saved_paths = save_uploaded_files(files)
|