yashmangal112 commited on
Commit
dfe4070
·
verified ·
1 Parent(s): 66a24fe

Upload 5 files

Browse files
Files changed (5) hide show
  1. agents.py +60 -0
  2. llm_model.py +14 -0
  3. main.py +45 -0
  4. requirements.txt +4 -0
  5. tasks.py +50 -0
agents.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Agent
2
+ from llm_model import LLM_MODEL
3
+
4
+ # 1. Content Planner Agent
5
+ content_planner = Agent(
6
+ role="Content Planner",
7
+ goal="Plan engaging and factually accurate content on {topic}",
8
+ backstory="You're working on planning a blog article "
9
+ "about the topic: {topic} in 'https://medium.com/'."
10
+ "You collect information that helps the "
11
+ "audience learn something "
12
+ "and make informed decisions. "
13
+ "You have to prepare a detailed "
14
+ "outline and the relevant topics and sub-topics that has to be a part of the"
15
+ "blogpost."
16
+ "Your work is the basis for "
17
+ "the Content Writer to write an article on this topic.",
18
+ llm=LLM_MODEL,
19
+ allow_delegation=False,
20
+ )
21
+
22
+ # 2. Blog Writer Agent
23
+ blog_writer = Agent(
24
+ role="Blog Writer",
25
+ goal="Write insightful and factually accurate "
26
+ "opinion piece about the topic: {topic}",
27
+ backstory="You're working on a writing "
28
+ "a new opinion piece about the topic: {topic} in 'https://medium.com/'. "
29
+ "You base your writing on the work of "
30
+ "the Content Planner, who provides an outline "
31
+ "and relevant context about the topic. "
32
+ "You follow the main objectives and "
33
+ "direction of the outline, "
34
+ "as provide by the Content Planner. "
35
+ "You also provide objective and impartial insights "
36
+ "and back them up with information "
37
+ "provide by the Content Planner. "
38
+ "You acknowledge in your opinion piece "
39
+ "when your statements are opinions "
40
+ "as opposed to objective statements.",
41
+ llm=LLM_MODEL,
42
+ allow_delegation=False,
43
+ )
44
+
45
+ # 3. Editor Agent
46
+ editor = Agent(
47
+ role="Editor",
48
+ goal="Edit a given blog post to align with "
49
+ "the writing style of the organization 'https://medium.com/'. ",
50
+ backstory="You are an editor who receives a blog post "
51
+ "from the Content Writer. "
52
+ "Your goal is to review the blog post "
53
+ "to ensure that it follows journalistic best practices,"
54
+ "provides balanced viewpoints "
55
+ "when providing opinions or assertions, "
56
+ "and also avoids major controversial topics "
57
+ "or opinions when possible.",
58
+ llm=LLM_MODEL,
59
+ allow_delegation=False,
60
+ )
llm_model.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_groq import ChatGroq
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv()
6
+ # os.environ["GROQ_API_KEY"] = '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'
7
+
8
+ LLM_MODEL = ChatGroq(
9
+ model="groq/llama-3.3-70b-versatile",
10
+ temperature=0,
11
+ max_tokens=1024,
12
+ timeout=30,
13
+ max_retries=2,
14
+ )
main.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Crew
2
+ from tasks import plan_task, write_task, edit_task
3
+ import gradio as gr
4
+
5
+ # Initialize Crew with agents and their tasks
6
+ blog_crew = Crew(
7
+ agents=[plan_task.agent, write_task.agent, edit_task.agent],
8
+ tasks=[plan_task, write_task, edit_task],
9
+ verbose=True
10
+ )
11
+
12
+ # Function to run the blog creation workflow
13
+ def generate_blog(topic):
14
+ if not topic or topic.strip() == "":
15
+ return "❌ Error: Please enter a valid topic for the blog post."
16
+ if len(topic.strip()) < 5:
17
+ return "❌ Error: The topic is too short. Please provide a more detailed topic."
18
+
19
+ print(f"Starting the Blog Writer Multi-Agent System for topic: {topic}")
20
+ try:
21
+ inputs = {"topic": topic}
22
+ result = blog_crew.kickoff(inputs=inputs)
23
+ print("Blog content creation completed!")
24
+ return result
25
+ except Exception as e:
26
+ print(f"An error occurred: {e}")
27
+ return f"❌ Error: Failed to generate the blog post. Please try again with a different topic."
28
+
29
+ # Gradio Interface
30
+ def gradio_interface(topic):
31
+ blog_content = generate_blog(topic)
32
+ return blog_content
33
+
34
+ # Create Gradio app
35
+ interface = gr.Interface(
36
+ fn=gradio_interface,
37
+ inputs=gr.Textbox(lines=2, placeholder="Enter the topic for your blog post...", label="Blog Topic"),
38
+ outputs=gr.Textbox(lines=20, label="Generated Blog Post"),
39
+ title="AI-Powered Blog Writer",
40
+ description="A Multi-Agent System for Automated Content Creation. Enter a topic, and the system will generate a blog post for you!"
41
+ )
42
+
43
+ # Run the Gradio app
44
+ if __name__ == "__main__":
45
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ crewai
2
+ langchain-groq
3
+ gradio
4
+ python-dotenv
tasks.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Task
2
+ from agents import content_planner, blog_writer, editor
3
+
4
+ # Task for Content Planner
5
+ plan_task = Task(
6
+ description=(
7
+ "1. Prioritize the latest trends, key players, "
8
+ "and noteworthy news on {topic}.\n"
9
+ "2. Identify the target audience, considering "
10
+ "their interests and pain points.\n"
11
+ "3. Develop a detailed content outline including "
12
+ "an introduction, key points, and a call to action.\n"
13
+ "4. Include SEO keywords and relevant data or sources."
14
+ ),
15
+ expected_output="A comprehensive content plan document "
16
+ "with an outline, audience analysis, "
17
+ "SEO keywords, and resources.",
18
+ agent=content_planner,
19
+ )
20
+
21
+ # Task for Blog Writer
22
+ write_task = Task(
23
+ description=(
24
+ "1. Use the content plan to craft a compelling "
25
+ "blog post on {topic}.\n"
26
+ "2. Incorporate SEO keywords naturally.\n"
27
+ "3. Sections/Subtitles are properly named "
28
+ "in an engaging manner.\n"
29
+ "4. Ensure the post is structured with an "
30
+ "engaging introduction, insightful body, "
31
+ "and a summarizing conclusion.\n"
32
+ "5. Proofread for grammatical errors and "
33
+ "alignment with the brand's voice.\n"
34
+ ),
35
+ expected_output="A well-written blog post "
36
+ "in markdown format, ready for publication, "
37
+ "each section should have 2 or 3 paragraphs.",
38
+ agent=blog_writer,
39
+ )
40
+
41
+ # Task for Editor
42
+ edit_task = Task(
43
+ description=("Proofread the given blog post for "
44
+ "grammatical errors and "
45
+ "alignment with the brand's voice."),
46
+ expected_output="A well-written blog post in markdown format, "
47
+ "ready for publication, "
48
+ "each section should have 2 or 3 paragraphs.",
49
+ agent=editor
50
+ )