Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from src.grobid import extract_metadata_grobid | |
| from src.pdf_parser import extract_text_from_pdf | |
| from src.rag_pipeline import ( | |
| create_rag_database, | |
| analyze_paper | |
| ) | |
| def upload_section(): | |
| st.header("📤 Upload Research Papers") | |
| uploaded_files = st.file_uploader( | |
| "Upload PDF papers", | |
| type="pdf", | |
| accept_multiple_files=True | |
| ) | |
| if not uploaded_files: | |
| return | |
| new_papers = [] | |
| progress = st.progress(0) | |
| status = st.empty() | |
| total_files = len(uploaded_files) | |
| for idx, file in enumerate(uploaded_files): | |
| status.write( | |
| f"Processing **{file.name}**..." | |
| ) | |
| # ---------------------------- | |
| # GROBID Metadata | |
| # ---------------------------- | |
| try: | |
| meta = extract_metadata_grobid(file) | |
| except Exception: | |
| meta = { | |
| "title": file.name.replace(".pdf", ""), | |
| "authors": ["Unknown"], | |
| "abstract": "" | |
| } | |
| # ---------------------------- | |
| # Read Full Paper | |
| # ---------------------------- | |
| file.seek(0) | |
| text = extract_text_from_pdf(file) | |
| meta["text"] = text | |
| if not meta.get("abstract"): | |
| meta["abstract"] = text[:3000] | |
| # ---------------------------- | |
| # One AI Call | |
| # ---------------------------- | |
| try: | |
| ai_result = analyze_paper( | |
| text=text, | |
| abstract=meta["abstract"] | |
| ) | |
| meta.update(ai_result) | |
| except Exception: | |
| meta["summary"] = "Summary could not be generated." | |
| meta["abstract_summary"] = "Abstract summary unavailable." | |
| meta["limitations"] = "Limitations unavailable." | |
| meta["research_gaps"] = "Research gaps unavailable." | |
| new_papers.append(meta) | |
| progress.progress( | |
| (idx + 1) / total_files | |
| ) | |
| st.session_state.papers.extend( | |
| new_papers | |
| ) | |
| create_rag_database( | |
| st.session_state.papers | |
| ) | |
| progress.empty() | |
| status.empty() | |
| st.success( | |
| f"Successfully processed {len(new_papers)} paper(s)." | |
| ) |