Spaces:
Sleeping
Sleeping
Commit
Β·
1cc5a1d
1
Parent(s):
e954dc8
alpha version 1.0
Browse files- .gitignore +1 -0
- app.py +131 -130
- src/research_agent/crew.py +4 -30
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
app.py
CHANGED
@@ -3,148 +3,149 @@ import sys
|
|
3 |
import streamlit as st
|
4 |
from src.research_agent.crew import MarketUseCaseCrew
|
5 |
import streamlit as st
|
6 |
-
from crewai import Crew, Process
|
7 |
import os
|
|
|
|
|
8 |
sys.path.append('..')
|
9 |
-
# Configure the Streamlit page
|
10 |
-
st.set_page_config(page_title="CrewAI Article Generator", page_icon="π", layout="wide")
|
11 |
|
12 |
-
# Custom CSS for styling the page
|
13 |
-
st.markdown("""
|
14 |
-
<style>
|
15 |
-
.reportview-container {
|
16 |
-
background: #f0f2f6
|
17 |
-
}
|
18 |
-
.main {
|
19 |
-
background: #00000;
|
20 |
-
padding: 3rem;
|
21 |
-
border-radius: 10px;
|
22 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
23 |
-
}
|
24 |
-
.stButton>button {
|
25 |
-
background-color: #0000;
|
26 |
-
color: white;
|
27 |
-
border-radius: 5px;
|
28 |
-
}
|
29 |
-
.stTextInput>div>div>input {
|
30 |
-
border-radius: 5px;
|
31 |
-
}
|
32 |
-
.sidebar .sidebar-content {
|
33 |
-
background-color: #f8f9fa;
|
34 |
-
}
|
35 |
-
</style>
|
36 |
-
""", unsafe_allow_html=True)
|
37 |
|
38 |
-
# Sidebar for API key input
|
39 |
-
st.sidebar.title("π API Configuration")
|
40 |
-
st.sidebar.markdown("Enter your API keys below:")
|
41 |
|
42 |
-
|
43 |
-
serper_api_key = st.sidebar.text_input("Serper API Key", type="password")
|
44 |
-
gemini_api_key = st.sidebar.text_input("Gemini Flash API Key", type="password")
|
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 |
-
progress_bar.progress(50)
|
90 |
-
# Call the kickoff method to generate the article
|
91 |
-
result = MarketUseCaseCrew().crew().kickoff(inputs=inputs)
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
else:
|
104 |
-
st.session_state.article_text = str(result)
|
105 |
-
|
106 |
-
# Display the article text
|
107 |
-
st.markdown(st.session_state.article_text)
|
108 |
|
109 |
-
#
|
110 |
-
|
|
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
-
|
|
|
150 |
|
|
|
|
|
|
3 |
import streamlit as st
|
4 |
from src.research_agent.crew import MarketUseCaseCrew
|
5 |
import streamlit as st
|
|
|
6 |
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
load_dotenv()
|
9 |
sys.path.append('..')
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
+
class MarketUseCaseGen:
|
|
|
|
|
14 |
|
15 |
+
def generation(self, name, link):
|
16 |
+
inputs = {"company": name, "company_link": link}
|
17 |
+
return MarketUseCaseCrew().crew().kickoff(inputs=inputs)
|
18 |
+
|
19 |
+
def use_case_generation(self):
|
20 |
+
if st.session_state.generation:
|
21 |
+
with st.spinner(f"Researching and generating uses cases about AI..."):
|
22 |
+
# Set progress to 50%
|
23 |
+
progress_bar = st.progress(50)
|
24 |
+
st.session_state.article_text = self.generation(
|
25 |
+
st.session_state.name, st.session_state.link
|
26 |
+
)
|
27 |
+
progress_bar.progress(100)
|
28 |
+
# Display the generated article
|
29 |
+
st.subheader("Generated Article:")
|
30 |
+
if st.session_state.article_text and st.session_state.article_text != "":
|
31 |
+
with st.container():
|
32 |
+
# Display the article text
|
33 |
+
st.markdown(st.session_state.article_text)
|
34 |
+
col1, col2, col3 = st.columns(3)
|
35 |
|
36 |
+
# Download button for the article
|
37 |
+
with col1:
|
38 |
+
if st.session_state.article_text:
|
39 |
+
st.download_button(
|
40 |
+
label="Download Article",
|
41 |
+
data=st.session_state.article_text,
|
42 |
+
file_name=f"{st.session_state.name.replace(' ', '_').lower()}_market_and_use_case_analysis.txt",
|
43 |
+
mime="text/plain"
|
44 |
+
)
|
45 |
+
else:
|
46 |
+
st.write("Article not generated yet.")
|
47 |
|
48 |
+
# Download button for ideas
|
49 |
+
with col2:
|
50 |
+
if st.session_state.article_text:
|
51 |
+
with open("output/ideas.md", "rb") as fp:
|
52 |
+
st.download_button(
|
53 |
+
label="Download Ideas",
|
54 |
+
data=fp,
|
55 |
+
file_name=f"{st.session_state.name.replace(' ', '_').lower()}_ideas.txt",
|
56 |
+
mime="text/plain"
|
57 |
+
)
|
58 |
+
else:
|
59 |
+
st.wrtie("Ideas are ideating")
|
60 |
+
# Download button for resources
|
61 |
+
with col3:
|
62 |
+
if st.session_state.article_text:
|
63 |
+
with open("output/resouce.md", "rb") as fp:
|
64 |
+
st.download_button(
|
65 |
+
label="Download Resources",
|
66 |
+
data=fp,
|
67 |
+
file_name=f"{st.session_state.name.replace(' ', '_').lower()}_resources.txt",
|
68 |
+
mime="text/plain"
|
69 |
+
)
|
70 |
+
else:
|
71 |
+
st.write("Resources are being researched")
|
72 |
+
st.markdown("---------")
|
73 |
+
st.session_state.generation=False
|
74 |
+
|
75 |
+
def sidebar(self):
|
76 |
+
with st.sidebar:
|
77 |
+
st.title("π API Configuration")
|
78 |
+
st.markdown("Enter your API keys below:")
|
79 |
|
80 |
+
# Input fields for API keys
|
81 |
+
serper_api_key = st.text_input("Serper API Key", type="password")
|
82 |
+
gemini_api_key = st.text_input("Gemini Flash API Key", type="password")
|
|
|
|
|
|
|
83 |
|
84 |
+
# Button to save API keys
|
85 |
+
if st.button("Save API Keys"):
|
86 |
+
# Check if both API keys are provided
|
87 |
+
if serper_api_key and gemini_api_key:
|
88 |
+
# Set environment variables for API keys
|
89 |
+
os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
|
90 |
+
os.environ['GOOGLE_API_KEY'] = gemini_api_key # Installed the gemini_api_key in the environment
|
91 |
+
st.success("API keys saved successfully!")
|
92 |
+
else:
|
93 |
+
st.error("Please enter both API keys.")
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
# Input fields for company name and website
|
96 |
+
name = st.text_input("Enter Name of the company:", key='name',placeholder="e.g., Google, Apple, Nike")
|
97 |
+
link = st.text_input("Enter the company's link:", key='link',placeholder="e.g., https://www.google.com, https://www.apple.com, https://www.nike.com")
|
98 |
|
99 |
+
if st.button("Generate Article"):
|
100 |
+
# Check if API keys are provided
|
101 |
+
if not serper_api_key or not gemini_api_key:
|
102 |
+
st.error("Please enter both API keys in the sidebar before generating.")
|
103 |
+
# Check if company name and website are provided
|
104 |
+
elif not name and link:
|
105 |
+
st.warning("Please enter the company name and website")
|
106 |
+
else:
|
107 |
+
# Create a progress bar
|
108 |
+
progress_bar = st.progress(0)
|
109 |
+
st.session_state.generation=True
|
110 |
|
111 |
+
def render(self):
|
112 |
+
st.set_page_config(page_title="CrewAI Article Generator", page_icon="π", layout="wide")
|
113 |
+
# Main content section
|
114 |
+
st.markdown("""
|
115 |
+
<style>
|
116 |
+
.reportview-container {
|
117 |
+
background: #f0f2f6
|
118 |
+
}
|
119 |
+
.main {
|
120 |
+
background: #00000;
|
121 |
+
padding: 3rem;
|
122 |
+
border-radius: 10px;
|
123 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
124 |
+
}
|
125 |
+
.stButton>button {
|
126 |
+
background-color: #0000;
|
127 |
+
color: white;
|
128 |
+
border-radius: 5px;
|
129 |
+
}
|
130 |
+
.stTextInput>div>div>input {
|
131 |
+
border-radius: 5px;
|
132 |
+
}
|
133 |
+
.sidebar .sidebar-content {
|
134 |
+
background-color: #f8f9fa;
|
135 |
+
}
|
136 |
+
</style>
|
137 |
+
""", unsafe_allow_html=True)
|
138 |
+
if "article_text" not in st.session_state:
|
139 |
+
st.session_state.article_text = ""
|
140 |
+
if "generation" not in st.session_state:
|
141 |
+
st.session_state.generation = False
|
142 |
+
if "name" not in st.session_state:
|
143 |
+
st.session_state.website = ""
|
144 |
+
if "link" not in st.session_state:
|
145 |
+
st.session_state.link = ""
|
146 |
|
147 |
+
self.sidebar()
|
148 |
+
self.use_case_generation()
|
149 |
|
150 |
+
if __name__ == "__main__":
|
151 |
+
MarketUseCaseGen().render()
|
src/research_agent/crew.py
CHANGED
@@ -4,46 +4,20 @@ from crewai.project import CrewBase, agent, crew, task
|
|
4 |
from src.research_agent.tools.tool import search_tool, website_search_tool,pdf_search_tool
|
5 |
import streamlit as st
|
6 |
import os
|
|
|
|
|
7 |
sys.path.append('..')
|
8 |
-
def streamlit_callback(step_output):
|
9 |
-
"""Callback function to display step output in Streamlit."""
|
10 |
-
st.markdown("---")
|
11 |
-
for step in step_output:
|
12 |
-
if isinstance(step, tuple) and len(step) == 2:
|
13 |
-
action, observation = step
|
14 |
-
if isinstance(action, dict) and "tool" in action and "tool_input" in action and "log" in action:
|
15 |
-
st.markdown(f"# Action")
|
16 |
-
st.markdown(f"**Tool:** {action['tool']}")
|
17 |
-
st.markdown(f"**Tool Input:** {action['tool_input']}")
|
18 |
-
st.markdown(f"**Log:** {action['log']}")
|
19 |
-
if 'Action' in action: # Check if 'Action' key exists before using it
|
20 |
-
st.markdown(f"**Action:** {action['Action']}")
|
21 |
-
st.markdown(f"**Action Input:** ```json\n{action['tool_input']}\n```")
|
22 |
-
elif isinstance(action, str):
|
23 |
-
st.markdown(f"**Action:** {action}")
|
24 |
-
else:
|
25 |
-
st.markdown(f"**Action:** {str(action)}")
|
26 |
-
|
27 |
-
st.markdown(f"**Observation**")
|
28 |
-
if isinstance(observation, str):
|
29 |
-
observation_lines = observation.split('\n')
|
30 |
-
for line in observation_lines:
|
31 |
-
st.markdown(line)
|
32 |
-
else:
|
33 |
-
st.markdown(str(observation))
|
34 |
-
else:
|
35 |
-
st.markdown(step)
|
36 |
|
37 |
@CrewBase
|
38 |
class MarketUseCaseCrew:
|
39 |
def llm(self):
|
40 |
-
return LLM(model="gemini/gemini-1.5-flash-002",
|
41 |
|
42 |
@agent
|
43 |
def researcher(self) -> Agent:
|
44 |
return Agent(
|
45 |
config=self.agents_config['researcher'],
|
46 |
-
tools=[search_tool,website_search_tool], # Example of custom tool, loaded on the beginning of file
|
47 |
verbose=True,
|
48 |
llm=self.llm(),
|
49 |
allow_delegation=True,
|
|
|
4 |
from src.research_agent.tools.tool import search_tool, website_search_tool,pdf_search_tool
|
5 |
import streamlit as st
|
6 |
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
load_dotenv()
|
9 |
sys.path.append('..')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
@CrewBase
|
12 |
class MarketUseCaseCrew:
|
13 |
def llm(self):
|
14 |
+
return LLM(model="gemini/gemini-1.5-flash-002", api_key=os.getenv("GOOGLE_API_KEY"))
|
15 |
|
16 |
@agent
|
17 |
def researcher(self) -> Agent:
|
18 |
return Agent(
|
19 |
config=self.agents_config['researcher'],
|
20 |
+
tools=[search_tool,website_search_tool, pdf_search_tool], # Example of custom tool, loaded on the beginning of file
|
21 |
verbose=True,
|
22 |
llm=self.llm(),
|
23 |
allow_delegation=True,
|