Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,9 @@ client = Groq(
|
|
18 |
# Helper Functions (Groq-based)
|
19 |
# -------------------------------
|
20 |
def groq_summarize(text: str) -> str:
|
|
|
|
|
|
|
21 |
response = client.chat.completions.create(
|
22 |
messages=[
|
23 |
{"role": "user", "content": f"Summarize the following text in detail:\n\n{text}"}
|
@@ -26,58 +29,67 @@ def groq_summarize(text: str) -> str:
|
|
26 |
)
|
27 |
return response.choices[0].message.content.strip()
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
"
|
46 |
-
|
|
|
47 |
|
48 |
-
# -------------------------------
|
49 |
-
# Retrieve Papers
|
50 |
-
# -------------------------------
|
51 |
def retrieve_papers(query, max_results=5):
|
|
|
52 |
search = arxiv.Search(query=query, max_results=max_results)
|
53 |
papers = []
|
54 |
for result in search.results():
|
55 |
-
paper_id = result.entry_id.split("/")[-1]
|
56 |
-
trust_score, relevance_score = calculate_trust_relevance(result)
|
57 |
-
external_links = get_external_links(paper_id)
|
58 |
paper = {
|
59 |
"title": result.title,
|
60 |
"summary": result.summary,
|
61 |
"url": result.pdf_url,
|
62 |
"authors": [author.name for author in result.authors],
|
63 |
"published": result.published,
|
64 |
-
"
|
65 |
-
"
|
66 |
-
"
|
|
|
|
|
67 |
}
|
68 |
papers.append(paper)
|
69 |
return papers
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.title("π PaperPilot β Intelligent Academic Navigator")
|
75 |
|
76 |
with st.sidebar:
|
77 |
st.header("π Search Parameters")
|
78 |
query = st.text_input("Research topic or question:")
|
79 |
-
show_scores = st.checkbox("Show Trust & Relevance Scores", value=True)
|
80 |
-
|
81 |
if st.button("π Find Articles"):
|
82 |
if query.strip():
|
83 |
with st.spinner("Searching arXiv..."):
|
@@ -85,30 +97,36 @@ with st.sidebar:
|
|
85 |
if papers:
|
86 |
st.session_state.papers = papers
|
87 |
st.success(f"Found {len(papers)} papers!")
|
88 |
-
st.session_state.active_section = "
|
89 |
else:
|
90 |
st.error("No papers found. Try different keywords.")
|
91 |
else:
|
92 |
st.warning("Please enter a search query")
|
93 |
|
|
|
|
|
|
|
94 |
if 'papers' in st.session_state and st.session_state.papers:
|
95 |
papers = st.session_state.papers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
st.header("π Retrieved Papers")
|
98 |
-
for idx, paper in enumerate(papers, 1):
|
99 |
-
with st.expander(f"{idx}. {paper['title']}"):
|
100 |
-
st.markdown(f"**Authors:** {', '.join(paper['authors'])}")
|
101 |
-
pub_date = paper['published'].strftime('%Y-%m-%d') if isinstance(paper['published'], datetime.datetime) else "n.d."
|
102 |
-
st.markdown(f"**Published:** {pub_date}")
|
103 |
-
st.markdown(f"**Link:** [PDF Link]({paper['url']})")
|
104 |
-
if show_scores:
|
105 |
-
st.markdown(f"**Trust Score:** {paper['trust_score']:.2f} | **Relevance Score:** {paper['relevance_score']:.2f}")
|
106 |
-
st.markdown("**External Research Tools:**")
|
107 |
-
for tool, link in paper["external_links"].items():
|
108 |
-
st.markdown(f"- [{tool}]({link})")
|
109 |
-
st.markdown("**Abstract:**")
|
110 |
-
st.write(paper['summary'])
|
111 |
else:
|
112 |
st.info("Enter a query in the sidebar and click 'Find Articles' to get started.")
|
113 |
|
114 |
-
st.caption("Built with β€οΈ using AI")
|
|
|
18 |
# Helper Functions (Groq-based)
|
19 |
# -------------------------------
|
20 |
def groq_summarize(text: str) -> str:
|
21 |
+
"""
|
22 |
+
Summarize the given text using Groq's chat completion API.
|
23 |
+
"""
|
24 |
response = client.chat.completions.create(
|
25 |
messages=[
|
26 |
{"role": "user", "content": f"Summarize the following text in detail:\n\n{text}"}
|
|
|
29 |
)
|
30 |
return response.choices[0].message.content.strip()
|
31 |
|
32 |
+
def groq_simplify(text: str) -> str:
|
33 |
+
"""
|
34 |
+
Explain Like I'm 5 (ELI5) version of the summary.
|
35 |
+
"""
|
36 |
+
response = client.chat.completions.create(
|
37 |
+
messages=[
|
38 |
+
{"role": "user", "content": f"Explain the following like I'm 5 years old:\n\n{text}"}
|
39 |
+
],
|
40 |
+
model="llama-3.3-70b-versatile",
|
41 |
+
)
|
42 |
+
return response.choices[0].message.content.strip()
|
43 |
|
44 |
+
def groq_generate_key_takeaways(text: str) -> str:
|
45 |
+
"""
|
46 |
+
Generate key takeaways from the paper.
|
47 |
+
"""
|
48 |
+
response = client.chat.completions.create(
|
49 |
+
messages=[
|
50 |
+
{"role": "user", "content": f"Provide key takeaways from this research paper:\n\n{text}"}
|
51 |
+
],
|
52 |
+
model="llama-3.3-70b-versatile",
|
53 |
+
)
|
54 |
+
return response.choices[0].message.content.strip()
|
55 |
|
|
|
|
|
|
|
56 |
def retrieve_papers(query, max_results=5):
|
57 |
+
"""Retrieve academic papers from arXiv, including DOI and tools for relevance/trust scoring."""
|
58 |
search = arxiv.Search(query=query, max_results=max_results)
|
59 |
papers = []
|
60 |
for result in search.results():
|
|
|
|
|
|
|
61 |
paper = {
|
62 |
"title": result.title,
|
63 |
"summary": result.summary,
|
64 |
"url": result.pdf_url,
|
65 |
"authors": [author.name for author in result.authors],
|
66 |
"published": result.published,
|
67 |
+
"doi": result.doi if hasattr(result, "doi") else f"https://doi.org/10.48550/arXiv.{result.entry_id.split('/')[-1]}",
|
68 |
+
"litmaps": f"https://app.litmaps.com/preview/{result.entry_id.split('/')[-1]}",
|
69 |
+
"connected_papers": f"https://www.connectedpapers.com/main/{result.entry_id.split('/')[-1]}",
|
70 |
+
"scite_ai": f"https://scite.ai/reports/{result.entry_id.split('/')[-1]}",
|
71 |
+
"biblio_explorer": f"https://arxiv.org/bib_explorer/{result.entry_id.split('/')[-1]}",
|
72 |
}
|
73 |
papers.append(paper)
|
74 |
return papers
|
75 |
|
76 |
+
def get_cached_summary(paper_id, text):
|
77 |
+
"""Retrieve or generate summaries, ELI5 explanations, and key takeaways."""
|
78 |
+
if 'summaries' not in st.session_state:
|
79 |
+
st.session_state.summaries = {}
|
80 |
+
if paper_id not in st.session_state.summaries:
|
81 |
+
st.session_state.summaries[paper_id] = {
|
82 |
+
"summary": groq_summarize(text),
|
83 |
+
"eli5": groq_simplify(text),
|
84 |
+
"key_takeaways": groq_generate_key_takeaways(text),
|
85 |
+
}
|
86 |
+
return st.session_state.summaries[paper_id]
|
87 |
+
|
88 |
st.title("π PaperPilot β Intelligent Academic Navigator")
|
89 |
|
90 |
with st.sidebar:
|
91 |
st.header("π Search Parameters")
|
92 |
query = st.text_input("Research topic or question:")
|
|
|
|
|
93 |
if st.button("π Find Articles"):
|
94 |
if query.strip():
|
95 |
with st.spinner("Searching arXiv..."):
|
|
|
97 |
if papers:
|
98 |
st.session_state.papers = papers
|
99 |
st.success(f"Found {len(papers)} papers!")
|
100 |
+
st.session_state.active_section = "review"
|
101 |
else:
|
102 |
st.error("No papers found. Try different keywords.")
|
103 |
else:
|
104 |
st.warning("Please enter a search query")
|
105 |
|
106 |
+
if 'active_section' not in st.session_state:
|
107 |
+
st.session_state.active_section = "none"
|
108 |
+
|
109 |
if 'papers' in st.session_state and st.session_state.papers:
|
110 |
papers = st.session_state.papers
|
111 |
+
|
112 |
+
if st.session_state.active_section == "review":
|
113 |
+
st.header("π Literature Review & Summary")
|
114 |
+
for idx, paper in enumerate(papers, 1):
|
115 |
+
with st.expander(f"Summary: {paper['title']}"):
|
116 |
+
with st.spinner(f"Analyzing {paper['title']}..."):
|
117 |
+
paper_id = f"paper_{idx}"
|
118 |
+
summary_data = get_cached_summary(paper_id, paper['summary'])
|
119 |
+
st.markdown(f"**Summary:** {summary_data['summary']}")
|
120 |
+
st.markdown(f"**ELI5:** {summary_data['eli5']}")
|
121 |
+
st.markdown("**Key Takeaways:**")
|
122 |
+
st.write(summary_data['key_takeaways'])
|
123 |
+
st.markdown(f"**DOI:** [Link]({paper['doi']})")
|
124 |
+
st.markdown(f"**Bibliographic Explorer:** [View]({paper['biblio_explorer']})")
|
125 |
+
st.markdown(f"**Connected Papers:** [View]({paper['connected_papers']})")
|
126 |
+
st.markdown(f"**Litmaps:** [View]({paper['litmaps']})")
|
127 |
+
st.markdown(f"**Scite.ai Citations:** [View]({paper['scite_ai']})")
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
else:
|
130 |
st.info("Enter a query in the sidebar and click 'Find Articles' to get started.")
|
131 |
|
132 |
+
st.caption("Built with β€οΈ using AI")
|