Spaces:
Build error
Build error
Upload 9 files
Browse files- .gitattributes +1 -0
- Agentic AI/.cache/41/cache.db +3 -0
- Agentic AI/.env +1 -0
- Agentic AI/.gitignore +0 -0
- Agentic AI/__pycache__/agents.cpython-312.pyc +0 -0
- Agentic AI/__pycache__/data_loader.cpython-312.pyc +0 -0
- Agentic AI/agents.py +43 -0
- Agentic AI/app.py +66 -0
- Agentic AI/data_loader.py +67 -0
- Agentic AI/requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Agentic[[:space:]]AI/.cache/41/cache.db filter=lfs diff=lfs merge=lfs -text
|
Agentic AI/.cache/41/cache.db
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:282d19e371aba488bebb35f9272cb6fa758d0e50874892c6b559d46b205acc17
|
| 3 |
+
size 151552
|
Agentic AI/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
GROQ_API_KEY="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"
|
Agentic AI/.gitignore
ADDED
|
File without changes
|
Agentic AI/__pycache__/agents.cpython-312.pyc
ADDED
|
Binary file (2.69 kB). View file
|
|
|
Agentic AI/__pycache__/data_loader.cpython-312.pyc
ADDED
|
Binary file (3.78 kB). View file
|
|
|
Agentic AI/agents.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from autogen import AssistantAgent
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
|
| 5 |
+
# Load environment variables
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
class ResearchAgents:
|
| 9 |
+
def __init__(self, api_key):
|
| 10 |
+
self.groq_api_key = api_key
|
| 11 |
+
self.llm_config = {'config_list': [{'model': 'deepseek-r1-distill-qwen-32b', 'api_key': self.groq_api_key, 'api_type': "groq"}]}
|
| 12 |
+
|
| 13 |
+
# Summarizer Agent - Summarizes research papers
|
| 14 |
+
self.summarizer_agent = AssistantAgent(
|
| 15 |
+
name="summarizer_agent",
|
| 16 |
+
system_message="Summarize the retrieved research papers and present concise summaries to the user, JUST GIVE THE RELEVANT SUMMARIES OF THE RESEARCH PAPER AND NOT YOUR THOUGHT PROCESS.",
|
| 17 |
+
llm_config=self.llm_config,
|
| 18 |
+
human_input_mode="NEVER",
|
| 19 |
+
code_execution_config=False
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Advantages and Disadvantages Agent - Analyzes pros and cons
|
| 23 |
+
self.advantages_disadvantages_agent = AssistantAgent(
|
| 24 |
+
name="advantages_disadvantages_agent",
|
| 25 |
+
system_message="Analyze the summaries of the research papers and provide a list of advantages and disadvantages for each paper in a pointwise format. JUST GIVE THE ADVANTAGES AND DISADVANTAGES, NOT YOUR THOUGHT PROCESS",
|
| 26 |
+
llm_config=self.llm_config,
|
| 27 |
+
human_input_mode="NEVER",
|
| 28 |
+
code_execution_config=False
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
def summarize_paper(self, paper_summary):
|
| 32 |
+
"""Generates a summary of the research paper."""
|
| 33 |
+
summary_response = self.summarizer_agent.generate_reply(
|
| 34 |
+
messages=[{"role": "user", "content": f"Summarize this paper: {paper_summary}"}]
|
| 35 |
+
)
|
| 36 |
+
return summary_response.get("content", "Summarization failed!") if isinstance(summary_response, dict) else str(summary_response)
|
| 37 |
+
|
| 38 |
+
def analyze_advantages_disadvantages(self, summary):
|
| 39 |
+
"""Generates advantages and disadvantages of the research paper."""
|
| 40 |
+
adv_dis_response = self.advantages_disadvantages_agent.generate_reply(
|
| 41 |
+
messages=[{"role": "user", "content": f"Provide advantages and disadvantages for this paper: {summary}"}]
|
| 42 |
+
)
|
| 43 |
+
return adv_dis_response.get("content", "Advantages and disadvantages analysis failed!")
|
Agentic AI/app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from agents import ResearchAgents
|
| 5 |
+
from data_loader import DataLoader
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
print("ok")
|
| 10 |
+
|
| 11 |
+
# Streamlit UI Title
|
| 12 |
+
st.title("📚 Virtual Research Assistant")
|
| 13 |
+
|
| 14 |
+
# Retrieve the API key from environment variables
|
| 15 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 16 |
+
|
| 17 |
+
# Check if API key is set, else stop execution
|
| 18 |
+
if not groq_api_key:
|
| 19 |
+
st.error("GROQ_API_KEY is missing. Please set it in your environment variables.")
|
| 20 |
+
st.stop()
|
| 21 |
+
|
| 22 |
+
# Initialize AI Agents for summarization and analysis
|
| 23 |
+
agents = ResearchAgents(groq_api_key)
|
| 24 |
+
|
| 25 |
+
# Initialize DataLoader for fetching research papers
|
| 26 |
+
data_loader = DataLoader()
|
| 27 |
+
|
| 28 |
+
# Input field for the user to enter a research topic
|
| 29 |
+
query = st.text_input("Enter a research topic:")
|
| 30 |
+
|
| 31 |
+
# When the user clicks "Search"
|
| 32 |
+
if st.button("Search"):
|
| 33 |
+
with st.spinner("Fetching research papers..."): # Show a loading spinner
|
| 34 |
+
|
| 35 |
+
# Fetch research papers from ArXiv and Google Scholar
|
| 36 |
+
arxiv_papers = data_loader.fetch_arxiv_papers(query)
|
| 37 |
+
#google_scholar_papers = data_loader.fetch_google_scholar_papers(query)
|
| 38 |
+
#all_papers = arxiv_papers + google_scholar_papers # Combine results from both sources
|
| 39 |
+
all_papers = arxiv_papers
|
| 40 |
+
|
| 41 |
+
# If no papers are found, display an error message
|
| 42 |
+
if not all_papers:
|
| 43 |
+
st.error("Failed to fetch papers. Try again!")
|
| 44 |
+
else:
|
| 45 |
+
processed_papers = []
|
| 46 |
+
|
| 47 |
+
# Process each paper: generate summary and analyze advantages/disadvantages
|
| 48 |
+
for paper in all_papers:
|
| 49 |
+
summary = agents.summarize_paper(paper['summary']) # Generate summary
|
| 50 |
+
adv_dis = agents.analyze_advantages_disadvantages(summary) # Analyze pros/cons
|
| 51 |
+
|
| 52 |
+
processed_papers.append({
|
| 53 |
+
"title": paper["title"],
|
| 54 |
+
"link": paper["link"],
|
| 55 |
+
"summary": summary,
|
| 56 |
+
"advantages_disadvantages": adv_dis,
|
| 57 |
+
})
|
| 58 |
+
|
| 59 |
+
# Display the processed research papers
|
| 60 |
+
st.subheader("Top Research Papers:")
|
| 61 |
+
for i, paper in enumerate(processed_papers, 1):
|
| 62 |
+
st.markdown(f"### {i}. {paper['title']}") # Paper title
|
| 63 |
+
st.markdown(f"🔗 [Read Paper]({paper['link']})") # Paper link
|
| 64 |
+
st.write(f"**Summary:** {paper['summary']}") # Paper summary
|
| 65 |
+
st.write(f"{paper['advantages_disadvantages']}") # Pros/cons analysis
|
| 66 |
+
st.markdown("---") # Separator between papers
|
Agentic AI/data_loader.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import xml.etree.ElementTree as ET
|
| 3 |
+
from scholarly import scholarly
|
| 4 |
+
|
| 5 |
+
class DataLoader:
|
| 6 |
+
def __init__(self):
|
| 7 |
+
print("DataLoader Init")
|
| 8 |
+
def fetch_arxiv_papers(self, query):
|
| 9 |
+
"""
|
| 10 |
+
Fetches top 5 research papers from ArXiv based on the user query.
|
| 11 |
+
If <5 papers are found, expands the search using related topics.
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
list: A list of dictionaries containing paper details (title, summary, link).
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
def search_arxiv(query):
|
| 18 |
+
"""Helper function to query ArXiv API."""
|
| 19 |
+
url = f"http://export.arxiv.org/api/query?search_query=all:{query}&start=0&max_results=5"
|
| 20 |
+
response = requests.get(url)
|
| 21 |
+
if response.status_code == 200:
|
| 22 |
+
root = ET.fromstring(response.text)
|
| 23 |
+
return [
|
| 24 |
+
{
|
| 25 |
+
"title": entry.find("{http://www.w3.org/2005/Atom}title").text,
|
| 26 |
+
"summary": entry.find("{http://www.w3.org/2005/Atom}summary").text,
|
| 27 |
+
"link": entry.find("{http://www.w3.org/2005/Atom}id").text
|
| 28 |
+
}
|
| 29 |
+
for entry in root.findall("{http://www.w3.org/2005/Atom}entry")
|
| 30 |
+
]
|
| 31 |
+
return []
|
| 32 |
+
|
| 33 |
+
papers = search_arxiv(query)
|
| 34 |
+
|
| 35 |
+
if len(papers) < 5 and self.search_agent: # If fewer than 5 papers, expand search
|
| 36 |
+
related_topics_response = self.search_agent.generate_reply(
|
| 37 |
+
messages=[{"role": "user", "content": f"Suggest 3 related research topics for '{query}'"}]
|
| 38 |
+
)
|
| 39 |
+
related_topics = related_topics_response.get("content", "").split("\n")
|
| 40 |
+
|
| 41 |
+
for topic in related_topics:
|
| 42 |
+
topic = topic.strip()
|
| 43 |
+
if topic and len(papers) < 5:
|
| 44 |
+
new_papers = search_arxiv(topic)
|
| 45 |
+
papers.extend(new_papers)
|
| 46 |
+
papers = papers[:5] # Ensure max 5 papers
|
| 47 |
+
|
| 48 |
+
return papers
|
| 49 |
+
|
| 50 |
+
def fetch_google_scholar_papers(self, query):
|
| 51 |
+
"""
|
| 52 |
+
Fetches top 5 research papers from Google Scholar.
|
| 53 |
+
Returns:
|
| 54 |
+
list: A list of dictionaries containing paper details (title, summary, link)
|
| 55 |
+
"""
|
| 56 |
+
papers = []
|
| 57 |
+
search_results = scholarly.search_pubs(query)
|
| 58 |
+
|
| 59 |
+
for i, paper in enumerate(search_results):
|
| 60 |
+
if i >= 5:
|
| 61 |
+
break
|
| 62 |
+
papers.append({
|
| 63 |
+
"title": paper["bib"]["title"],
|
| 64 |
+
"summary": paper["bib"].get("abstract", "No summary available"),
|
| 65 |
+
"link": paper.get("pub_url", "No link available")
|
| 66 |
+
})
|
| 67 |
+
return papers
|
Agentic AI/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
autogen
|
| 2 |
+
scholarly
|
| 3 |
+
python-dotenv
|
| 4 |
+
streamlit
|
| 5 |
+
streamlit-chat
|