Upload 6 files
Browse files- Agents/__pycache__/multi_agent.cpython-310.pyc +0 -0
- Agents/multi_agent.py +43 -0
- app.py +47 -0
- data_loaders.py +67 -0
- requirements.txt +10 -0
- setup.py +24 -0
Agents/__pycache__/multi_agent.cpython-310.pyc
ADDED
|
Binary file (2.18 kB). View file
|
|
|
Agents/multi_agent.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from autogen import AssistantAgent
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
load_dotenv()
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 9 |
+
os.environ['GROQ_API_KEY'] = GROQ_API_KEY
|
| 10 |
+
|
| 11 |
+
class ResearchAgents:
|
| 12 |
+
def __init__(self, api_key):
|
| 13 |
+
self.groq_api_key = api_key
|
| 14 |
+
self.llm_config = {'config_list': [{'model': 'llama-3.3-70b-versatile', 'api_key': self.groq_api_key, 'api_type': "groq"}]}
|
| 15 |
+
|
| 16 |
+
self.summarizer_agent = AssistantAgent(
|
| 17 |
+
name="summarizer_agent",
|
| 18 |
+
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.",
|
| 19 |
+
llm_config=self.llm_config,
|
| 20 |
+
human_input_mode="NEVER",
|
| 21 |
+
code_execution_config=False
|
| 22 |
+
)
|
| 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!")
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from Agents.multi_agent import ResearchAgents
|
| 5 |
+
from data_loaders import DataLoader
|
| 6 |
+
|
| 7 |
+
load_dotenv()
|
| 8 |
+
|
| 9 |
+
st.title("📚 Virtual Research Assistant")
|
| 10 |
+
|
| 11 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 12 |
+
if not groq_api_key:
|
| 13 |
+
st.error("GROQ_API_KEY is missing. Please set it in your environment variables.")
|
| 14 |
+
st.stop()
|
| 15 |
+
|
| 16 |
+
agents = ResearchAgents(groq_api_key)
|
| 17 |
+
data_loader = DataLoader()
|
| 18 |
+
|
| 19 |
+
query = st.text_input("Enter a research topic:")
|
| 20 |
+
|
| 21 |
+
if st.button("Search"):
|
| 22 |
+
with st.spinner("Fetching research papers..."):
|
| 23 |
+
arxiv_papers = data_loader.fetch_arxiv_papers(query)
|
| 24 |
+
all_papers = arxiv_papers
|
| 25 |
+
|
| 26 |
+
if not all_papers:
|
| 27 |
+
st.error("Failed to fetch papers. Try again!")
|
| 28 |
+
else:
|
| 29 |
+
processed_papers = []
|
| 30 |
+
|
| 31 |
+
for paper in all_papers:
|
| 32 |
+
summary = agents.summarize_paper(paper['summary'])
|
| 33 |
+
adv_dis = agents.analyze_advantages_disadvantages(summary)
|
| 34 |
+
|
| 35 |
+
processed_papers.append({
|
| 36 |
+
"title": paper["title"],
|
| 37 |
+
"link": paper["link"],
|
| 38 |
+
"summary": summary,
|
| 39 |
+
"advantages_disadvantages": adv_dis,
|
| 40 |
+
})
|
| 41 |
+
st.subheader("Top Research Papers:")
|
| 42 |
+
for i, paper in enumerate(processed_papers, 1):
|
| 43 |
+
st.markdown(f"### {i}. {paper['title']}")
|
| 44 |
+
st.markdown(f"🔗 [Read Paper]({paper['link']})")
|
| 45 |
+
st.write(f"**Summary:** {paper['summary']}")
|
| 46 |
+
st.write(f"{paper['advantages_disadvantages']}")
|
| 47 |
+
st.markdown("---")
|
data_loaders.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:
|
| 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]
|
| 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
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain-community
|
| 2 |
+
langchain-core
|
| 3 |
+
streamlit
|
| 4 |
+
langchain
|
| 5 |
+
python-dotenv
|
| 6 |
+
langchain_groq
|
| 7 |
+
transformers
|
| 8 |
+
scholarly
|
| 9 |
+
autogen
|
| 10 |
+
-e .
|
setup.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from setuptools import find_packages, setup
|
| 2 |
+
from typing import List
|
| 3 |
+
def get_requirements() -> List[str]:
|
| 4 |
+
try:
|
| 5 |
+
with open('requirements.txt', 'r') as file:
|
| 6 |
+
requirement_list = [
|
| 7 |
+
line.strip() for line in file.readlines()
|
| 8 |
+
if line.strip() and line.strip() != '-e .'
|
| 9 |
+
]
|
| 10 |
+
return requirement_list
|
| 11 |
+
except FileNotFoundError:
|
| 12 |
+
print("requirements.txt file not found. Make sure it exists!")
|
| 13 |
+
return []
|
| 14 |
+
|
| 15 |
+
setup(
|
| 16 |
+
name="Virtual_Research_Assistant",
|
| 17 |
+
version="0.0.1",
|
| 18 |
+
author="Parthib Karak",
|
| 19 |
+
description="A virtual research assistant that fetches and summarizes research papers.",
|
| 20 |
+
author_email="[email protected]",
|
| 21 |
+
packages=find_packages(),
|
| 22 |
+
install_requires=get_requirements(),
|
| 23 |
+
python_requires=">=3.10",
|
| 24 |
+
)
|