Spaces:
Running
Running
Upload 2 files
Browse filesAdd necessary files for the project
- app.py +113 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Blog Editor agent implemented with LLMs and crewai framework for handling autogen agents.
|
3 |
+
|
4 |
+
It uses streamlit, crewai and openai functions to execute the task of interest.
|
5 |
+
|
6 |
+
It is based on the crewai gemini demo: https://huggingface.co/spaces/eaglelandsonce/crewaiongemini
|
7 |
+
"""
|
8 |
+
|
9 |
+
import os
|
10 |
+
import streamlit as st
|
11 |
+
from crewai import Agent, Task, Crew, Process
|
12 |
+
from langchain.tools import DuckDuckGoSearchRun
|
13 |
+
|
14 |
+
# from langchain.llms import ChatOpenAI
|
15 |
+
|
16 |
+
# set page title
|
17 |
+
st.title("Blog Editor")
|
18 |
+
st.markdown(
|
19 |
+
"This is a demo of the [CrewAI](https://crewai.co/) framework for handling autogen agents. It is based on the [CrewAI Gemini Demo](https://huggingface.co/spaces/eaglelandsonce/crewaiongemini)."
|
20 |
+
)
|
21 |
+
st.markdown(
|
22 |
+
"The goal of this demo is to show how you can use the [CrewAI](https://crewai.co/) framework to create a blog editor agent that can help you edit your blog posts. The agent is composed of two agents: a researcher and an editor. The researcher is responsible for conducting research and fact-checking the information provided in the blog post. The editor is responsible for editing the blog post and making sure it is clear, coherent, and impactful."
|
23 |
+
)
|
24 |
+
|
25 |
+
|
26 |
+
# Retrieve API Key from Environment Variable
|
27 |
+
# setup sidebar: models to choose from and API key input
|
28 |
+
with st.sidebar:
|
29 |
+
st.header("OpenAI Configuration")
|
30 |
+
st.markdown(
|
31 |
+
"For more information about the models, see [here](https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo)."
|
32 |
+
)
|
33 |
+
selected_key = st.text_input("API Key", type="password")
|
34 |
+
|
35 |
+
# Instantiate your tools: Search engine tool duckduckgo-search
|
36 |
+
search_tool = DuckDuckGoSearchRun()
|
37 |
+
|
38 |
+
# enter blogpost article
|
39 |
+
blogpost = st.text_area("Enter blogpost article here", height=200)
|
40 |
+
|
41 |
+
# check if blogpost is empty
|
42 |
+
if blogpost == "":
|
43 |
+
st.warning("Please enter a blogpost article.")
|
44 |
+
st.stop()
|
45 |
+
else:
|
46 |
+
# Define your agents with roles and goals
|
47 |
+
editor = Agent(
|
48 |
+
role="Senior Article Editor",
|
49 |
+
goal=f"Enhance the clarity, coherence, and impact of the {blogpost}, while maintaining the intended tone and voice of the writer.",
|
50 |
+
backstory="""You are a Senior Article Editor with extensive experience in editing captivating articles. Non-native English-speaking writers will
|
51 |
+
provide you with sentences from their articles, and your task is to provide feedback on the grammar, style, and overall impact of the sentences. Your
|
52 |
+
feedback should focus on enhancing the clarity, coherence, and engagement of the sentences.""",
|
53 |
+
verbose=True,
|
54 |
+
allow_delegation=False,
|
55 |
+
tools=[search_tool],
|
56 |
+
# llm=ChatOpenAI(model_name=selected_model, api_key=selected_key),
|
57 |
+
# You can pass an optional llm attribute specifying what mode you wanna use.
|
58 |
+
# It can be a local model through Ollama / LM Studio or a remote
|
59 |
+
# model like OpenAI, Mistral, Antrophic of others (https://python.langchain.com/docs/integrations/llms/)
|
60 |
+
#
|
61 |
+
# Examples:
|
62 |
+
# llm=ollama_llm # was defined above in the file
|
63 |
+
# llm=ChatOpenAI(model_name="gpt-3.5", temperature=0.7)
|
64 |
+
)
|
65 |
+
researcher = Agent(
|
66 |
+
role="Article Researcher",
|
67 |
+
goal="conduct thorough research, fact-check information, and verify the credibility of sources cited in the articles.",
|
68 |
+
backstory="""I want you to act as a news article researcher responsible for reviewing the content provided by the editor. Your task is to ensure that the
|
69 |
+
content is accurate, up-to-date, and aligned with the current day and age. You will need to fact-check information, verify sources, and identify any
|
70 |
+
outdated or irrelevant details. Additionally, you should assess the overall tone and style of the article to ensure it resonates with the intended
|
71 |
+
audience.""",
|
72 |
+
verbose=True,
|
73 |
+
allow_delegation=True,
|
74 |
+
tools=[search_tool],
|
75 |
+
# llm=ChatOpenAI(model_name=selected_model, api_key=selected_key),
|
76 |
+
# (optional) llm=ollama_llm
|
77 |
+
)
|
78 |
+
|
79 |
+
# Create tasks for your agents
|
80 |
+
task1 = Task(
|
81 |
+
description=f"""Conduct a comprehensive analysis of the provided {blogpost}.
|
82 |
+
Your analysis should include the following:
|
83 |
+
- Give a brief overview of the article
|
84 |
+
- Identify the main points of the article
|
85 |
+
- Find grammatical errors and suggest corrections
|
86 |
+
- Identify any outdated or irrelevant details and suggest corrections
|
87 |
+
|
88 |
+
You can use the search tool to find additional information. But if there is no text do not continue to the next task.
|
89 |
+
|
90 |
+
But if there is no text do not continue to the next task.
|
91 |
+
""",
|
92 |
+
agent=editor,
|
93 |
+
)
|
94 |
+
|
95 |
+
task2 = Task(
|
96 |
+
description=f"""Review the credibility of the sources cited in the {blogpost} and trustworthiness of the information provided.
|
97 |
+
do not hesitate to use the search tool to find additional information. But if there is no text do not continue to the next task.""",
|
98 |
+
agent=researcher,
|
99 |
+
)
|
100 |
+
|
101 |
+
# Instantiate your crew with a sequential process
|
102 |
+
crew = Crew(
|
103 |
+
agents=[researcher, editor],
|
104 |
+
tasks=[task2, task1],
|
105 |
+
verbose=2, # You can set it to 1 or 2 to different logging levels
|
106 |
+
# process=Process.sequential,
|
107 |
+
)
|
108 |
+
|
109 |
+
# Get your crew to work!
|
110 |
+
result = crew.kickoff()
|
111 |
+
|
112 |
+
st.write("######################")
|
113 |
+
st.markdown(result)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
crewai
|
2 |
+
langchain_openai
|
3 |
+
duckduckgo-search
|
4 |
+
ipython
|
5 |
+
black
|
6 |
+
streamlit
|
7 |
+
openai
|