Upload article4.py
Browse files- article4.py +110 -0
article4.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from crewai import Agent, Task, Crew, LLM
|
| 4 |
+
|
| 5 |
+
# Set your Gemini AI API key and model
|
| 6 |
+
gemini_api_key = 'AIzaSyAC_i-I9uCP2UP14H89uigWP7MDM2xQno8' # Replace with your actual Gemini API key
|
| 7 |
+
os.environ["GEMINI_API_KEY"] = gemini_api_key
|
| 8 |
+
|
| 9 |
+
# Initialize the LLM instance
|
| 10 |
+
my_llm = LLM(
|
| 11 |
+
api_key=gemini_api_key, # Replace with your actual API key
|
| 12 |
+
model="gemini/gemini-pro"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Define your agents with roles, goals, and backstory
|
| 16 |
+
planner = Agent(
|
| 17 |
+
role="Content Planner",
|
| 18 |
+
goal="Plan engaging and factually accurate content on {topic}",
|
| 19 |
+
backstory="You're working on planning a blog article "
|
| 20 |
+
"about the topic: {topic}. "
|
| 21 |
+
"You collect information that helps the "
|
| 22 |
+
"audience learn something and make informed decisions. "
|
| 23 |
+
"Your work is the basis for the Content Writer to write an article on this topic.",
|
| 24 |
+
llm=my_llm, # Use the LLM instance here
|
| 25 |
+
allow_delegation=False,
|
| 26 |
+
verbose=True
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
writer = Agent(
|
| 30 |
+
role="Content Writer",
|
| 31 |
+
goal="Write insightful and factually accurate opinion piece about the topic: {topic}",
|
| 32 |
+
backstory="You're writing a new opinion piece about the topic: {topic}. "
|
| 33 |
+
"You base your writing on the work of the Content Planner, "
|
| 34 |
+
"who provides an outline and relevant context about the topic. "
|
| 35 |
+
"You follow the main objectives and direction of the outline provided by the Content Planner.",
|
| 36 |
+
llm=my_llm, # Use the LLM instance here
|
| 37 |
+
allow_delegation=False,
|
| 38 |
+
verbose=True
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
editor = Agent(
|
| 42 |
+
role="Editor",
|
| 43 |
+
goal="Edit a given blog post to align with the writing style of the organization.",
|
| 44 |
+
backstory="You are an editor who reviews blog posts from the Content Writer to ensure they follow journalistic best practices, provide balanced viewpoints, "
|
| 45 |
+
"and avoid controversial topics when possible.",
|
| 46 |
+
llm=my_llm, # Use the LLM instance here
|
| 47 |
+
allow_delegation=False,
|
| 48 |
+
verbose=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Define your tasks with descriptions, expected output, and the associated agent
|
| 52 |
+
plan = Task(
|
| 53 |
+
description=(
|
| 54 |
+
"1. Prioritize the latest trends, key players, "
|
| 55 |
+
"and noteworthy news on {topic}.\n"
|
| 56 |
+
"2. Identify the target audience, considering "
|
| 57 |
+
"their interests and pain points.\n"
|
| 58 |
+
"3. Develop a detailed content outline including "
|
| 59 |
+
"an introduction, key points, and a call to action.\n"
|
| 60 |
+
"4. Include SEO keywords and relevant data or sources."
|
| 61 |
+
),
|
| 62 |
+
expected_output="A comprehensive content plan document "
|
| 63 |
+
"with an outline, audience analysis, SEO keywords, and resources.",
|
| 64 |
+
agent=planner,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
write = Task(
|
| 68 |
+
description=(
|
| 69 |
+
"1. Use the content plan to craft a compelling "
|
| 70 |
+
"blog post on {topic}.\n"
|
| 71 |
+
"2. Incorporate SEO keywords naturally.\n"
|
| 72 |
+
"3. Ensure the post is structured with an engaging introduction, insightful body, and a summarizing conclusion.\n"
|
| 73 |
+
"4. Proofread for grammatical errors and alignment with the brand's voice."
|
| 74 |
+
),
|
| 75 |
+
expected_output="A well-written blog post in markdown format, "
|
| 76 |
+
"ready for publication, each section should have 2 or 3 paragraphs.",
|
| 77 |
+
agent=writer,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
edit = Task(
|
| 81 |
+
description=("Proofread the given blog post for "
|
| 82 |
+
"grammatical errors and alignment with the brand's voice."),
|
| 83 |
+
expected_output="A well-written blog post in markdown format, "
|
| 84 |
+
"ready for publication, each section should have 2 or 3 paragraphs.",
|
| 85 |
+
agent=editor
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
# Create the crew with your agents and tasks
|
| 89 |
+
article_crew = Crew(
|
| 90 |
+
agents=[planner, writer, editor],
|
| 91 |
+
tasks=[plan, write, edit],
|
| 92 |
+
manager_llm=False,
|
| 93 |
+
verbose=True
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# Streamlit interface for user input
|
| 97 |
+
st.title('Content Creation for Blog Articles')
|
| 98 |
+
st.write("Enter the topic for your blog article:")
|
| 99 |
+
|
| 100 |
+
# Input for the topic from the user
|
| 101 |
+
topic = st.text_input("Topic", "Artificial Intelligence")
|
| 102 |
+
|
| 103 |
+
if st.button('Generate Article'):
|
| 104 |
+
# Run the crew with the topic
|
| 105 |
+
result = article_crew.kickoff(inputs={"topic": topic})
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# Display the results as markdown on the Streamlit page
|
| 109 |
+
st.markdown(result)
|
| 110 |
+
|