ryefoxlime commited on
Commit
1cc5a1d
Β·
1 Parent(s): e954dc8

alpha version 1.0

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +131 -130
  3. 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
- # Input fields for API keys
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
- # Button to save API keys
47
- if st.sidebar.button("Save API Keys"):
48
- # Check if both API keys are provided
49
- if serper_api_key and gemini_api_key:
50
- # Set environment variables for API keys
51
- os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
52
- os.environ['GOOGLE_API_KEY'] = gemini_api_key # Installed the gemini_api_key in the environment
53
- st.sidebar.success("API keys saved successfully!")
54
- else:
55
- st.sidebar.error("Please enter both API keys.")
56
-
57
- # Main content section
58
- st.title("πŸ“ Market and Research Analysis ")
59
- st.markdown("This is an Agent which can do Market Analysis and Generate Use Cases in the AI space for you")
60
-
61
- # Input fields for company name and website
62
- name = st.text_input("Enter Name of the company:", placeholder="e.g., Google, Apple, Nike")
63
- link = st.text_input("Enter the company's link:", placeholder="e.g., https://www.google.com, https://www.apple.com, https://www.nike.com")
 
 
64
 
65
- # Initialize session state if not present
66
- if 'article_text' not in st.session_state:
67
- st.session_state.article_text = ""
 
 
 
 
 
 
 
 
68
 
69
- # Button to generate article
70
- if st.button("Generate Article"):
71
- # Check if API keys are provided
72
- if not serper_api_key or not gemini_api_key:
73
- st.error("Please enter both API keys in the sidebar before generating.")
74
- # Check if company name and website are provided
75
- elif not name and link:
76
- st.warning("Please enter the company name and website")
77
- else:
78
- # Create a progress bar
79
- progress_bar = st.progress(0)
80
- # Input data for the article generation
81
- inputs = {
82
- 'company': name,
83
- 'company_link': link
84
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- # Use the MarketUseCaseCrew class to generate the article
87
- with st.spinner(f"Researching and generating uses cases about AI for '{name}'..."):
88
- # Set progress to 50%
89
- progress_bar.progress(50)
90
- # Call the kickoff method to generate the article
91
- result = MarketUseCaseCrew().crew().kickoff(inputs=inputs)
92
 
93
- # Set progress to 100%
94
- progress_bar.progress(100)
95
- # Display the generated article
96
- st.subheader("Generated Article:")
97
-
98
- # Extract the article text from the result
99
- if isinstance(result, str):
100
- st.session_state.article_text = result
101
- elif isinstance(result, dict) and 'article' in result:
102
- st.session_state.article_text = result['article']
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
- # Create three columns for download buttons
110
- col1, col2, col3 = st.columns(3)
 
111
 
112
- # Download button for the article
113
- with col1:
114
- if st.session_state.article_text:
115
- st.download_button(
116
- label="Download Article",
117
- data=st.session_state.article_text,
118
- file_name=f"{name.replace(' ', '_').lower()}_market_and_use_case_analysis.txt",
119
- mime="text/plain"
120
- )
121
- else:
122
- st.write("Article not generated yet.")
123
 
124
- # Download button for ideas
125
- with col2:
126
- if st.session_state.article_text:
127
- with open("output/ideas.md", "rb") as fp:
128
- st.download_button(
129
- label="Download Ideas",
130
- data=fp,
131
- file_name=f"{name.replace(' ', '_').lower()}_ideas.txt",
132
- mime="text/plain"
133
- )
134
- else:
135
- st.wrtie("Ideas are ideating")
136
- # Download button for resources
137
- with col3:
138
- if st.session_state.article_text:
139
- with open("output/resouce.md", "rb") as fp:
140
- st.download_button(
141
- label="Download Resources",
142
- data=fp,
143
- file_name=f"{name.replace(' ', '_').lower()}_resources.txt",
144
- mime="text/plain"
145
- )
146
- else:
147
- st.write("Resources are being researched")
 
 
 
 
 
 
 
 
 
 
 
148
 
149
- st.markdown("---------")
 
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", temperature=0.01, api_key=os.environ["GOOGLE_API_KEY"])
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,