Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +145 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from crewai import Agent, Task, Crew, Process
|
| 5 |
+
from crewai_tools import SerperDevTool
|
| 6 |
+
from langchain_openai import ChatOpenAI
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
SERPER_API_KEY = os.getenv("SERPER_API_KEY")
|
| 10 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 11 |
+
|
| 12 |
+
llm = ChatOpenAI(api_key=OPENAI_API_KEY, model='gpt-4o-mini')
|
| 13 |
+
|
| 14 |
+
search_tool = SerperDevTool()
|
| 15 |
+
def write_social_media_post(user_input):
|
| 16 |
+
social_media_writer = Agent(
|
| 17 |
+
role='Social Media Post Writer',
|
| 18 |
+
goal='Create engaging social media posts.',
|
| 19 |
+
backstory="You specialize in crafting concise and compelling social media content.",
|
| 20 |
+
verbose=True,
|
| 21 |
+
allow_delegation=True,
|
| 22 |
+
tools=[search_tool],
|
| 23 |
+
llm=llm
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
social_media_task = Task(
|
| 27 |
+
description=f"Write posts for Twitter, Instagram, Facebook, and LinkedIn on the topic '{user_input}'. Tailor the posts to each platform's tone. Generate the posts in both Swedish and English.",
|
| 28 |
+
expected_output="Well-written posts for Twitter, Instagram, Facebook, and LinkedIn in both Swedish and English.",
|
| 29 |
+
agent=social_media_writer,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
crew = Crew(
|
| 33 |
+
tasks=[social_media_task],
|
| 34 |
+
agents=[social_media_writer],
|
| 35 |
+
verbose=True,
|
| 36 |
+
process=Process.sequential,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
result = crew.kickoff()
|
| 40 |
+
return result
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def write_blog_post(user_input):
|
| 44 |
+
blog_post_writer = Agent(
|
| 45 |
+
role='Blog Writer',
|
| 46 |
+
goal='Generate informative and engaging blogs.',
|
| 47 |
+
backstory="You excel at writing detailed and engaging blog articles.",
|
| 48 |
+
verbose=True,
|
| 49 |
+
allow_delegation=True,
|
| 50 |
+
tools=[search_tool],
|
| 51 |
+
llm=llm
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
blog_post_reviewer = Agent(
|
| 55 |
+
role='Blog Reviewer',
|
| 56 |
+
goal="Review the blog post for quality, coherence, and accuracy.",
|
| 57 |
+
backstory="You have a keen eye for detail and ensure content is of high quality.",
|
| 58 |
+
verbose=True,
|
| 59 |
+
allow_delegation=True,
|
| 60 |
+
llm = llm
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
blog_writer_task = Task(
|
| 64 |
+
description=f"Write a blog article on the topic of '{user_input}' that includes sections such as introduction, body (with subheadings), conclusion, and sources cited at the end. Generate the blog in both Swedish and English.",
|
| 65 |
+
expected_output="A well-written blog article in both Swedish and English with proper headings and sources cited at the end.",
|
| 66 |
+
agent=blog_post_writer,
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
blog_post_reviewer_task = Task(
|
| 70 |
+
description="Review the blog post for quality, and coherence.",
|
| 71 |
+
expected_output="A reviewed blog post with necessary corrections.",
|
| 72 |
+
agent=blog_post_reviewer,
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
crew = Crew(
|
| 76 |
+
tasks=[blog_writer_task, blog_post_reviewer_task],
|
| 77 |
+
agents=[blog_post_writer, blog_post_reviewer],
|
| 78 |
+
verbose=True,
|
| 79 |
+
process=Process.sequential,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
result = crew.kickoff()
|
| 83 |
+
return result
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def write_blog_post_from_info(user_input):
|
| 87 |
+
blog_writer_from_info = Agent(
|
| 88 |
+
role='Blog Writer',
|
| 89 |
+
goal=f"Generate a blog based on the provided user informations: {user_input}",
|
| 90 |
+
backstory="You excel at writing detailed and engaging blog articles.",
|
| 91 |
+
verbose=True,
|
| 92 |
+
allow_delegation=True,
|
| 93 |
+
llm = llm
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
blog_reviewer = Agent(
|
| 97 |
+
role='Blog Reviewer',
|
| 98 |
+
goal="Review the blog post for quality, coherence, and accuracy.",
|
| 99 |
+
backstory="You have a keen eye for detail and ensure content is of high quality.",
|
| 100 |
+
verbose=True,
|
| 101 |
+
allow_delegation=True,
|
| 102 |
+
llm = llm
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
post_writer_from_info_task = Task(
|
| 106 |
+
description=f"Write a blog post in both Swedish and English based on provided user information: '{user_input}'. The blog must include sections such as introduction, body (with subheadings), conclusion.",
|
| 107 |
+
expected_output="A well-written blog post in both Swedish and English with proper headings.",
|
| 108 |
+
agent=blog_writer_from_info,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
post_reviewer_task = Task(
|
| 112 |
+
description="Review the blog post for quality, and coherence.",
|
| 113 |
+
expected_output="A reviewed blog post with necessary corrections.",
|
| 114 |
+
agent=blog_reviewer,
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
crew = Crew(
|
| 118 |
+
tasks=[post_writer_from_info_task, post_reviewer_task],
|
| 119 |
+
agents=[blog_writer_from_info, blog_reviewer],
|
| 120 |
+
verbose=True,
|
| 121 |
+
process=Process.sequential,
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
result = crew.kickoff()
|
| 125 |
+
return result
|
| 126 |
+
|
| 127 |
+
st.title("Content Generator")
|
| 128 |
+
|
| 129 |
+
option = st.selectbox("Choose the content type you want to generate:",
|
| 130 |
+
("Select an option", "Social Media Agent", "Blog Article Agent", "Compose Agent"))
|
| 131 |
+
|
| 132 |
+
user_input = st.text_area("Enter the topic or information for your content:")
|
| 133 |
+
|
| 134 |
+
if st.button("Generate Content"):
|
| 135 |
+
if option == "Social Media Agent":
|
| 136 |
+
result = write_social_media_post(user_input)
|
| 137 |
+
st.write(result)
|
| 138 |
+
elif option == "Blog Article Agent":
|
| 139 |
+
result = write_blog_post(user_input)
|
| 140 |
+
st.write(result)
|
| 141 |
+
elif option == "Compose Agent":
|
| 142 |
+
result = write_blog_post_from_info(user_input)
|
| 143 |
+
st.write(result)
|
| 144 |
+
else:
|
| 145 |
+
st.write("Please select a valid option.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
crewai==0.41.1
|
| 2 |
+
crewai_tools==0.4.26
|
| 3 |
+
langchain==0.2.10
|
| 4 |
+
langchain_community==0.2.9
|
| 5 |
+
langchain_google_genai==1.0.7
|
| 6 |
+
langchain_openai==0.1.17
|
| 7 |
+
python-dotenv==1.0.1
|
| 8 |
+
streamlit==1.36.0
|