Commit
·
4fd500e
1
Parent(s):
1e2617e
updated all files
Browse files- README.md +50 -13
- app.py +95 -4
- outputs/content_creator.md +0 -0
- requirements.txt +9 -0
- src/components/agents.py +119 -0
- src/components/image_generate.py +41 -0
- src/components/process.py +17 -0
- src/components/tasks.py +107 -0
- src/exception.py +22 -0
- src/logger.py +15 -0
- src/utils.py +52 -0
README.md
CHANGED
@@ -1,13 +1,50 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### Project Description
|
2 |
+
Implementing a scalable content team using AI involves creating a framework that blends the strengths of AI technologies with the creative and supervisory capabilities of human team members. This strategy aims to enhance efficiency, creativity, and content output quality.
|
3 |
+
|
4 |
+
This code is a high-level conceptualization and would require adaptation to fit the actual CrewAI framework and toolset specifics. It illustrates how different AI agents, equipped with specialized roles and tools, can collaborate within a content creation process. Each agent focuses on a key area—research, writing, and SEO—streamlining the content development workflow and enhancing output quality through specialized AI-driven tasks.
|
5 |
+
|
6 |
+
### Objective
|
7 |
+
Implement a content generation workflow using the Crew AI framework. This workflow should autonomously process input topics, conduct research, plan content, generate images, optimize for SEO, and perform final editorial checks.
|
8 |
+
|
9 |
+
### Tools and Frameworks:
|
10 |
+
* Crew AI framework
|
11 |
+
* Streamlit - User Interface(UI)
|
12 |
+
* Python for scripting
|
13 |
+
* AI models or APIs (e.g., `gemini-pro` for content, `stable-diffusion-xl-base` for images)
|
14 |
+
|
15 |
+
### Prerequisites
|
16 |
+
To complete this project, you should understand Python programming, data manipulation, visualization libraries such as Pandas and Matplotlib, and machine learning libraries such as Scikit-Learn. Additionally, some background knowledge of natural language processing (NLP) techniques and generate text to image and image to text methods would be helpful.
|
17 |
+
|
18 |
+
### Resources
|
19 |
+
- Live demo link: [Article Generate using CrewAI]()
|
20 |
+
- Check out [CrewAI](https://docs.crewai.com/)
|
21 |
+
- Project code [GitHub](https://github.com/Bhavik-Jikadara/Content-Generation-Workflow.git)
|
22 |
+
|
23 |
+
-----------------------------------------------------------------------------------------------------------------
|
24 |
+
## Notes: This step is very import:
|
25 |
+
### [Click here](https://www.c-sharpcorner.com/article/how-to-addedit-path-environment-variable-in-windows-11/) to set three API_KEYs in the Environment Variable, and use this link as a reference.
|
26 |
+
* [Click here to OpenAI API Key](https://platform.openai.com/api-keys)
|
27 |
+
|
28 |
+
$ OPENAI_API_KEY="Your-API-key"
|
29 |
+
* [Click here to Google API Key](https://aistudio.google.com/)
|
30 |
+
|
31 |
+
$ GOOGLE_API_KEY="Your-API-key"
|
32 |
+
* [Click here to Serper API Key](https://serper.dev/api-key)
|
33 |
+
|
34 |
+
$ SERPER_API_KEY="Your-API-key"
|
35 |
+
-----------------------------------------------------------------------------------------------------------------
|
36 |
+
|
37 |
+
### Step 1: Clone the repository
|
38 |
+
$ git clone https://github.com/Bhavik-Jikadara/Content-Generation-Workflow.git
|
39 |
+
$ cd Content-Generation-Workflow/
|
40 |
+
|
41 |
+
### Step 2: Create a virtualenv (windows user)
|
42 |
+
$ pip install virtualenv
|
43 |
+
$ virtualenv venv
|
44 |
+
$ source venv/Scripts/activate
|
45 |
+
|
46 |
+
### Step 3: Install the requirements libraries using pip
|
47 |
+
$ pip install -r requirements.txt
|
48 |
+
|
49 |
+
### Step 4: Type this command and run the project:
|
50 |
+
$ streamlit run Home.py
|
app.py
CHANGED
@@ -1,7 +1,98 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
-
st.title("Welcome to the Streamlit app")
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from src.components.process import all_crew
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
load_dotenv()
|
5 |
|
|
|
6 |
|
7 |
+
class ContentGenerationUI:
|
8 |
+
|
9 |
+
def generate_content(self, topic):
|
10 |
+
inputs = {
|
11 |
+
"topic": topic
|
12 |
+
}
|
13 |
+
result = all_crew.kickoff(inputs=inputs)
|
14 |
+
return result
|
15 |
+
|
16 |
+
def content_generation(self):
|
17 |
+
if st.session_state.generating:
|
18 |
+
st.session_state.content_generator = self.generate_content(
|
19 |
+
st.session_state.topic)
|
20 |
+
|
21 |
+
if st.session_state.content_generator and st.session_state.content_generator != "":
|
22 |
+
with st.container():
|
23 |
+
st.write("Content generated successfully!")
|
24 |
+
st.download_button(
|
25 |
+
label="Download Markdown file",
|
26 |
+
data=st.session_state.content_generator,
|
27 |
+
file_name="content_generate.md",
|
28 |
+
mime="text/markdown"
|
29 |
+
)
|
30 |
+
st.session_state.generating = False
|
31 |
+
|
32 |
+
def sidebar(self):
|
33 |
+
with st.sidebar:
|
34 |
+
st.title("Content Generator Tool")
|
35 |
+
st.write("This workflow should autonomously process input topics, conduct research, plan content, generate images, optimize for SEO, and perform final editorial checks.")
|
36 |
+
|
37 |
+
topic = st.text_area(
|
38 |
+
label="Enter the topic: ",
|
39 |
+
placeholder="Enter the name of the topic to generate the article",
|
40 |
+
key="topic",
|
41 |
+
height=175
|
42 |
+
)
|
43 |
+
st.write(f'You wrote {len(topic.split())} words.')
|
44 |
+
|
45 |
+
if st.button("Generate Content"):
|
46 |
+
st.session_state.generating = True
|
47 |
+
|
48 |
+
def render(self):
|
49 |
+
st.set_page_config(page_title="Content Generation", page_icon="📃")
|
50 |
+
tab1, tab2 = st.tabs(["Output", "About Project"])
|
51 |
+
|
52 |
+
# This is sidebar section
|
53 |
+
self.sidebar()
|
54 |
+
|
55 |
+
with tab2:
|
56 |
+
st.markdown("# About project")
|
57 |
+
st.write(
|
58 |
+
"""
|
59 |
+
### Project Description
|
60 |
+
Implementing a scalable content team using AI involves creating a framework that blends the strengths of AI technologies with the creative and supervisory capabilities of human team members. This strategy aims to enhance efficiency, creativity, and content output quality.
|
61 |
+
|
62 |
+
This code is a high-level conceptualization and would require adaptation to fit the actual CrewAI framework and toolset specifics. It illustrates how different AI agents, equipped with specialized roles and tools, can collaborate within a content creation process. Each agent focuses on a key area—research, writing, and SEO—streamlining the content development workflow and enhancing output quality through specialized AI-driven tasks.
|
63 |
+
|
64 |
+
### Objective
|
65 |
+
Implement a content generation workflow using the Crew AI framework. This workflow should autonomously process input topics, conduct research, plan content, generate images, optimize for SEO, and perform final editorial checks.
|
66 |
+
|
67 |
+
### Tools and Frameworks:
|
68 |
+
* Crew AI framework
|
69 |
+
* Streamlit - User Interface(UI)
|
70 |
+
* Python for scripting
|
71 |
+
* AI models or APIs (e.g., `gemini-pro` for content, `stable-diffusion-xl-base` for images)
|
72 |
+
|
73 |
+
### Prerequisites
|
74 |
+
To complete this project, you should understand Python programming, data manipulation, visualization libraries such as Pandas and Matplotlib, and machine learning libraries such as Scikit-Learn. Additionally, some background knowledge of natural language processing (NLP) techniques and generate text to image and image to text methods would be helpful.
|
75 |
+
|
76 |
+
### Resources
|
77 |
+
- Live demo link: [Content Generate - WebApp]()
|
78 |
+
- Check out [CrewAI](https://docs.crewai.com/)
|
79 |
+
- Project code [GitHub](https://github.com/Bhavik-Jikadara/Content-Generation-Workflow)
|
80 |
+
"""
|
81 |
+
)
|
82 |
+
|
83 |
+
with tab1:
|
84 |
+
# Initialize the app session state
|
85 |
+
if "topic" not in st.session_state:
|
86 |
+
st.session_state.topic = ""
|
87 |
+
|
88 |
+
if "content_generator" not in st.session_state:
|
89 |
+
st.session_state.content_generator = ""
|
90 |
+
|
91 |
+
if "generating" not in st.session_state:
|
92 |
+
st.session_state.generating = False
|
93 |
+
|
94 |
+
self.content_generation()
|
95 |
+
|
96 |
+
|
97 |
+
if __name__ == "__main__":
|
98 |
+
ContentGenerationUI().render()
|
outputs/content_creator.md
ADDED
File without changes
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
crewai
|
2 |
+
crewai[tools]
|
3 |
+
openai
|
4 |
+
streamlit
|
5 |
+
duckduckgo-search
|
6 |
+
langchain-google-genai
|
7 |
+
python-dotenv
|
8 |
+
requests
|
9 |
+
beautifulsoup4
|
src/components/agents.py
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from crewai import Agent
|
2 |
+
from src.utils import llm, search_tool, step_callback
|
3 |
+
from src.exception import CustomException
|
4 |
+
from src.components.image_generate import image_generate
|
5 |
+
import sys
|
6 |
+
|
7 |
+
|
8 |
+
try:
|
9 |
+
researcher_agent = Agent(
|
10 |
+
role="Researcher Agent",
|
11 |
+
goal="Your goal is to assists in content research by gathering, analyzing, and summarizing information on specified topics.",
|
12 |
+
backstory="""
|
13 |
+
### You are conducting keyword research and identifying trending topics relevant to the content strategy.
|
14 |
+
- This involves using various tools and techniques to identify keywords and topics that are relevant to the content strategy of the organization.
|
15 |
+
- Keyword research helps in understanding what topics are popular among the target audience and what keywords are commonly used in search queries related to the organization's industry or niche.
|
16 |
+
- Identifying trending topics allows the organization to capitalize on current trends and create content that is timely and relevant.
|
17 |
+
|
18 |
+
### Also, you are collecting data and insights from reputable sources to support content creation.
|
19 |
+
- This involves gathering data and information from reputable sources such as research papers, industry reports, authoritative websites, and credible publications.
|
20 |
+
- The collected data and insights serve as valuable resources for content creation, providing facts, statistics, case studies, and other supporting evidence to strengthen the content's credibility and relevance.
|
21 |
+
- Data collection may include conducting surveys, interviews, or market research to gather firsthand insights from target audiences or industry experts.
|
22 |
+
|
23 |
+
### Finally, you are proving summaries and briefs to human content creators to streamline their research phase.
|
24 |
+
- This responsibility entails summarizing the gathered information and insights into concise and actionable briefs for human content creators.
|
25 |
+
- Summaries and briefs help content creators quickly grasp the key points and main findings of the research, saving time and effort during the content creation process.
|
26 |
+
- By providing organized and digestible summaries, the AI Research Assistant enables content creators to focus on creative ideation, storytelling, and content development rather than spending excessive time on research and information gathering.
|
27 |
+
""",
|
28 |
+
tools=[search_tool],
|
29 |
+
verbose=True,
|
30 |
+
max_iter=5,
|
31 |
+
allow_delegation=True,
|
32 |
+
step_callback=lambda step: step_callback(
|
33 |
+
agent_output=step, agent_name="Research Agent")
|
34 |
+
)
|
35 |
+
|
36 |
+
content_creator_agent = Agent(
|
37 |
+
role="Content Creator",
|
38 |
+
goal="Your goal is to generate initial drafts of content based on templates, guidelines, and inputs for the research phase.",
|
39 |
+
backstory="""
|
40 |
+
- **Creating Initial Content Drafts for Various Formats:** This involves using natural language generation (NLG) technologies to generate preliminary drafts of content in different formats, such as blog posts, articles, and social media updates. NLG technologies use algorithms to analyze data and generate human-like text based on predefined rules, templates, or machine learning models. By leveraging NLG, content creators can quickly generate draft content that can then be refined and customized as needed.
|
41 |
+
|
42 |
+
- **Adhering to Brand Voice, Style Guides, and Content Objectives:** Content creators must ensure that the generated content aligns with the brand's voice and adheres to established style guides and content objectives. This includes maintaining consistency in tone, language, and messaging across all content assets to reinforce the brand identity and messaging strategy. Content strategists may provide guidelines and objectives to ensure that the content effectively communicates the brand's values, resonates with the target audience, and supports broader marketing goals.
|
43 |
+
|
44 |
+
- **Generating Creative Ideas for Content:** In addition to generating draft content, content creators are responsible for brainstorming and developing creative ideas for content campaigns. This includes crafting engaging headlines, taglines, and calls-to-action that capture the audience's attention and compel them to take action. Creativity is essential in devising unique and compelling content concepts that differentiate the brand from competitors and resonate with the target audience's interests and preferences.
|
45 |
+
""",
|
46 |
+
llm=llm,
|
47 |
+
verbose=True,
|
48 |
+
max_iter=5,
|
49 |
+
allow_delegation=True,
|
50 |
+
step_callback=lambda step: step_callback(
|
51 |
+
agent_output=step, agent_name="Content Creator Agent")
|
52 |
+
)
|
53 |
+
|
54 |
+
content_curator_agent = Agent(
|
55 |
+
role="Content Curatorr",
|
56 |
+
goal="Identifies and curates relevant external content to share with the audience, enhancing brand authority and engagement.",
|
57 |
+
backstory="""
|
58 |
+
- The AI Agent continuously monitors a wide array of sources such as websites, blogs, social media platforms, news outlets, and databases. It uses advanced algorithms to filter through this vast amount of information and identify content that is relevant to the target audience or specific topic of interest.
|
59 |
+
|
60 |
+
- Once relevant content is identified, the AI Agent analyzes and processes it to generate concise summaries and provide context. It may extract key points, insights, or quotes from articles, videos, or other media and reframe them in a format suitable for the intended audience or platform. This ensures that the curated content is digestible and adds value to the audience.
|
61 |
+
|
62 |
+
- Content Curator AI Agents are capable of tailoring curated content for various platforms and formats. Whether it's social media posts, blog articles, email newsletters, or video scripts, the AI Agent optimizes the content to fit the style, tone, and requirements of each platform.
|
63 |
+
""",
|
64 |
+
step_callback=lambda step: step_callback(
|
65 |
+
agent_output=step, agent_name="Content Curator Agent")
|
66 |
+
)
|
67 |
+
|
68 |
+
visual_content_creator_agent = Agent(
|
69 |
+
role="Visual Content Creator",
|
70 |
+
goal="Generates visual content such as images, infographics, and simple videos to complement textual content.",
|
71 |
+
backstory="""
|
72 |
+
- **Creating Visual Content Based on Textual Content Themes and Highlights:** Visual content creators translate textual content into engaging visuals, such as graphics, images, infographics, videos, or animations, to represent key themes and messages. This enhances audience engagement and understanding of the content.
|
73 |
+
|
74 |
+
- **Adhering to Brand Visual Guidelines and Aesthetics:** Visual content must align with the brand's visual identity, using consistent colors, fonts, logos, and design elements. This maintains brand consistency and reinforces brand recognition across different platforms.
|
75 |
+
|
76 |
+
- **Automatically Resizing and Adapting Visual Content for Different Platforms and Devices:** Visual content creators optimize assets for various screen sizes and platforms, ensuring they look great and perform well across devices. Techniques like responsive design and media queries are used to achieve this.
|
77 |
+
""",
|
78 |
+
verbose=True,
|
79 |
+
tools=[image_generate],
|
80 |
+
step_callback=lambda step: step_callback(
|
81 |
+
agent_output=step, agent_name="Visual Content creator Agent")
|
82 |
+
)
|
83 |
+
|
84 |
+
seo_analyst_agent = Agent(
|
85 |
+
role="SEO Analyst",
|
86 |
+
goal="Optimizes content for search engines and improves content discoverability online.",
|
87 |
+
backstory="""
|
88 |
+
- **Analyzing Content for SEO Best Practices:** Content analysts assess content to ensure it adheres to SEO best practices, including keyword density, meta descriptions, and title tags. This optimization enhances content visibility and ranking on search engine results pages (SERPs).
|
89 |
+
|
90 |
+
- **Recommending Improvements to Enhance Content Ranking:** Content analysts suggest improvements based on their analysis to enhance content ranking. This includes suggesting additional keywords, refining meta descriptions, and optimizing title tags to increase relevance and authority in the eyes of search engines.
|
91 |
+
|
92 |
+
- **Monitoring Content Performance and Providing Insights:** Content analysts continuously monitor content performance, including organic search traffic and user engagement metrics. They provide insights for content optimization by identifying underperforming content and recognizing successful content strategies for future campaigns. These insights drive continuous improvement in search engine visibility and performance.
|
93 |
+
""",
|
94 |
+
verbose=True,
|
95 |
+
allow_delegation=True,
|
96 |
+
step_callback=lambda step: step_callback(
|
97 |
+
agent_output=step, agent_name="SEO Analyst Agent")
|
98 |
+
)
|
99 |
+
|
100 |
+
editorial_assistant_agent = Agent(
|
101 |
+
role="Editorial Assistant",
|
102 |
+
goal="Your goal is to implement a review process to check the content for accuracy, coherence, grammar, and style. Make necessary adjustments.",
|
103 |
+
backstory="""
|
104 |
+
- Detailed Grammar and Spelling Checks: The Editorial Assistant meticulously examines content to identify and rectify any grammatical or spelling errors. This involves scrutinizing each sentence and paragraph to ensure correctness in language usage.
|
105 |
+
|
106 |
+
- Stylistic Adjustments:
|
107 |
+
In addition to grammar and spelling, the Editorial Assistant makes stylistic adjustments to harmonize content with the publication's designated tone and style guidelines. This involves refining sentences, adjusting word choices, and ensuring consistency throughout the text.
|
108 |
+
|
109 |
+
- Conducting Final Reviews:
|
110 |
+
The Editorial Assistant performs thorough final reviews to verify the readiness of content for publication. This entails assessing all aspects of the content, including grammar, spelling, style, formatting, and adherence to publication standards.
|
111 |
+
""",
|
112 |
+
verbose=True,
|
113 |
+
step_callback=lambda step: step_callback(
|
114 |
+
agent_output=step, agent_name="Editorial Assistant Agent")
|
115 |
+
)
|
116 |
+
|
117 |
+
|
118 |
+
except Exception as e:
|
119 |
+
raise CustomException(e, sys)
|
src/components/image_generate.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import io
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
from crewai_tools import tool
|
6 |
+
|
7 |
+
# API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
8 |
+
# hugginface_api_key = os.getenv("HUGGINGFACE_API_KEY")
|
9 |
+
# headers = {"Authorization": f"Bearer {hugginface_api_key}"}
|
10 |
+
# def query(payload):
|
11 |
+
# response = requests.post(API_URL, headers=headers, json=payload)
|
12 |
+
# return response.content
|
13 |
+
# def generate_image(input: str):
|
14 |
+
# """Create an image based on input"""
|
15 |
+
# image_bytes = query({
|
16 |
+
# "inputs": input,
|
17 |
+
# })
|
18 |
+
# # You can access the image with PIL.Image for example
|
19 |
+
|
20 |
+
# image = Image.open(io.BytesIO(image_bytes))
|
21 |
+
# name = input.split(" ")[0]
|
22 |
+
# image.save(f"images/generate_{name}.jpg")
|
23 |
+
# return image
|
24 |
+
|
25 |
+
@tool("Image Generate Tool")
|
26 |
+
def image_generate(context: str):
|
27 |
+
"""This is Image generate tool"""
|
28 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
29 |
+
hugginface_api_key = os.getenv("HUGGINGFACE_API_KEY")
|
30 |
+
headers = {"Authorization": f"Bearer {hugginface_api_key}"}
|
31 |
+
|
32 |
+
def query(payload):
|
33 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
34 |
+
return response.content
|
35 |
+
image_bytes = query({
|
36 |
+
"inputs": context,
|
37 |
+
})
|
38 |
+
name = context.split(" ")[0]
|
39 |
+
image = Image.open(io.BytesIO(image_bytes)).resize((1024, 1024))
|
40 |
+
image.save(f"outputs/generate_{name}.jpg")
|
41 |
+
return image
|
src/components/process.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Combine your agents into a crew, setting the workflow process they'll follow to accomplish the tasks, now with the option to configure language models for enhanced interaction.
|
3 |
+
"""
|
4 |
+
|
5 |
+
from crewai import Crew, Process
|
6 |
+
from src.components.agents import researcher_agent, content_creator_agent, seo_analyst_agent, visual_content_creator_agent, editorial_assistant_agent, content_curator_agent
|
7 |
+
from src.components.tasks import researcher_task, content_creator_task, seo_analyst_task, visual_content_creator_task, editorial_assistant_task, content_curator_task
|
8 |
+
|
9 |
+
|
10 |
+
# all crew
|
11 |
+
all_crew = Crew(
|
12 |
+
agents=[researcher_agent, content_creator_agent, content_curator_agent, seo_analyst_agent,
|
13 |
+
visual_content_creator_agent, editorial_assistant_agent],
|
14 |
+
tasks=[researcher_task, content_creator_task, content_curator_task, seo_analyst_task,
|
15 |
+
visual_content_creator_task, editorial_assistant_task],
|
16 |
+
process=Process.sequential
|
17 |
+
)
|
src/components/tasks.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from src.exception import CustomException
|
2 |
+
from crewai import Task
|
3 |
+
from src.components.agents import researcher_agent, content_creator_agent, visual_content_creator_agent, seo_analyst_agent, editorial_assistant_agent, content_curator_agent
|
4 |
+
import sys
|
5 |
+
from src.utils import llm
|
6 |
+
|
7 |
+
try:
|
8 |
+
researcher_task = Task(
|
9 |
+
description="""
|
10 |
+
These responsibilities highlight the role of the AI Research Assistant in supporting the content creation process by leveraging AI and machine learning techniques to streamline research, gather relevant data and insights, and facilitate collaboration between AI and human content creators based on the user input {topic}.
|
11 |
+
""",
|
12 |
+
agent=researcher_agent,
|
13 |
+
expected_output="""
|
14 |
+
Structuring a content plan that includes headings, subheadings, and key points to cover for the {topic}.
|
15 |
+
|
16 |
+
Exaple output:
|
17 |
+
### Title: The Role of AI in Healthcare
|
18 |
+
|
19 |
+
### Introduction:
|
20 |
+
- Brief overview of ....
|
21 |
+
|
22 |
+
### 1: AI Applications in Diagnosis and Disease Detection
|
23 |
+
* 1.1: Medical Imaging and Radiology
|
24 |
+
* Key points:
|
25 |
+
- Use of AI algorithms to analyze medical images (X-rays, MRIs, CT scans) for early detection of diseases.
|
26 |
+
- Improved accuracy and efficiency in identifying abnormalities and diagnosing conditions such as cancer, fractures, and cardiovascular diseases.
|
27 |
+
* 1.2: .......
|
28 |
+
|
29 |
+
### Conclusion:
|
30 |
+
- Summary of the key roles and applications of AI in healthcare, from diagnosis and treatment to personalized medicine and remote monitoring.
|
31 |
+
- Discussion of the potential benefits and challenges of AI adoption in healthcare, along with considerations for future developments.
|
32 |
+
- Call-to-action encouraging readers to stay informed about advancements in AI healthcare and to engage in discussions about the ethical and regulatory implications.
|
33 |
+
- Closing remarks emphasizing the transformative potential of AI in improving patient care and shaping the future of healthcare delivery.
|
34 |
+
|
35 |
+
""",
|
36 |
+
llm=llm,
|
37 |
+
output_file="outputs/content_creator.md"
|
38 |
+
)
|
39 |
+
|
40 |
+
content_creator_task = Task(
|
41 |
+
description="""
|
42 |
+
The role of generating initial drafts of content requires a blend of creativity, research skills, attention to detail, and adherence to guidelines. By effectively translating research insights into compelling content drafts, content creators lay the groundwork for successful content marketing campaigns that resonate with the target audience and achieve business objectives.
|
43 |
+
""",
|
44 |
+
agent=content_creator_agent,
|
45 |
+
expected_output="""
|
46 |
+
- Based on the content plan, generate a draft using an AI text-generation model. This should form the body of your content.
|
47 |
+
- Generating creative ideas for content, including headlines, taglines, and calls-to-action.
|
48 |
+
""",
|
49 |
+
llm=llm
|
50 |
+
)
|
51 |
+
|
52 |
+
content_curator_task = Task(
|
53 |
+
description="""
|
54 |
+
The Content Curator plays a pivotal role in guaranteeing that published content is error-free, stylistically appropriate, and prepared to meet the publication's standards and expectations.
|
55 |
+
""",
|
56 |
+
agent=content_curator_agent,
|
57 |
+
expected_output="""
|
58 |
+
- Apply SEO best practices to the generated content. This may involve:
|
59 |
+
- Keyword optimization.
|
60 |
+
- Meta tags and descriptions.
|
61 |
+
- Readability improvements.
|
62 |
+
|
63 |
+
The expected output of a Content Curator is optimizing content for SEO best practices, including keyword density, meta descriptions, and title tags. Recommending improvements to enhance content ranking on search engines. Monitoring content performance and providing insights for content optimization.
|
64 |
+
""",
|
65 |
+
llm=llm,
|
66 |
+
context=[researcher_task]
|
67 |
+
)
|
68 |
+
|
69 |
+
visual_content_creator_task = Task(
|
70 |
+
description="""
|
71 |
+
Incorporate an AI-based image generation model to create relevant images for the content. Ensure these images are saved locally.
|
72 |
+
""",
|
73 |
+
agent=visual_content_creator_agent,
|
74 |
+
expected_output="""Generate a .png or .jpg file image based on the input and return it in images folder."""
|
75 |
+
)
|
76 |
+
|
77 |
+
seo_analyst_task = Task(
|
78 |
+
description="""
|
79 |
+
The role involves optimizing content for search engines by analyzing, recommending improvements, and monitoring performance, ultimately aiming to enhance content discoverability online and improve its ranking on search engine results pages.
|
80 |
+
""",
|
81 |
+
agent=seo_analyst_agent,
|
82 |
+
expected_output="""
|
83 |
+
Apply SEO best practices to the generated content. This may involve:
|
84 |
+
- Keyword optimization.
|
85 |
+
- Meta tags and descriptions.
|
86 |
+
- Readability improvements.
|
87 |
+
|
88 |
+
The expected output of an SEO Analyst is analyzing content for SEO best practices, including keyword density, meta descriptions, and title tags. Recommending improvements to enhance content ranking on search engines. Monitoring content performance and providing insights for content optimization.
|
89 |
+
""",
|
90 |
+
context=[content_creator_task]
|
91 |
+
)
|
92 |
+
|
93 |
+
editorial_assistant_task = Task(
|
94 |
+
description="""
|
95 |
+
The Editorial Assistant plays a pivotal role in guaranteeing that published content is error-free, stylistically appropriate, and prepared to meet the publication's standards and expectations.
|
96 |
+
""",
|
97 |
+
agent=editorial_assistant_agent,
|
98 |
+
expected_output="""
|
99 |
+
The expected output is high-quality content that is polished, accurate, and in line with the publication's editorial standards, ensuring a positive reader experience and maintaining the publication's reputation for excellence.
|
100 |
+
""",
|
101 |
+
context=[seo_analyst_task],
|
102 |
+
output_file="outputs/content_creator.md"
|
103 |
+
)
|
104 |
+
|
105 |
+
|
106 |
+
except Exception as err:
|
107 |
+
raise CustomException(err, sys)
|
src/exception.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
from src.logger import logging
|
3 |
+
|
4 |
+
# custom error handling
|
5 |
+
|
6 |
+
|
7 |
+
def error_message_detail(error, error_detail: sys):
|
8 |
+
_, _, exc_tb = error_detail.exc_info()
|
9 |
+
filename = exc_tb.tb_frame.f_code.co_filename
|
10 |
+
error_message = "Error occured in python script name [{0}] line number [{1}] error message [{2}]".format(
|
11 |
+
filename, exc_tb.tb_lineno, str(error))
|
12 |
+
return error_message
|
13 |
+
|
14 |
+
|
15 |
+
class CustomException(Exception):
|
16 |
+
def __init__(self, error_message, error_details: sys) -> None:
|
17 |
+
super().__init__(error_message)
|
18 |
+
self.error_message = error_message_detail(error_message, error_details)
|
19 |
+
|
20 |
+
# return error message
|
21 |
+
def __str__(self):
|
22 |
+
return self.error_message
|
src/logger.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
LOG_FILE = f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log"
|
6 |
+
logs_path = os.path.join(os.getcwd(), "logs", LOG_FILE)
|
7 |
+
os.makedirs(logs_path, exist_ok=True)
|
8 |
+
|
9 |
+
LOG_FILE_PATH = os.path.join(logs_path, LOG_FILE)
|
10 |
+
|
11 |
+
logging.basicConfig(
|
12 |
+
filename=LOG_FILE_PATH,
|
13 |
+
format="[ %(asctime)s ] %(lineno)d %(name)s - %(levelname)s - %(message)s",
|
14 |
+
level=logging.INFO
|
15 |
+
)
|
src/utils.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain_google_genai import GoogleGenerativeAI
|
2 |
+
from crewai_tools import SerperDevTool
|
3 |
+
import datetime
|
4 |
+
import json
|
5 |
+
import os
|
6 |
+
import streamlit as st
|
7 |
+
from typing import Dict, List, Tuple, Union
|
8 |
+
from langchain_core.agents import AgentFinish
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# search tool
|
13 |
+
search_tool = SerperDevTool(n_results=5)
|
14 |
+
# model for generate content
|
15 |
+
llm = GoogleGenerativeAI(
|
16 |
+
model="gemini-pro", google_api_key=os.getenv("GOOGLE_API_KEY"))
|
17 |
+
|
18 |
+
|
19 |
+
# Step_callback function
|
20 |
+
def step_callback(agent_output: Union[str, List[Tuple[Dict, str]], AgentFinish], agent_name, *args):
|
21 |
+
with st.chat_message("AI"):
|
22 |
+
# Try to parse the output if it is a JSON string
|
23 |
+
if isinstance(agent_output, str):
|
24 |
+
try:
|
25 |
+
agent_output = json.loads(agent_output)
|
26 |
+
except json.JSONDecodeError:
|
27 |
+
pass
|
28 |
+
|
29 |
+
if isinstance(agent_output, list) and all(
|
30 |
+
isinstance(item, tuple) for item in agent_output
|
31 |
+
):
|
32 |
+
|
33 |
+
for action, description in agent_output:
|
34 |
+
# Print attributes based on assumed structure
|
35 |
+
st.write(f"Agent Name: {agent_name}")
|
36 |
+
st.write(f"Tool used: {getattr(action, 'tool', 'Unknown')}")
|
37 |
+
st.write(
|
38 |
+
f"Tool input: {getattr(action, 'tool_input', 'Unknown')}")
|
39 |
+
st.write(f"{getattr(action, 'log', 'Unknown')}")
|
40 |
+
with st.expander("Show observation"):
|
41 |
+
st.markdown(f"Observation\n\n{description}")
|
42 |
+
|
43 |
+
# Check if the output is a dictionary as in the second case
|
44 |
+
elif isinstance(agent_output, AgentFinish):
|
45 |
+
st.write(f"Agent Name: {agent_name}")
|
46 |
+
output = agent_output.return_values
|
47 |
+
st.write(f"I finished my task:\n{output['output']}")
|
48 |
+
|
49 |
+
# Handle unexpected formats
|
50 |
+
else:
|
51 |
+
st.write(type(agent_output))
|
52 |
+
st.write(agent_output)
|