File size: 4,505 Bytes
b4c04de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from dotenv import load_dotenv
from agents import ResearchAgents
from data_loader import DataLoader

load_dotenv()

# Move set_page_config() to be the first Streamlit command.
st.set_page_config(
    page_title="Autogen Agent",
    page_icon="⚑",
    initial_sidebar_state="expanded"
)

# --- Added Custom CSS for a Professional Look ---
custom_css = """
<style>
    body {
        background-color: #f5f5f5;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }
    .css-18e3th9, .css-1d391kg {  /* Streamlit title and header adjustments */
        color: #333333;
    }
    .stButton>button {
        background-color: #4a90e2;
        color: #ffffff;
        border-radius: 5px;
        border: none;
    }
    .sidebar .sidebar-content {
        background-color: #ffffff;
    }
    .stMarkdown, .css-1d391kg {
        color: #555555;
    }
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)

# Streamlit UI Title
st.title("πŸ“š Virtual Research Assistant")

num_results = 5
source_choice = st.sidebar.multiselect("Select Data Sources", options=["ArXiv", "Google Scholar"], default=["ArXiv"])
# Sidebar with features and footer
with st.sidebar:
    st.divider()
    st.markdown("<h3 style='text-align: center; color: #333;'>Key Features</h3>", unsafe_allow_html=True)
    st.markdown("""
    <ul style='list-style: none; padding: 0;'>
        <li style='margin-bottom: 8px;'>πŸ” <strong>Multi-Source Research Retrieval</strong></li>
        <li style='margin-bottom: 8px;'>πŸ€– <strong>Integrated Chatbot Interaction</strong></li>
        <li style='margin-bottom: 8px;'>✨ <strong>Advanced Summarization</strong></li>
        <li style='margin-bottom: 8px;'>πŸ”„ <strong>Automatic Query Expansion & Refinement</strong></li>
        <li style='margin-bottom: 8px;'>πŸ“Š <strong>Visual Data Presentation</strong></li>
    </ul>
    """, unsafe_allow_html=True)
    st.divider()
    st.markdown("<p style='text-align: center;'><em>Built with Groq | Autogen</em></p>", unsafe_allow_html=True)

# Retrieve the API key from environment variables
groq_api_key = os.getenv("GROQ_API_KEY")

# Check if API key is set, else stop execution
if not groq_api_key:
    st.error("GROQ_API_KEY is missing. Please set it in your environment variables.")
    st.stop()

# Initialize AI Agents for summarization and analysis
agents = ResearchAgents(groq_api_key)

# Initialize DataLoader for fetching research papers
data_loader = DataLoader()

# Use chat_input instead of text_input for entering the research topic.
query = st.chat_input("Enter a research topic:")

# Trigger the search automatically if a query is provided.
if query:
    with st.spinner("Fetching research papers..."):  # Show a loading spinner
        
        all_papers = []
        # Fetch from selected sources based on sidebar choices
        if "ArXiv" in source_choice:
            arxiv_papers = data_loader.fetch_arxiv_papers(query, limit=num_results)
            all_papers.extend(arxiv_papers)
        if "Google Scholar" in source_choice:
            google_scholar_papers = data_loader.fetch_google_scholar_papers(query)
            all_papers.extend(google_scholar_papers)

        # If no papers are found, display an error message
        if not all_papers:
            st.error("Failed to fetch papers. Try again!")
        else:
            processed_papers = []

            # Process each paper: generate summary and analyze advantages/disadvantages
            for paper in all_papers:
                summary = agents.summarize_paper(paper['summary'])  # Generate summary
                adv_dis = agents.analyze_advantages_disadvantages(summary)  # Analyze pros/cons

                processed_papers.append({
                    "title": paper["title"],
                    "link": paper["link"],
                    "summary": summary,
                    "advantages_disadvantages": adv_dis,
                })

            # Display the processed research papers
            st.subheader("Top Research Papers:")
            for i, paper in enumerate(processed_papers, 1):
                st.markdown(f"### {i}. {paper['title']}")  # Paper title
                st.markdown(f"πŸ”— [Read Paper]({paper['link']})")  # Paper link
                st.write(f"**Summary:** {paper['summary']}")  # Paper summary
                st.write(f"{paper['advantages_disadvantages']}")  # Pros/cons analysis
                st.markdown("---")  # Separator between papers