Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import arxiv
|
4 |
-
import requests
|
5 |
-
import datetime
|
6 |
import networkx as nx
|
7 |
import matplotlib.pyplot as plt
|
|
|
8 |
|
9 |
# -------------------------------
|
10 |
# Groq API Client
|
@@ -19,9 +18,6 @@ client = Groq(
|
|
19 |
# Helper Functions (Groq-based)
|
20 |
# -------------------------------
|
21 |
def groq_summarize(text: str) -> str:
|
22 |
-
"""
|
23 |
-
Summarize the given text using Groq's chat completion API.
|
24 |
-
"""
|
25 |
response = client.chat.completions.create(
|
26 |
messages=[
|
27 |
{"role": "user", "content": f"Summarize the following text in detail:\n\n{text}"}
|
@@ -31,55 +27,45 @@ def groq_summarize(text: str) -> str:
|
|
31 |
return response.choices[0].message.content.strip()
|
32 |
|
33 |
# -------------------------------
|
34 |
-
# Trust & Relevance
|
35 |
# -------------------------------
|
36 |
-
def
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
# Fetch citation data from scite.ai
|
41 |
-
scite_url = f"https://api.scite.ai/papers/{arxiv_id}"
|
42 |
-
response = requests.get(scite_url)
|
43 |
-
if response.status_code == 200:
|
44 |
-
scite_data = response.json()
|
45 |
-
metadata["citations"] = scite_data.get("citation_count", 0)
|
46 |
-
metadata["trust_score"] = scite_data.get("trust_score", 0)
|
47 |
-
|
48 |
-
# Generate Connected Papers & Litmaps links
|
49 |
-
metadata["links"]["Connected Papers"] = f"https://www.connectedpapers.com/main/{arxiv_id}"
|
50 |
-
metadata["links"]["Bibliographic Explorer"] = f"https://arxiv.org/bib_explorer/{arxiv_id}"
|
51 |
-
metadata["links"]["Litmaps"] = f"https://www.litmaps.com/publications/{arxiv_id}"
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# -------------------------------
|
59 |
# Retrieve Papers
|
60 |
# -------------------------------
|
61 |
def retrieve_papers(query, max_results=5):
|
62 |
-
"""Retrieve academic papers from arXiv & add Trust/Relevance scores."""
|
63 |
search = arxiv.Search(query=query, max_results=max_results)
|
64 |
papers = []
|
65 |
-
|
66 |
for result in search.results():
|
67 |
-
paper_id = result.entry_id.split("/")[-1]
|
68 |
-
|
69 |
-
|
70 |
paper = {
|
71 |
"title": result.title,
|
72 |
"summary": result.summary,
|
73 |
"url": result.pdf_url,
|
74 |
"authors": [author.name for author in result.authors],
|
75 |
"published": result.published,
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"links": metadata["links"],
|
80 |
}
|
81 |
papers.append(paper)
|
82 |
-
|
83 |
return papers
|
84 |
|
85 |
# -------------------------------
|
@@ -87,11 +73,10 @@ def retrieve_papers(query, max_results=5):
|
|
87 |
# -------------------------------
|
88 |
st.title("π PaperPilot β Intelligent Academic Navigator")
|
89 |
|
90 |
-
# Sidebar: Search & Toggle
|
91 |
with st.sidebar:
|
92 |
st.header("π Search Parameters")
|
93 |
query = st.text_input("Research topic or question:")
|
94 |
-
show_scores = st.checkbox("
|
95 |
|
96 |
if st.button("π Find Articles"):
|
97 |
if query.strip():
|
@@ -99,37 +84,31 @@ with st.sidebar:
|
|
99 |
papers = retrieve_papers(query)
|
100 |
if papers:
|
101 |
st.session_state.papers = papers
|
102 |
-
st.session_state.active_section = "articles"
|
103 |
st.success(f"Found {len(papers)} papers!")
|
|
|
104 |
else:
|
105 |
st.error("No papers found. Try different keywords.")
|
106 |
else:
|
107 |
st.warning("Please enter a search query")
|
108 |
|
109 |
-
# Main Content
|
110 |
if 'papers' in st.session_state and st.session_state.papers:
|
111 |
papers = st.session_state.papers
|
112 |
-
|
113 |
st.header("π Retrieved Papers")
|
114 |
for idx, paper in enumerate(papers, 1):
|
115 |
with st.expander(f"{idx}. {paper['title']}"):
|
116 |
st.markdown(f"**Authors:** {', '.join(paper['authors'])}")
|
117 |
-
|
118 |
-
st.markdown(f"**
|
119 |
-
|
120 |
-
# Show Trust & Relevance Scores if enabled
|
121 |
if show_scores:
|
122 |
-
st.markdown(f"
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
# External Links
|
127 |
-
st.markdown(f"[π Connected Papers]({paper['links']['Connected Papers']})")
|
128 |
-
st.markdown(f"[π Bibliographic Explorer]({paper['links']['Bibliographic Explorer']})")
|
129 |
-
st.markdown(f"[π Litmaps]({paper['links']['Litmaps']})")
|
130 |
-
|
131 |
-
# Display Summary
|
132 |
st.markdown("**Abstract:**")
|
133 |
st.write(paper['summary'])
|
|
|
|
|
134 |
|
135 |
-
st.caption("Built with β€οΈ using AI")
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import arxiv
|
|
|
|
|
4 |
import networkx as nx
|
5 |
import matplotlib.pyplot as plt
|
6 |
+
import datetime
|
7 |
|
8 |
# -------------------------------
|
9 |
# Groq API Client
|
|
|
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}"}
|
|
|
27 |
return response.choices[0].message.content.strip()
|
28 |
|
29 |
# -------------------------------
|
30 |
+
# Trust & Relevance Scoring
|
31 |
# -------------------------------
|
32 |
+
def calculate_trust_relevance(paper):
|
33 |
+
trust_score = 0.8 # Placeholder value, can be enhanced with external APIs
|
34 |
+
relevance_score = 0.9 # Placeholder value
|
35 |
+
return trust_score, relevance_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
# -------------------------------
|
38 |
+
# External Research Tools
|
39 |
+
# -------------------------------
|
40 |
+
def get_external_links(paper_id):
|
41 |
+
return {
|
42 |
+
"Bibliographic Explorer": f"https://ui.adsabs.harvard.edu/#abs/{paper_id}/bibliography",
|
43 |
+
"Connected Papers": f"https://www.connectedpapers.com/main/{paper_id}",
|
44 |
+
"Litmaps": f"https://app.litmaps.com/preview/{paper_id}",
|
45 |
+
"Scite.ai": f"https://scite.ai/reports/{paper_id}"
|
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 |
+
"trust_score": trust_score,
|
65 |
+
"relevance_score": relevance_score,
|
66 |
+
"external_links": external_links
|
|
|
67 |
}
|
68 |
papers.append(paper)
|
|
|
69 |
return papers
|
70 |
|
71 |
# -------------------------------
|
|
|
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():
|
|
|
84 |
papers = retrieve_papers(query)
|
85 |
if papers:
|
86 |
st.session_state.papers = papers
|
|
|
87 |
st.success(f"Found {len(papers)} papers!")
|
88 |
+
st.session_state.active_section = "articles"
|
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")
|