Spaces:
Sleeping
Sleeping
File size: 4,293 Bytes
fbec6c3 a263aa6 d6c42b6 7f6ef04 d6c42b6 7f6ef04 d6c42b6 fbec6c3 7f6ef04 fbec6c3 d6c42b6 0623585 7f6ef04 0623585 d6c42b6 7f6ef04 d6c42b6 7f6ef04 0623585 7f6ef04 0623585 fbec6c3 7f6ef04 fbec6c3 0623585 7f6ef04 fbec6c3 7f6ef04 a263aa6 7f6ef04 a263aa6 7f6ef04 fbec6c3 7f6ef04 fbec6c3 7f6ef04 0623585 7f6ef04 0623585 7f6ef04 0623585 7f6ef04 a263aa6 7f6ef04 a263aa6 0623585 7f6ef04 d6c42b6 7f6ef04 0623585 d6c42b6 7f6ef04 1220468 7f6ef04 |
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 |
import os
import streamlit as st
import arxiv
import random
import datetime
from groq import Groq
# -------------------------------
# API Clients
# -------------------------------
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
# -------------------------------
# Helper Functions
# -------------------------------
def groq_summarize(text: str) -> str:
response = client.chat.completions.create(
messages=[{"role": "user", "content": f"Summarize in 250 characters:
{text}"}],
model="llama-3.3-70b-versatile",
)
return response.choices[0].message.content.strip()
def groq_eli5(text: str) -> str:
response = client.chat.completions.create(
messages=[{"role": "user", "content": f"Explain like I'm 5:
{text}"}],
model="llama-3.3-70b-versatile",
)
return response.choices[0].message.content.strip()
def calculate_trust_relevance(paper_title):
random.seed(hash(paper_title))
return random.randint(60, 95), random.randint(50, 90)
def retrieve_papers(query, max_results=5):
search = arxiv.Search(query=query, max_results=max_results)
papers = []
for result in search.results():
trust, relevance = calculate_trust_relevance(result.title)
paper_id = result.entry_id.split('/')[-1]
paper = {
"title": result.title,
"summary": result.summary,
"url": result.pdf_url,
"authors": [author.name for author in result.authors],
"published": result.published.strftime('%Y-%m-%d') if isinstance(result.published, datetime.datetime) else "n.d.",
"doi": f"https://doi.org/10.48550/arXiv.{paper_id}",
"bib_explorer": f"https://arxiv.org/abs/{paper_id}",
"litmaps": f"https://app.litmaps.com/preview/{paper_id}",
"trust_score": trust,
"relevance_score": relevance
}
papers.append(paper)
return papers
def get_random_papers():
sample_topics = ["AI ethics", "Quantum computing", "Neuroscience", "Robotics", "Renewable energy", "Space exploration"]
query = random.choice(sample_topics)
return retrieve_papers(query, random.randint(5, 15))
# -------------------------------
# Streamlit UI
# -------------------------------
st.title("π PaperPilot β Intelligent Research Navigator")
# Sidebar Controls
with st.sidebar:
st.header("π Search or Discover")
query = st.text_input("Search topic:")
if st.button("π Find Articles"):
if query.strip():
with st.spinner("Searching arXiv..."):
st.session_state.papers = retrieve_papers(query)
st.success(f"Found {len(st.session_state.papers)} papers!")
else:
st.warning("Please enter a search query")
if st.button("π² Random Papers"):
with st.spinner("Fetching random papers..."):
st.session_state.papers = get_random_papers()
st.success(f"Found {len(st.session_state.papers)} random papers!")
if "papers" in st.session_state and st.session_state.papers:
st.header("π Research Feed")
for paper in st.session_state.papers:
with st.expander(f"π {paper['title']}"):
st.markdown(f"**Authors:** {', '.join(paper['authors'])}")
st.markdown(f"**Published:** {paper['published']}")
st.markdown(f"**[PDF Link]({paper['url']})** | **[DOI]({paper['doi']})** | **[Bibliographic Explorer]({paper['bib_explorer']})** | **[Litmaps]({paper['litmaps']})**")
with st.spinner("Summarizing..."):
summary = groq_summarize(paper['summary'])
st.markdown(f"**Summary:** {summary}")
if st.button(f"Explain like I'm 5 π§Έ - {paper['title']}"):
with st.spinner("Simplifying..."):
st.write(groq_eli5(paper['summary']))
st.markdown("**Trust & Relevance Scores:**")
st.progress(paper['trust_score'] / 100)
st.caption(f"πΉ Trust Score: {paper['trust_score']}%")
st.progress(paper['relevance_score'] / 100)
st.caption(f"πΉ Relevance Score: {paper['relevance_score']}%")
else:
st.info("Enter a query or use the π² Random Papers button to get started!")
|