Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -170,7 +170,6 @@ def generate_focused_summary(question, abstracts, model, tokenizer):
|
|
170 |
|
171 |
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
172 |
|
173 |
-
|
174 |
def main():
|
175 |
st.title("π¬ Biomedical Papers Analysis")
|
176 |
|
@@ -198,9 +197,6 @@ def main():
|
|
198 |
df = st.session_state.processed_data
|
199 |
st.write(f"π Loaded {len(df)} papers")
|
200 |
|
201 |
-
# Individual Summaries Section
|
202 |
-
st.header("π Individual Paper Summaries")
|
203 |
-
|
204 |
# Question input before the unified generate button
|
205 |
st.header("β Question-focused Summary (Optional)")
|
206 |
question = st.text_input("Enter your research question (optional):")
|
@@ -217,7 +213,7 @@ def main():
|
|
217 |
progress_bar = st.progress(0)
|
218 |
|
219 |
# Create a table for live updates
|
220 |
-
summary_table = st.
|
221 |
summaries = []
|
222 |
table_data = []
|
223 |
|
@@ -230,14 +226,14 @@ def main():
|
|
230 |
|
231 |
# Update table data
|
232 |
table_data.append({
|
233 |
-
"
|
234 |
-
"
|
235 |
})
|
236 |
summary_table.dataframe(
|
237 |
pd.DataFrame(table_data),
|
238 |
column_config={
|
239 |
-
"
|
240 |
-
"
|
241 |
},
|
242 |
hide_index=True
|
243 |
)
|
@@ -257,12 +253,14 @@ def main():
|
|
257 |
torch.cuda.empty_cache()
|
258 |
gc.collect()
|
259 |
|
|
|
260 |
results = st.session_state.text_processor.find_most_relevant_abstracts(
|
261 |
question,
|
262 |
df['Abstract'].tolist(),
|
263 |
top_k=5
|
264 |
)
|
265 |
|
|
|
266 |
model, tokenizer = load_model("question_focused")
|
267 |
|
268 |
relevant_abstracts = df['Abstract'].iloc[results['top_indices']].tolist()
|
@@ -303,38 +301,37 @@ def main():
|
|
303 |
|
304 |
# Display sorted summaries if they exist
|
305 |
if st.session_state.summaries is not None:
|
306 |
-
st.
|
307 |
-
|
308 |
-
'Article Title': 'Article Title',
|
309 |
-
'Authors': 'Authors',
|
310 |
-
'Publication Year': 'Publication Year',
|
311 |
-
'Source Title': 'Source Title'
|
312 |
-
}
|
313 |
-
|
314 |
-
col1, col2 = st.columns(2)
|
315 |
with col1:
|
316 |
-
|
|
|
|
|
|
|
|
|
317 |
with col2:
|
318 |
-
ascending = st.checkbox("Ascending order", True)
|
319 |
|
|
|
320 |
display_df = df.copy()
|
321 |
-
display_df['
|
322 |
-
|
323 |
-
|
|
|
|
|
|
|
|
|
|
|
324 |
|
|
|
325 |
st.dataframe(
|
326 |
-
sorted_df[['
|
327 |
-
'Publication Year', 'DOI', 'Summary']],
|
328 |
column_config={
|
329 |
-
|
330 |
-
|
331 |
-
'Source Title': st.column_config.TextColumn('Source Title', width='medium'),
|
332 |
-
'Publication Year': st.column_config.NumberColumn('Year', format="%d"),
|
333 |
-
'DOI': st.column_config.TextColumn('DOI', width='small'),
|
334 |
-
'Summary': st.column_config.TextColumn('Summary', width='large'),
|
335 |
},
|
336 |
hide_index=True
|
337 |
)
|
338 |
|
339 |
if __name__ == "__main__":
|
340 |
-
main()
|
|
|
170 |
|
171 |
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
172 |
|
|
|
173 |
def main():
|
174 |
st.title("π¬ Biomedical Papers Analysis")
|
175 |
|
|
|
197 |
df = st.session_state.processed_data
|
198 |
st.write(f"π Loaded {len(df)} papers")
|
199 |
|
|
|
|
|
|
|
200 |
# Question input before the unified generate button
|
201 |
st.header("β Question-focused Summary (Optional)")
|
202 |
question = st.text_input("Enter your research question (optional):")
|
|
|
213 |
progress_bar = st.progress(0)
|
214 |
|
215 |
# Create a table for live updates
|
216 |
+
summary_table = st.empty()
|
217 |
summaries = []
|
218 |
table_data = []
|
219 |
|
|
|
226 |
|
227 |
# Update table data
|
228 |
table_data.append({
|
229 |
+
"PAPER": f"{row['Article Title']}\n{row['Authors']}\nDOI: {row['DOI']}",
|
230 |
+
"SUMMARY": summary
|
231 |
})
|
232 |
summary_table.dataframe(
|
233 |
pd.DataFrame(table_data),
|
234 |
column_config={
|
235 |
+
"PAPER": st.column_config.TextColumn("PAPER", width=300),
|
236 |
+
"SUMMARY": st.column_config.TextColumn("SUMMARY", width="medium")
|
237 |
},
|
238 |
hide_index=True
|
239 |
)
|
|
|
253 |
torch.cuda.empty_cache()
|
254 |
gc.collect()
|
255 |
|
256 |
+
# Find relevant abstracts
|
257 |
results = st.session_state.text_processor.find_most_relevant_abstracts(
|
258 |
question,
|
259 |
df['Abstract'].tolist(),
|
260 |
top_k=5
|
261 |
)
|
262 |
|
263 |
+
# Load question model
|
264 |
model, tokenizer = load_model("question_focused")
|
265 |
|
266 |
relevant_abstracts = df['Abstract'].iloc[results['top_indices']].tolist()
|
|
|
301 |
|
302 |
# Display sorted summaries if they exist
|
303 |
if st.session_state.summaries is not None:
|
304 |
+
st.header("π Individual Paper Summaries")
|
305 |
+
col1, col2 = st.columns([2, 1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
with col1:
|
307 |
+
sort_by = st.selectbox(
|
308 |
+
"Sort By",
|
309 |
+
["Article Title", "Publication Year"],
|
310 |
+
key="sort_summaries"
|
311 |
+
)
|
312 |
with col2:
|
313 |
+
ascending = st.checkbox("Ascending order", True, key="sort_order")
|
314 |
|
315 |
+
# Create display dataframe
|
316 |
display_df = df.copy()
|
317 |
+
display_df['PAPER'] = display_df.apply(
|
318 |
+
lambda x: f"{x['Article Title']}\n{x['Authors']}\nDOI: {x['DOI']}",
|
319 |
+
axis=1
|
320 |
+
)
|
321 |
+
display_df['SUMMARY'] = st.session_state.summaries
|
322 |
+
|
323 |
+
# Sort the dataframe
|
324 |
+
sorted_df = display_df.sort_values(by=sort_by, ascending=ascending)
|
325 |
|
326 |
+
# Display the table
|
327 |
st.dataframe(
|
328 |
+
sorted_df[['PAPER', 'SUMMARY']],
|
|
|
329 |
column_config={
|
330 |
+
"PAPER": st.column_config.TextColumn("PAPER", width=300),
|
331 |
+
"SUMMARY": st.column_config.TextColumn("SUMMARY", width="medium")
|
|
|
|
|
|
|
|
|
332 |
},
|
333 |
hide_index=True
|
334 |
)
|
335 |
|
336 |
if __name__ == "__main__":
|
337 |
+
main()
|