File size: 5,026 Bytes
fbec6c3
 
 
7aa208d
fbec6c3
7aa208d
 
fbec6c3
 
 
 
 
 
 
aee8230
fbec6c3
 
 
 
 
 
7aa208d
 
 
fbec6c3
 
7aa208d
f3f61db
 
 
 
 
7aa208d
 
 
 
 
 
fbec6c3
7aa208d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbec6c3
 
7aa208d
fbec6c3
 
7aa208d
fbec6c3
 
7aa208d
fbec6c3
7aa208d
 
 
fbec6c3
 
 
 
 
7aa208d
 
 
 
 
fbec6c3
 
7aa208d
fbec6c3
 
 
 
 
 
 
7aa208d
fbec6c3
 
 
7aa208d
fbec6c3
 
 
 
 
 
 
7aa208d
fbec6c3
 
 
 
 
 
7aa208d
fbec6c3
 
7aa208d
 
 
 
 
 
 
 
 
 
 
 
 
f3f61db
7aa208d
 
 
 
 
 
 
 
fbec6c3
7aa208d
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
import os
import streamlit as st
import arxiv
import requests
import datetime
import networkx as nx
import matplotlib.pyplot as plt

# -------------------------------
# Groq API Client
# -------------------------------
from groq import Groq

client = Groq(
    api_key=os.environ.get("GROQ_API_KEY"),
)

# -------------------------------
# Helper Functions (Groq-based)
# -------------------------------
def groq_summarize(text: str) -> str:
    """
    Summarize the given text using Groq's chat completion API.
    """
    response = client.chat.completions.create(
        messages=[
            {"role": "user", "content": f"Summarize the following text in detail:\n\n{text}"}
        ],
        model="llama-3.3-70b-versatile",
    )
    return response.choices[0].message.content.strip()

# -------------------------------
# Trust & Relevance Scores
# -------------------------------
def get_citation_metadata(arxiv_id):
    """Fetch trust & relevance scores from external sources."""
    metadata = {"citations": 0, "trust_score": 0, "relevance_score": 0, "links": {}}

    # Fetch citation data from scite.ai
    scite_url = f"https://api.scite.ai/papers/{arxiv_id}"
    response = requests.get(scite_url)
    if response.status_code == 200:
        scite_data = response.json()
        metadata["citations"] = scite_data.get("citation_count", 0)
        metadata["trust_score"] = scite_data.get("trust_score", 0)

    # Generate Connected Papers & Litmaps links
    metadata["links"]["Connected Papers"] = f"https://www.connectedpapers.com/main/{arxiv_id}"
    metadata["links"]["Bibliographic Explorer"] = f"https://arxiv.org/bib_explorer/{arxiv_id}"
    metadata["links"]["Litmaps"] = f"https://www.litmaps.com/publications/{arxiv_id}"

    # Calculate relevance score
    metadata["relevance_score"] = metadata["citations"] * 0.8 + metadata["trust_score"] * 0.2

    return metadata

# -------------------------------
# Retrieve Papers
# -------------------------------
def retrieve_papers(query, max_results=5):
    """Retrieve academic papers from arXiv & add Trust/Relevance scores."""
    search = arxiv.Search(query=query, max_results=max_results)
    papers = []

    for result in search.results():
        paper_id = result.entry_id.split("/")[-1]  # Extract arXiv ID
        metadata = get_citation_metadata(paper_id)

        paper = {
            "title": result.title,
            "summary": result.summary,
            "url": result.pdf_url,
            "authors": [author.name for author in result.authors],
            "published": result.published,
            "citations": metadata["citations"],
            "trust_score": metadata["trust_score"],
            "relevance_score": metadata["relevance_score"],
            "links": metadata["links"],
        }
        papers.append(paper)

    return papers

# -------------------------------
# Streamlit Interface
# -------------------------------
st.title("πŸ“š PaperPilot – Intelligent Academic Navigator")

# Sidebar: Search & Toggle
with st.sidebar:
    st.header("πŸ” Search Parameters")
    query = st.text_input("Research topic or question:")
    show_scores = st.checkbox("Enable Trust & Relevance Scores", value=True)
    
    if st.button("πŸš€ Find Articles"):
        if query.strip():
            with st.spinner("Searching arXiv..."):
                papers = retrieve_papers(query)
                if papers:
                    st.session_state.papers = papers
                    st.session_state.active_section = "articles"
                    st.success(f"Found {len(papers)} papers!")
                else:
                    st.error("No papers found. Try different keywords.")
        else:
            st.warning("Please enter a search query")

# Main Content
if 'papers' in st.session_state and st.session_state.papers:
    papers = st.session_state.papers

    st.header("πŸ“‘ Retrieved Papers")
    for idx, paper in enumerate(papers, 1):
        with st.expander(f"{idx}. {paper['title']}"):
            st.markdown(f"**Authors:** {', '.join(paper['authors'])}")
            st.markdown(f"**Published:** {paper['published']}")
            st.markdown(f"**Link:** [PDF]({paper['url']})")

            # Show Trust & Relevance Scores if enabled
            if show_scores:
                st.markdown(f"πŸ“Š **Citations:** {paper['citations']}")
                st.markdown(f"πŸ›‘οΈ **Trust Score:** {round(paper['trust_score'], 2)} / 10")
                st.markdown(f"πŸ” **Relevance Score:** {round(paper['relevance_score'], 2)} / 10")
                
                # External Links
                st.markdown(f"[πŸ”— Connected Papers]({paper['links']['Connected Papers']})")
                st.markdown(f"[πŸ“– Bibliographic Explorer]({paper['links']['Bibliographic Explorer']})")
                st.markdown(f"[πŸ“Š Litmaps]({paper['links']['Litmaps']})")

            # Display Summary
            st.markdown("**Abstract:**")
            st.write(paper['summary'])

st.caption("Built with ❀️ using AI")