ryefoxlime commited on
Commit
99c3854
1 Parent(s): 3f949c9

First push to hugging_face

Browse files
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ crewai
2
+ crewai_tools
3
+ streamlit
4
+ python-dotenv
src/gui/__init__.py ADDED
File without changes
src/gui/app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from ..research_agent.crew import MarketUseCaseCrew
3
+ import streamlit as st
4
+ from crewai import Crew, Process
5
+ from tools import tool
6
+ import os
7
+
8
+ # Configure the Streamlit page
9
+ st.set_page_config(page_title="CrewAI Article Generator", page_icon="📝", layout="wide")
10
+
11
+ # Custom CSS for styling the page
12
+ st.markdown("""
13
+ <style>
14
+ .reportview-container {
15
+ background: #f0f2f6
16
+ }
17
+ .main {
18
+ background: #00000;
19
+ padding: 3rem;
20
+ border-radius: 10px;
21
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
22
+ }
23
+ .stButton>button {
24
+ background-color: #0000;
25
+ color: white;
26
+ border-radius: 5px;
27
+ }
28
+ .stTextInput>div>div>input {
29
+ border-radius: 5px;
30
+ }
31
+ .sidebar .sidebar-content {
32
+ background-color: #f8f9fa;
33
+ }
34
+ </style>
35
+ """, unsafe_allow_html=True)
36
+
37
+ # Sidebar for API key input
38
+ st.sidebar.title("📊 API Configuration")
39
+ st.sidebar.markdown("Enter your API keys below:")
40
+
41
+ # Input fields for API keys
42
+ serper_api_key = st.sidebar.text_input("Serper API Key", type="password")
43
+ gemini_api_key = st.sidebar.text_input("Gemini Flash API Key", type="password")
44
+
45
+ # Button to save API keys
46
+ if st.sidebar.button("Save API Keys"):
47
+ # Check if both API keys are provided
48
+ if serper_api_key and gemini_api_key:
49
+ # Set environment variables for API keys
50
+ os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
51
+ os.environ['GOOGLE_API_KEY'] = gemini_api_key # Installed the gemini_api_key in the environment
52
+ st.sidebar.success("API keys saved successfully!")
53
+ else:
54
+ st.sidebar.error("Please enter both API keys.")
55
+
56
+ # Main content section
57
+ st.title("📝 Market and Research Analysis ")
58
+ st.markdown("This is an Agent which can do Market Analysis and Generate Use Cases in the AI space for you")
59
+
60
+ # Input fields for company name and website
61
+ name = st.text_input("Enter Name of the company:", placeholder="e.g., Google, Apple, Nike")
62
+ link = st.text_input("Enter the company's link:", placeholder="e.g., https://www.google.com, https://www.apple.com, https://www.nike.com")
63
+
64
+ # Button to generate article
65
+ if st.button("Generate Article"):
66
+ # Check if API keys are provided
67
+ if not serper_api_key or not gemini_api_key:
68
+ st.error("Please enter both API keys in the sidebar before generating.")
69
+ # Check if company name and website are provided
70
+ elif not name and link:
71
+ st.warning("Please enter the company name and website")
72
+ else:
73
+ # Create a progress bar
74
+ progress_bar = st.progress(0)
75
+ # Input data for the article generation
76
+ inputs = {
77
+ 'company': name,
78
+ 'company_link': link
79
+ }
80
+
81
+ # Use the MarketUseCaseCrew class to generate the article
82
+ with st.spinner(f"Researching and generating uses cases about AI for '{name}'..."):
83
+ # Set progress to 50%
84
+ progress_bar.progress(50)
85
+ # Call the kickoff method to generate the article
86
+ result = MarketUseCaseCrew().crew().kickoff(inputs=inputs)
87
+
88
+ # Set progress to 100%
89
+ progress_bar.progress(100)
90
+ # Display the generated article
91
+ st.subheader("Generated Article:")
92
+
93
+ # Extract the article text from the result
94
+ if isinstance(result, str):
95
+ article_text = result
96
+ elif isinstance(result, dict) and 'article' in result:
97
+ article_text = result['article']
98
+ else:
99
+ article_text = str(result)
100
+
101
+ # Display the article text
102
+ st.markdown(article_text)
103
+
104
+ # Create three columns for download buttons
105
+ col1, col2, col3 = st.columns(3)
106
+
107
+ # Download button for the article
108
+ with col1:
109
+ st.download_button(
110
+ label="Download Article",
111
+ data=article_text,
112
+ file_name=f"{name.replace(' ', '_').lower()}_market_and_use_case_analysis.txt",
113
+ mime="text/plain"
114
+ )
115
+
116
+ # Download button for ideas
117
+ with col2:
118
+ with open("output/ideas.md", "rb") as fp:
119
+ st.download_button(
120
+ label="Download Ideas",
121
+ data=fp,
122
+ file_name=f"{name.replace(' ', '_').lower()}_ideas.txt",
123
+ mime="text/plain"
124
+ )
125
+
126
+ # Download button for resources
127
+ with col3:
128
+ with open("output/resouce.md", "rb") as fp:
129
+ st.download_button(
130
+ label="Download Ideas",
131
+ data=fp,
132
+ file_name=f"{name.replace(' ', '_').lower()}_ideas.txt",
133
+ mime="image/txt"
134
+ )
135
+
136
+ st.markdown("---------")
src/research_agent/__init__.py ADDED
File without changes
src/research_agent/config/agents.yaml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ researcher:
2
+ role: >
3
+ {company} Senior Research Analyst
4
+ goal: >
5
+ - Understanding the industry and segment {company} is working in (e.g., Automotive, Manufacturing, Finance, Retail, Healthcare, etc.).
6
+ - Identify the {company}'s key offering with respect to the competition and
7
+ - What should the strategic focus be based on how the competition is performing in the market in the present and in the past.
8
+ - refer to reports and insights on AI and digital transformation from industry-specific sources such as McKinsey, Deloitte,Nexocode etc.''',
9
+ backstory: >
10
+ You are a veteran market analyst with an eye to find trends and usage patterns such as which services/products return the highest income or customer retention.
11
+ Through qualitative research both internal and external, you are also able to find the services/products which have the highest bottom line and are difficult to scale
12
+ You also find niche markets or high potential markets that align with the companys goals and can lead to growth in that sector
13
+
14
+ design_thinker:
15
+ role: >
16
+ {company} Senior Design Thinker
17
+ goal: >
18
+ Using the information given to you, identify possibilities/ideas that the {company} can use technologies such as AI, ML, DL, Gen AI etc.
19
+ backstory: >
20
+ You are a veteran design thinker graduated from a very reputed organization that has been tasked to help the company navigate the AI space by giving ideas on how AI,GEN AI,LLMS can be implemented into the product to make it more user and business friendly.
21
+
22
+ developer:
23
+ role: >
24
+ {company} Senior Data Scientist
25
+ goal: >
26
+ Based on the ideas from the Design Thinker, compile all the relevant information and technical drawbacks.
27
+ backstory: >
28
+ You are a senior data scientist with a strong background in machine learning and AI. You have worked on various projects and have a good understanding of the technical aspects of implementing AI into a product.
29
+ You are also able to identify the potential drawbacks of implementing AI into a product and how to mitigate them.,
src/research_agent/config/tasks.yaml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ research_task:
2
+ description: >
3
+ - Conduct a Through Market and Segment Analysis of {company} with other companies in the same Industry
4
+ - Identify the {company}'s' major offering with respect to other companies that will make users prefer {company}
5
+ - Find out the {company} strategic focus areas where it outperforms other companys in the same Industry
6
+ - For additional information about the company use the following link: {company_link}
7
+ IMPORTANT INSTRUCTIONS ABOUT USING TOOLS: When using tools, DO NOT ESCAPE the underscore character "_", EVER. If you need to use a tool and pass in a parameter called 'search_query', you should write 'search_query', not 'search\_query'. THIS IS VERY IMPORTANT, else the tool will not work.
8
+
9
+ expected_output: >
10
+ - A list with the most relevant information about industry,segment,key offering and strategic focus of {company} in a markdown file.
11
+ - For each source or contextual detail referenced, please include any relevant links in a markdown link format (e.g., [source text](URL)).
12
+
13
+ agent: researcher
14
+
15
+ design_task:
16
+ description: >
17
+ - Based on the context you got and define scope where {company} can expand. Generate a detailed report that includes:
18
+ - An analysis using 'Yes, and...' to list example use cases, potential implementation strategies, and possible drawbacks illustrated through flowcharts.
19
+ - Insights that empathize with shareholders, focusing on how these ideas may impact and benefit customers.
20
+ - Proposals for low-cost, easily testable prototypes to gauge market interest.
21
+ - Try to avoid already existing products and put more emphasis on how others are approaching AI space
22
+
23
+ For flowcharts use the mermaid js library.
24
+ Ensure that all relevant information is accessible within the file, and integrate each link in context as necessary for clarity (e.g., [source text](URL)).
25
+ IMPORTANT INSTRUCTIONS ABOUT USING TOOLS: When using tools, DO NOT ESCAPE the underscore character "_", EVER. If you need to use a tool and pass in a parameter called 'search_query', you should write 'search_query', not 'search\_query'. THIS IS VERY IMPORTANT, else the tool will not work.
26
+
27
+ expected_output: >
28
+ A markdown document with all the ideas to that can be implemented.
29
+
30
+ Each one should contain:
31
+ - Title:
32
+ - Summary:
33
+ - Flowchart (if applicable)
34
+ - Use Case
35
+ - Potenial Drawbacks
36
+ - How the idea may impact or benefit the customers
37
+ - Source: [source text](URL)
38
+
39
+
40
+ agent: design_thinker
41
+
42
+ resource_collector:
43
+ description: >
44
+ Based on the ideas generated by the design thinker, gather relevant resources to support each idea.
45
+ - The resources should include relevant datasets, research papers, similar or existing projects, and any related documentation that may aid in exploring or validating the proposed expansion ideas.
46
+ - Each resource should be annotated with a short description explaining its relevance.
47
+ - If applicable, propose GenAI solutions like document search, automated report generation, and AI-powered chat systems for internal or customer-facing purposes.
48
+ - Datasets and existing projects can be found on websites such as hugging_face, github, kaggle.
49
+
50
+ IMPORTANT INSTRUCTIONS ABOUT USING TOOLS: When using tools, DO NOT ESCAPE the underscore character "_", EVER. If you need to use a tool and pass in a parameter called 'search_query', you should write 'search_query', not 'search\_query'. THIS IS VERY IMPORTANT, else the tool will not work.
51
+
52
+ Context: ["analysing_task"]
53
+
54
+ expected_output: >
55
+ A structured list of resources for any two ideas, with the following details for each resource:
56
+ - Title and type of the resource (e.g., Dataset, Research Paper, Project)
57
+ - Direct link or reference to the resource in markdown link format (e.g., [Title](URL))
58
+ - A short summary of how each resource is relevant to the specific idea.
59
+ - Modification to suit {company}'s goals
60
+
61
+ Ensure that this information is formatted as markdown, with each resource link integrated in context for readability.
62
+
63
+ agent: developer
src/research_agent/crew.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Agent, Crew, Process, Task, LLM
2
+ from crewai.tasks.task_output import TaskOutput
3
+ from crewai.project import CrewBase, agent, crew, task
4
+ from tools.tool import search_tool, website_search_tool,pdf_search_tool
5
+ import streamlit as st
6
+ import os
7
+ from crewai.agents.parser import AgentFinish
8
+
9
+ def streamlit_callback(step_output):
10
+ """Callback function to display step output in Streamlit."""
11
+ st.markdown("---")
12
+ for step in step_output:
13
+ if isinstance(step, tuple) and len(step) == 2:
14
+ action, observation = step
15
+ if isinstance(action, dict) and "tool" in action and "tool_input" in action and "log" in action:
16
+ st.markdown(f"# Action")
17
+ st.markdown(f"**Tool:** {action['tool']}")
18
+ st.markdown(f"**Tool Input:** {action['tool_input']}")
19
+ st.markdown(f"**Log:** {action['log']}")
20
+ if 'Action' in action: # Check if 'Action' key exists before using it
21
+ st.markdown(f"**Action:** {action['Action']}")
22
+ st.markdown(f"**Action Input:** ```json\n{action['tool_input']}\n```")
23
+ elif isinstance(action, str):
24
+ st.markdown(f"**Action:** {action}")
25
+ else:
26
+ st.markdown(f"**Action:** {str(action)}")
27
+
28
+ st.markdown(f"**Observation**")
29
+ if isinstance(observation, str):
30
+ observation_lines = observation.split('\n')
31
+ for line in observation_lines:
32
+ st.markdown(line)
33
+ else:
34
+ st.markdown(str(observation))
35
+ else:
36
+ st.markdown(step)
37
+
38
+ @CrewBase
39
+ class MarketUseCaseCrew:
40
+ def llm(self):
41
+ return LLM(model="gemini/gemini-1.5-flash-002", temperature=0.01, api_key=os.environ["GOOGLE_API_KEY"])
42
+
43
+ @agent
44
+ def researcher(self) -> Agent:
45
+ return Agent(
46
+ config=self.agents_config['researcher'],
47
+ tools=[search_tool,website_search_tool], # Example of custom tool, loaded on the beginning of file
48
+ verbose=True,
49
+ llm=self.llm(),
50
+ allow_delegation=True,
51
+ )
52
+
53
+ @agent
54
+ def design_thinker(self) -> Agent:
55
+ return Agent(
56
+ config=self.agents_config['design_thinker'],
57
+ verbose=True,
58
+ tools=[search_tool, website_search_tool],
59
+ llm=self.llm(),
60
+ allow_delegation=True,
61
+ )
62
+
63
+ @agent
64
+ def developer(self) -> Agent:
65
+ return Agent(
66
+ config=self.agents_config['developer'],
67
+ verbose=True,
68
+ tools=[search_tool, website_search_tool, pdf_search_tool],
69
+ llm=self.llm(),
70
+ allow_delegation=True,
71
+ )
72
+
73
+ @task
74
+ def research_task(self) -> Task:
75
+ return Task(
76
+ config=self.tasks_config['research_task'],
77
+ output_file=f'output/researched_data.md',
78
+ )
79
+
80
+ @task
81
+ def design_task(self) -> Task:
82
+ return Task(
83
+ config=self.tasks_config['design_task'],
84
+ output_file=f'output/ideas.md'
85
+ )
86
+
87
+ @task
88
+ def resource_collector(self) -> Task:
89
+ return Task(
90
+ config=self.tasks_config['resource_collector'],
91
+ output_file=f'output/resouce.md'
92
+ )
93
+ @crew
94
+ def crew(self) -> Crew:
95
+ """Creates the ResearchAgent crew"""
96
+ return Crew(
97
+ agents=self.agents, # Automatically created by the @agent decorator
98
+ tasks=self.tasks, # Automatically created by the @task decorator
99
+ process=Process.sequential,
100
+ verbose=True,
101
+ # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
102
+ )
src/research_agent/main.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ import sys
3
+ from crew import MarketUseCaseCrew
4
+
5
+ # This main file is intended to be a way for you to run your
6
+ # crew locally, so refrain from adding unnecessary logic into this file.
7
+ # Replace with inputs you want to test with, it will automatically
8
+ # interpolate any tasks and agents information
9
+
10
+ def run():
11
+ """
12
+ Run the crew.
13
+ """
14
+ inputs = {
15
+ 'topic': 'google'
16
+ }
17
+ MarketUseCaseCrew().crew().kickoff(inputs=inputs)
18
+
19
+
20
+ def train():
21
+ """
22
+ Train the crew for a given number of iterations.
23
+ """
24
+ inputs = {
25
+ "topic": "google"
26
+ }
27
+ try:
28
+ MarketUseCaseCrew().crew().train(n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=inputs)
29
+
30
+ except Exception as e:
31
+ raise Exception(f"An error occurred while training the crew: {e}")
32
+
33
+ def replay():
34
+ """
35
+ Replay the crew execution from a specific task.
36
+ """
37
+ try:
38
+ MarketUseCaseCrew().crew().replay(task_id=sys.argv[1])
39
+
40
+ except Exception as e:
41
+ raise Exception(f"An error occurred while replaying the crew: {e}")
42
+
43
+ def test():
44
+ """
45
+ Test the crew execution and returns the results.
46
+ """
47
+ inputs = {
48
+ "topic": "google"
49
+ }
50
+ try:
51
+ MarketUseCaseCrew().crew().test(n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs)
52
+
53
+ except Exception as e:
54
+ raise Exception(f"An error occurred while replaying the crew: {e}")
src/research_agent/tools/__init__.py ADDED
File without changes
src/research_agent/tools/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (173 Bytes). View file
 
src/research_agent/tools/__pycache__/tool.cpython-311.pyc ADDED
Binary file (1.29 kB). View file
 
src/research_agent/tools/tool.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai_tools import SerperDevTool, WebsiteSearchTool, PDFSearchTool
2
+ import os
3
+ from dotenv import load_dotenv
4
+ load_dotenv()
5
+
6
+ search_tool = SerperDevTool(
7
+ serper_api_key=os.getenv("SERPER_API_KEY")
8
+ )
9
+
10
+ website_search_tool = WebsiteSearchTool(
11
+ config=dict(
12
+ llm=dict(
13
+ provider='google',
14
+ config=dict(
15
+ model="gemini/gemini-1.5-flash-002",
16
+ ),
17
+ ),
18
+ embedder=dict(
19
+ provider="google",
20
+ config=dict(
21
+ model="models/embedding-001/",
22
+ task_type="retrieval_document"
23
+ ),
24
+ ),
25
+ )
26
+ )
27
+
28
+ pdf_search_tool = PDFSearchTool(
29
+ config=dict(
30
+ llm=dict(
31
+ provider='google',
32
+ config=dict(
33
+ model="gemini/gemini-1.5-flash-002",
34
+ ),
35
+ ),
36
+ embedder=dict(
37
+ provider="google",
38
+ config=dict(
39
+ model="models/embedding-001/",
40
+ task_type="retrieval_document"
41
+ ),
42
+ ),
43
+ )
44
+ )