Spaces:
Sleeping
Sleeping
File size: 6,084 Bytes
449bb7f ff54315 449bb7f ff54315 449bb7f ff54315 449bb7f ff54315 449bb7f ff54315 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# app.py
import streamlit as st
import arxiv
import networkx as nx
import matplotlib.pyplot as plt
import datetime
from transformers import pipeline
# Initialize Hugging Face pipelines for summarization and text generation
@st.cache_resource(show_spinner=False)
def load_summarizer():
return pipeline("summarization", model="facebook/bart-large-cnn")
@st.cache_resource(show_spinner=False)
def load_generator():
return pipeline("text-generation", model="gpt2")
summarizer = load_summarizer()
generator = load_generator()
# -------------------------------
# Helper Functions
# -------------------------------
def retrieve_papers(query, max_results=5):
"""
Retrieve academic papers from arXiv based on the query.
"""
search = arxiv.Search(query=query, max_results=max_results)
papers = []
for result in search.results():
paper = {
"title": result.title,
"summary": result.summary,
"url": result.pdf_url,
"authors": [author.name for author in result.authors],
"published": result.published
}
papers.append(paper)
return papers
def summarize_text(text):
"""
Use a generative model to create a concise summary of the input text.
"""
# The summarizer may need the text to be below a certain token length.
# If necessary, you could chunk the text.
summarized = summarizer(text, max_length=130, min_length=30, do_sample=False)
return summarized[0]['summary_text']
def generate_concept_map(papers):
"""
Generate a visual concept map by connecting papers with shared authors.
"""
G = nx.Graph()
# Add nodes for each paper title
for paper in papers:
G.add_node(paper['title'])
# Create edges between papers that share at least one common author
for i in range(len(papers)):
for j in range(i + 1, len(papers)):
common_authors = set(papers[i]['authors']).intersection(set(papers[j]['authors']))
if common_authors:
G.add_edge(papers[i]['title'], papers[j]['title'])
return G
def generate_citation(paper):
"""
Format citation information in APA style.
"""
authors = ", ".join(paper['authors'])
year = paper['published'].year if isinstance(paper['published'], datetime.datetime) else "n.d."
title = paper['title']
url = paper['url']
citation = f"{authors} ({year}). {title}. Retrieved from {url}"
return citation
def generate_proposal_suggestions(text):
"""
Generate research proposal suggestions based on the synthesized literature review.
"""
prompt = (
"Based on the following literature review, propose a novel research proposal "
"including potential research questions and an outline for experimental design.\n\n"
f"{text}\n\nProposal:"
)
generated = generator(prompt, max_new_tokens=50, num_return_sequences=1)
return generated[0]['generated_text']
# -------------------------------
# Streamlit User Interface
# -------------------------------
st.title("📚PaperPilot – The Intelligent Academic Navigator")
st.markdown("Welcome to **PaperPilot**! Enter a research topic or question below to retrieve academic papers, generate summaries, visualize concept maps, format citations, and get research proposal suggestions.")
# Input section
query = st.text_input("Research Topic or Question:")
if st.button("Search"):
if query.strip() == "":
st.warning("Please enter a research topic or question.")
else:
# --- Step 1: Retrieve Papers ---
with st.spinner("Retrieving relevant academic papers..."):
papers = retrieve_papers(query, max_results=5)
if not papers:
st.error("No papers found. Please try a different query.")
else:
st.success(f"Found {len(papers)} papers.")
# --- Step 2: Display Retrieved Papers ---
st.header("Retrieved Papers")
for idx, paper in enumerate(papers, start=1):
with st.expander(f"{idx}. {paper['title']}"):
st.markdown(f"**Authors:** {', '.join(paper['authors'])}")
st.markdown(f"**Published:** {paper['published'].strftime('%Y-%m-%d') if isinstance(paper['published'], datetime.datetime) else 'n.d.'}")
st.markdown(f"**Link:** [PDF Link]({paper['url']})")
st.markdown("**Abstract:**")
st.write(paper['summary'])
# --- Step 3: Generate Summaries & Literature Review ---
st.header("Automated Summaries & Literature Review")
combined_summary = ""
for paper in papers:
st.subheader(f"Summary for: {paper['title']}")
# Use the paper summary as input for further summarization
summary_text = summarize_text(paper['summary'])
st.write(summary_text)
combined_summary += summary_text + " "
# --- Step 4: Create Visual Concept Map & Gap Analysis ---
st.header("Visual Concept Map & Gap Analysis")
G = generate_concept_map(papers)
if len(G.nodes) > 0:
fig, ax = plt.subplots(figsize=(8, 6))
pos = nx.spring_layout(G, seed=42)
nx.draw_networkx(G, pos, with_labels=True, node_color='skyblue', edge_color='gray', node_size=1500, font_size=8, ax=ax)
st.pyplot(fig)
else:
st.info("Not enough data to generate a concept map.")
# --- Step 5: Citation & Reference Management ---
st.header("Formatted Citations (APA Style)")
for paper in papers:
citation = generate_citation(paper)
st.markdown(f"- {citation}")
# --- Step 6: Research Proposal Assistance ---
st.header("Research Proposal Suggestions")
proposal = generate_proposal_suggestions(combined_summary)
st.write(proposal)
st.caption("Built with ❤️") |