Spaces:
Sleeping
Sleeping
Initial Commit
Browse files- agents.py +53 -0
- crew.py +90 -0
- requirements.txt +5 -0
- tasks.py +30 -0
- tools.py +8 -0
agents.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai import Agent
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from langchain_groq import ChatGroq
|
| 4 |
+
import os
|
| 5 |
+
from tools import tool
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
llm = ChatGroq(
|
| 10 |
+
model = "groq/llama-3.1-8b-instant",
|
| 11 |
+
verbose = True,
|
| 12 |
+
temperature = 0.5,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
## Creating a researcher agent who is responsible to dig the details of particular
|
| 16 |
+
## topic in detail
|
| 17 |
+
|
| 18 |
+
News_Researcher = Agent(
|
| 19 |
+
role = "Senior Researcher",
|
| 20 |
+
goal = "uncover ground breaking Technologies in {topic}",
|
| 21 |
+
verbose = True,
|
| 22 |
+
memory = True,
|
| 23 |
+
backstory = (
|
| 24 |
+
"""
|
| 25 |
+
Driven by curiosity, you are at forefront of the innovation,
|
| 26 |
+
eager to explore and share knowledge that could change the world
|
| 27 |
+
"""
|
| 28 |
+
),
|
| 29 |
+
tools = [tool],
|
| 30 |
+
llm = llm,
|
| 31 |
+
allow_delegation = True,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
## Creating a writer agent with custom tools responsible in writing news blog
|
| 35 |
+
|
| 36 |
+
News_Writer = Agent(
|
| 37 |
+
role = 'Writer',
|
| 38 |
+
goal = 'Narrate compelling tech stories about {topic}',
|
| 39 |
+
verbose = True,
|
| 40 |
+
memory = True,
|
| 41 |
+
backstory = (
|
| 42 |
+
"""
|
| 43 |
+
With a Flair for simplifying complex topics, you craft engaging
|
| 44 |
+
narratives that captivate and educate, bringing new discoveries to light
|
| 45 |
+
in an accessible manner.
|
| 46 |
+
"""
|
| 47 |
+
),
|
| 48 |
+
tools = [tool],
|
| 49 |
+
llm = llm,
|
| 50 |
+
allow_delegations = False
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
crew.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from crewai import Crew, Process
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from agents import News_Researcher, News_Writer
|
| 5 |
+
from tasks import Research_task, Write_task
|
| 6 |
+
from tools import tool
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="CrewAI Article Generator", page_icon="📝", layout="wide")
|
| 9 |
+
|
| 10 |
+
st.markdown("""
|
| 11 |
+
<style>
|
| 12 |
+
.reportview-container {
|
| 13 |
+
background: #f0f2f6
|
| 14 |
+
}
|
| 15 |
+
.main {
|
| 16 |
+
background: #00000;
|
| 17 |
+
padding: 3rem;
|
| 18 |
+
border-radius: 10px;
|
| 19 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 20 |
+
}
|
| 21 |
+
.stButton>button {
|
| 22 |
+
background-color: #0000;
|
| 23 |
+
color: white;
|
| 24 |
+
border-radius: 5px;
|
| 25 |
+
}
|
| 26 |
+
.stTextInput>div>div>input {
|
| 27 |
+
border-radius: 5px;
|
| 28 |
+
}
|
| 29 |
+
.sidebar .sidebar-content {
|
| 30 |
+
background-color: #f8f9fa;
|
| 31 |
+
}
|
| 32 |
+
</style>
|
| 33 |
+
""", unsafe_allow_html=True)
|
| 34 |
+
|
| 35 |
+
st.sidebar.title("📊 API Configuration")
|
| 36 |
+
st.sidebar.markdown("Enter your API keys below:")
|
| 37 |
+
|
| 38 |
+
serper_api_key = st.sidebar.text_input("Serper API Key", type="password")
|
| 39 |
+
groq_api_key = st.sidebar.text_input("Groq API Key", type="password")
|
| 40 |
+
|
| 41 |
+
if st.sidebar.button("Save API Keys"):
|
| 42 |
+
if serper_api_key and groq_api_key:
|
| 43 |
+
st.sidebar.success("API keys saved successfully!")
|
| 44 |
+
else:
|
| 45 |
+
st.sidebar.error("Please enter both API keys.")
|
| 46 |
+
|
| 47 |
+
st.title("📝 Culprit ")
|
| 48 |
+
st.markdown("This is an Agent which can write articles for your blog on any Topic - Have a Try")
|
| 49 |
+
|
| 50 |
+
topic = st.text_input("Enter a topic for your article:", placeholder="e.g., Space exploration, Climate change, Artificial intelligence")
|
| 51 |
+
|
| 52 |
+
if st.button("Generate Article"):
|
| 53 |
+
if not serper_api_key or not groq_api_key:
|
| 54 |
+
st.error("Please enter both API keys in the sidebar before generating an article.")
|
| 55 |
+
elif not topic:
|
| 56 |
+
st.warning("Please enter a topic before generating the article.")
|
| 57 |
+
else:
|
| 58 |
+
progress_bar = st.progress(0)
|
| 59 |
+
crew = Crew(
|
| 60 |
+
agents=[News_Researcher, News_Writer],
|
| 61 |
+
tasks=[Research_task, Write_task],
|
| 62 |
+
process=Process.sequential,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
with st.spinner(f"Researching and writing the article about '{topic}'..."):
|
| 66 |
+
progress_bar.progress(50)
|
| 67 |
+
result = crew.kickoff(inputs={'topic': topic})
|
| 68 |
+
|
| 69 |
+
progress_bar.progress(100)
|
| 70 |
+
|
| 71 |
+
st.subheader("Generated Article:")
|
| 72 |
+
|
| 73 |
+
if isinstance(result, str):
|
| 74 |
+
article_text = result
|
| 75 |
+
elif isinstance(result, dict) and 'article' in result:
|
| 76 |
+
article_text = result['article']
|
| 77 |
+
else:
|
| 78 |
+
article_text = str(result)
|
| 79 |
+
|
| 80 |
+
st.markdown(article_text)
|
| 81 |
+
|
| 82 |
+
st.download_button(
|
| 83 |
+
label="Download Article",
|
| 84 |
+
data=article_text,
|
| 85 |
+
file_name=f"{topic.replace(' ', '_').lower()}_article.txt",
|
| 86 |
+
mime="text/plain"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
st.markdown("---------")
|
| 90 |
+
st.markdown("Created using CrewAI with ❤️ by BLJP ")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
crewai
|
| 2 |
+
langchain-groq
|
| 3 |
+
load_dotenv
|
| 4 |
+
crewai_tools
|
| 5 |
+
streamlit
|
tasks.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai import Task
|
| 2 |
+
from tools import *
|
| 3 |
+
from agents import *
|
| 4 |
+
|
| 5 |
+
Research_task = Task(
|
| 6 |
+
description = (
|
| 7 |
+
'''
|
| 8 |
+
Identify the next big trend in {topic}.Focus in Identifying the pros and cons
|
| 9 |
+
and the overall narrative.Your final report should clearly articulate the key points,
|
| 10 |
+
its market opportunities, and potential risks.
|
| 11 |
+
'''
|
| 12 |
+
),
|
| 13 |
+
expected_output = 'A Comprehensive 13 paragraphs long report on the latest AI Trends',
|
| 14 |
+
tools = [tool],
|
| 15 |
+
agent = News_Researcher,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
Write_task = Task(
|
| 19 |
+
description = (
|
| 20 |
+
'''
|
| 21 |
+
Compose an insightful article on {topic}.Focus on the latest trends
|
| 22 |
+
and how it's impacting the industry.This article should be easy to understand,engaging and positive.
|
| 23 |
+
'''
|
| 24 |
+
),
|
| 25 |
+
expected_output = 'A paragraph article on {topic} advancements in around 12 to 14 paragraphs formatted as markdown',
|
| 26 |
+
tools = [tool],
|
| 27 |
+
agent = News_Writer,
|
| 28 |
+
async_execution = False,
|
| 29 |
+
output_file = 'new-blog-post.md'
|
| 30 |
+
)
|
tools.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from crewai_tools import SerperDevTool
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
load_dotenv()
|
| 5 |
+
|
| 6 |
+
os.environ['SERPER_API_KEY'] = os.getenv('SERPER_API_KEY')
|
| 7 |
+
|
| 8 |
+
tool = SerperDevTool()
|