Spaces:
Sleeping
Sleeping
Upload 4 files
Browse filesInitial commit from C:\Users\jfhmb\AI FOR SCIENCE\AI Researcher Pro\AI_Researcher
- README.md +79 -11
- main.py +178 -0
- prompts.py +41 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,13 +1,81 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
|
2 |
+
# AI Researcher Pro - Your Research Companion
|
3 |
+
|
4 |
+
AI Researcher Pro is an AI-powered research assistant designed to streamline your research workflow. The app uses Groq API for intelligent research assistance and Google Scholar to retrieve relevant papers based on user queries. The tool helps researchers ask domain-specific questions and get AI-driven answers, along with recommended papers from the research community.
|
5 |
+
|
6 |
+
## Features
|
7 |
+
- **AI-Powered Research**: Ask research questions in specific domains like Computer Science, Medical, Engineering, and more.
|
8 |
+
- **Research Paper Suggestions**: Get suggested papers directly from Google Scholar based on your question and selected sub-fields.
|
9 |
+
- **Customizable Fields**: Choose from multiple research domains and their respective sub-fields to narrow down your research.
|
10 |
+
- **Interactive User Interface**: User-friendly interface with enhanced styling and tooltips for better user experience.
|
11 |
+
- **Secure API Handling**: Uses `st.secrets` to securely handle API keys, making the app ready for hackathon environments.
|
12 |
+
|
13 |
+
## Tech Stack
|
14 |
+
- **Streamlit**: For creating the interactive web interface.
|
15 |
+
- **Groq API**: To generate AI-powered research responses.
|
16 |
+
- **Google Scholar**: For fetching research papers based on the query.
|
17 |
+
- **Python**: Core language used for application development.
|
18 |
+
- **st.secrets**: Used for secure environment variable management.
|
19 |
+
|
20 |
+
## Installation
|
21 |
+
|
22 |
+
1. **Clone the Repository**
|
23 |
+
```bash
|
24 |
+
git clone https://github.com/yourusername/ai-researcher-pro.git
|
25 |
+
cd ai-researcher-pro
|
26 |
+
```
|
27 |
+
|
28 |
+
2. **Set Up Environment Variables**
|
29 |
+
- Create a `secrets.toml` file in the `.streamlit` directory (if it doesn't exist):
|
30 |
+
```bash
|
31 |
+
mkdir -p .streamlit
|
32 |
+
nano .streamlit/secrets.toml
|
33 |
+
```
|
34 |
+
- Add your Groq API key in the `secrets.toml` file:
|
35 |
+
```toml
|
36 |
+
[general]
|
37 |
+
GROQ_API_KEY = "your-groq-api-key-here"
|
38 |
+
```
|
39 |
+
|
40 |
+
3. **Install Dependencies**
|
41 |
+
Use `pip` to install the required dependencies:
|
42 |
+
```bash
|
43 |
+
pip install -r requirements.txt
|
44 |
+
```
|
45 |
+
|
46 |
+
4. **Run the Application**
|
47 |
+
Start the Streamlit app by running the following command:
|
48 |
+
```bash
|
49 |
+
streamlit run app.py
|
50 |
+
```
|
51 |
+
|
52 |
+
## Usage
|
53 |
+
|
54 |
+
1. **Select a Research Field**: Choose a broad research field from the sidebar (e.g., Computer Science, Medical, Engineering, etc.).
|
55 |
+
2. **Select Sub-fields**: Based on the chosen research field, you can select specific sub-fields like AI, Data Science, Quantum Mechanics, and more.
|
56 |
+
3. **Enter Research Question**: Type a clear, research-related question in the provided text box.
|
57 |
+
4. **Submit**: Click the **Submit** button to get AI-generated answers and suggested research papers.
|
58 |
+
5. **View Results**: Check the AI response in the **AI Response** tab and view suggested research papers in the **Suggested Papers** tab.
|
59 |
+
|
60 |
+
## Example Queries
|
61 |
+
- "What are the latest trends in Machine Learning?"
|
62 |
+
- "How to improve model accuracy in Natural Language Processing?"
|
63 |
+
- "Current advancements in Quantum Mechanics?"
|
64 |
+
|
65 |
+
The app will return a tailored response based on your query and the sub-fields selected.
|
66 |
+
|
67 |
+
## Troubleshooting
|
68 |
+
|
69 |
+
- **No Internet Connection**: If the app shows a "No internet connection" error, ensure your device is connected to the internet.
|
70 |
+
- **Missing API Key**: If you encounter an error related to the API key, double-check your `secrets.toml` file for the correct `GROQ_API_KEY`.
|
71 |
+
|
72 |
+
## Contribution
|
73 |
+
|
74 |
+
Feel free to fork this project and submit a pull request if you'd like to contribute. You can also open an issue if you find bugs or have feature requests.
|
75 |
+
|
76 |
+
## License
|
77 |
+
|
78 |
+
This project is licensed under the [LICENSE](LICENSE).
|
79 |
+
|
80 |
---
|
81 |
|
|
main.py
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import socket
|
5 |
+
from groq import Groq
|
6 |
+
from scholarly import scholarly
|
7 |
+
from prompts import get_research_prompt, get_guidance_prompt, invalid_question_prompt
|
8 |
+
|
9 |
+
# Load environment variables from (.env) file
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Set up Groq client using st.secrets for secure API key handling
|
13 |
+
api_key = st.secrets["GROQ_API_KEY"]
|
14 |
+
if not api_key:
|
15 |
+
st.error("GROQ_API_KEY not found. Please check your environment variables.")
|
16 |
+
else:
|
17 |
+
client = Groq(api_key=api_key)
|
18 |
+
|
19 |
+
# Function to check internet connection
|
20 |
+
def is_connected():
|
21 |
+
try:
|
22 |
+
socket.create_connection(("www.google.com", 80))
|
23 |
+
return True
|
24 |
+
except OSError:
|
25 |
+
return False
|
26 |
+
|
27 |
+
# Streamlit UI Enhancements
|
28 |
+
st.set_page_config(page_title="AI Researcher Pro - Your Research Companion", layout="wide")
|
29 |
+
|
30 |
+
# Custom CSS for styling
|
31 |
+
st.markdown("""
|
32 |
+
<style>
|
33 |
+
body {
|
34 |
+
font-family: 'Arial', sans-serif;
|
35 |
+
}
|
36 |
+
.stButton button {
|
37 |
+
border-radius: 10px;
|
38 |
+
padding: 10px 20px;
|
39 |
+
}
|
40 |
+
|
41 |
+
.big-title {
|
42 |
+
font-size: 80px;
|
43 |
+
font-weight: bold;
|
44 |
+
color: #d84df1;
|
45 |
+
text-align: center;
|
46 |
+
background: linear-gradient(90deg, #4285f4, #ea4335, #fbbc05, #34a853);
|
47 |
+
-webkit-background-clip: text;
|
48 |
+
-webkit-text-fill-color: transparent;
|
49 |
+
}
|
50 |
+
.subtitle-style {
|
51 |
+
font-size: 18px;
|
52 |
+
text-align: center;
|
53 |
+
margin-bottom: 20px;
|
54 |
+
}
|
55 |
+
.tooltip {
|
56 |
+
color: gray;
|
57 |
+
font-style: italic;
|
58 |
+
font-size: 14px;
|
59 |
+
}
|
60 |
+
.sidebar-title {
|
61 |
+
font-size: 18px;
|
62 |
+
font-weight: bold;
|
63 |
+
color: #c24838;
|
64 |
+
margin-bottom: 10px;
|
65 |
+
}
|
66 |
+
.research-field {
|
67 |
+
font-weight: bold;
|
68 |
+
color: #c24838;
|
69 |
+
font-size: 14px;
|
70 |
+
}
|
71 |
+
</style>
|
72 |
+
""", unsafe_allow_html=True)
|
73 |
+
|
74 |
+
# Title and subtitle with custom styling
|
75 |
+
st.markdown("<h1 class='big-title'>AI Researcher Pro</h1>", unsafe_allow_html=True)
|
76 |
+
st.markdown("<p class='subtitle-style'>Your AI-powered research assistant for all your research needs!</p>", unsafe_allow_html=True)
|
77 |
+
|
78 |
+
# Adding a tooltip with enhanced styling
|
79 |
+
st.markdown("""
|
80 |
+
<p class='tooltip'>Tip: Ask specific research questions like "What are the latest trends in AI?" or "How to improve model accuracy in NLP?"</p>
|
81 |
+
""", unsafe_allow_html=True)
|
82 |
+
|
83 |
+
# Connectivity Check
|
84 |
+
if not is_connected():
|
85 |
+
st.error("⚠️ No internet connection. Please check your internet and try again.")
|
86 |
+
st.stop()
|
87 |
+
|
88 |
+
# Define fields and their respective sub-fields
|
89 |
+
fields_dict = {
|
90 |
+
"Computer Science": ["Artificial Intelligence", "Machine Learning", "Data Science", "Computer Vision", "Natural Language Processing"],
|
91 |
+
"Medical": ["Biotechnology", "Genetics", "Neuroscience", "Immunology", "Medical Imaging"],
|
92 |
+
"Physics": ["Quantum Mechanics", "Astrophysics", "Nuclear Physics", "Condensed Matter Physics", "Particle Physics"],
|
93 |
+
"Chemistry": ["Organic Chemistry", "Inorganic Chemistry", "Biochemistry", "Physical Chemistry", "Analytical Chemistry"],
|
94 |
+
"Engineering": ["Electrical Engineering", "Mechanical Engineering", "Civil Engineering", "Aerospace Engineering", "Biomedical Engineering"]
|
95 |
+
}
|
96 |
+
|
97 |
+
# Sidebar for selecting broad research fields
|
98 |
+
st.sidebar.markdown("<div class='sidebar-title'>Select a Broad Research Field</div>", unsafe_allow_html=True)
|
99 |
+
broad_field = st.sidebar.selectbox("Research Field", list(fields_dict.keys()))
|
100 |
+
|
101 |
+
# Show relevant sub-fields based on the broad field selected
|
102 |
+
st.sidebar.markdown(f"<div class='sidebar-title'>Select Sub-fields in {broad_field}</div>", unsafe_allow_html=True)
|
103 |
+
selected_subfields = []
|
104 |
+
for subfield in fields_dict[broad_field]:
|
105 |
+
if st.sidebar.checkbox(f"🔍 {subfield}", key=subfield):
|
106 |
+
selected_subfields.append(subfield)
|
107 |
+
|
108 |
+
# User input in the main layout
|
109 |
+
st.markdown("<div class='research-field'>Research Question</div>", unsafe_allow_html=True)
|
110 |
+
research_question = st.text_input("", "", help="Enter a clear research-related question")
|
111 |
+
|
112 |
+
# Function to get research papers from Google Scholar
|
113 |
+
def get_research_papers_from_scholar(topic, fields):
|
114 |
+
papers = []
|
115 |
+
for field in fields:
|
116 |
+
search_query = scholarly.search_pubs(f"{topic} {field}")
|
117 |
+
for i in range(5): # Get top 5 results for each field
|
118 |
+
try:
|
119 |
+
paper = next(search_query)
|
120 |
+
title = paper['bib']['title']
|
121 |
+
abstract = paper.get('bib', {}).get('abstract', "No abstract available")
|
122 |
+
url = paper.get('pub_url', "No URL available")
|
123 |
+
papers.append({
|
124 |
+
"title": title,
|
125 |
+
"abstract": abstract,
|
126 |
+
"url": url,
|
127 |
+
"field": field
|
128 |
+
})
|
129 |
+
except StopIteration:
|
130 |
+
break
|
131 |
+
return papers
|
132 |
+
|
133 |
+
# Function to simulate AI researcher's response
|
134 |
+
def get_researcher_response(question, fields):
|
135 |
+
subfields = ", ".join(fields)
|
136 |
+
chat_completion = client.chat.completions.create(
|
137 |
+
messages=[get_research_prompt(question, subfields)],
|
138 |
+
model="llama3-groq-70b-8192-tool-use-preview",
|
139 |
+
)
|
140 |
+
answer = chat_completion.choices[0].message.content
|
141 |
+
|
142 |
+
if "non-research" in answer.lower():
|
143 |
+
return invalid_question_prompt(), None
|
144 |
+
|
145 |
+
guidance = get_guidance_prompt(question, subfields)
|
146 |
+
|
147 |
+
return answer, guidance
|
148 |
+
|
149 |
+
# Submit button with enhanced styling
|
150 |
+
if st.button("Submit"):
|
151 |
+
if research_question and selected_subfields:
|
152 |
+
with st.spinner(f"Researching your question in {', '.join(selected_subfields)}..."):
|
153 |
+
answer, guidance = get_researcher_response(research_question, selected_subfields)
|
154 |
+
|
155 |
+
if guidance:
|
156 |
+
# Use Tabs with icons for better organization
|
157 |
+
tab1, tab2 = st.tabs([f"🤖 AI Response", f"📄 Suggested Papers"])
|
158 |
+
|
159 |
+
with tab1:
|
160 |
+
st.write("### Researcher's Answer:")
|
161 |
+
st.write(answer)
|
162 |
+
st.write("### Researcher's Guidance:")
|
163 |
+
st.write(guidance)
|
164 |
+
|
165 |
+
with tab2:
|
166 |
+
st.write("### Suggested Research Papers:")
|
167 |
+
scholar_papers = get_research_papers_from_scholar(research_question, selected_subfields)
|
168 |
+
if scholar_papers:
|
169 |
+
for i, paper in enumerate(scholar_papers):
|
170 |
+
with st.expander(f"📄 Paper {i+1}: {paper['title']} ({paper['field']})"):
|
171 |
+
st.write(f"**Abstract**: {paper['abstract']}")
|
172 |
+
st.write(f"[Read Full Paper]({paper['url']})")
|
173 |
+
else:
|
174 |
+
st.info("No papers found, try a different query.")
|
175 |
+
else:
|
176 |
+
st.warning(answer)
|
177 |
+
else:
|
178 |
+
st.warning("Please enter a research question and select at least one sub-field before submitting.")
|
prompts.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# prompts.py
|
2 |
+
|
3 |
+
def get_research_prompt(question, field):
|
4 |
+
return {
|
5 |
+
"role": "user",
|
6 |
+
"content": f"""
|
7 |
+
The user is asking a research-related question in the field of '{field}'. Please provide a comprehensive answer to the question '{question}'.
|
8 |
+
|
9 |
+
Additionally, include the following guidance:
|
10 |
+
- A suggested approach to perform a literature review.
|
11 |
+
- Potential open challenges or unresolved questions in this field.
|
12 |
+
- The most suitable methods or frameworks to address the research problem.
|
13 |
+
- Peer-reviewed sources or journals to consult.
|
14 |
+
- Next steps to further explore the topic, including objectives, methodology, and potential tools or datasets.
|
15 |
+
|
16 |
+
Make sure the response is structured and concise.
|
17 |
+
"""
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def get_guidance_prompt(question, field):
|
23 |
+
return f"""
|
24 |
+
Here’s a suggested approach to explore the research question '{question}' in the field of '{field}':
|
25 |
+
|
26 |
+
- **Literature Review**: Start by identifying key papers, influential researchers, and recent advancements in the field.
|
27 |
+
- **Open Challenges**: Look for gaps or unresolved questions in existing research that align with your query.
|
28 |
+
- **Peer-Reviewed Sources**: Focus on gathering peer-reviewed papers, conference publications, and reputable journals.
|
29 |
+
- **Approach and Methods**: Consider the most suitable experimental methods or theoretical frameworks to address the research problem.
|
30 |
+
- **Next Steps**: Define a research plan, including objectives, methodology, and potential datasets or tools.
|
31 |
+
|
32 |
+
This structured approach will guide you in navigating and contributing to the existing body of knowledge.
|
33 |
+
"""
|
34 |
+
|
35 |
+
|
36 |
+
def invalid_question_prompt():
|
37 |
+
return """
|
38 |
+
This question doesn't appear to be research-related. Please ask questions that align with research topics
|
39 |
+
such as theories, methodologies, or advancements in the field. You could ask about current trends,
|
40 |
+
innovations, or key challenges in research fields like AI or Data Science.
|
41 |
+
"""
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
python-dotenv
|
3 |
+
groq
|
4 |
+
scholarly
|