Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
result = content_crew.run()
|
| 74 |
-
|
| 75 |
-
# Debugging: Print the result to ensure it is not empty
|
| 76 |
-
print("DEBUG: Result received")
|
| 77 |
-
print(result)
|
| 78 |
-
|
| 79 |
-
st.write("## Here is your Content Plan")
|
| 80 |
-
st.write('-------------------------------')
|
| 81 |
-
st.write(result)
|
| 82 |
-
else:
|
| 83 |
-
st.error("Please enter a topic.")
|
| 84 |
-
|
|
|
|
| 1 |
+
class ContentCrew:
|
| 2 |
+
def __init__(self, topic):
|
| 3 |
+
self.topic = topic
|
| 4 |
+
|
| 5 |
+
def run(self):
|
| 6 |
+
agents = ContentAgents()
|
| 7 |
+
tasks = ContentTasks()
|
| 8 |
+
|
| 9 |
+
planner_agent = agents.planner_agent(self.topic)
|
| 10 |
+
researcher_agent = agents.researcher_agent(self.topic)
|
| 11 |
+
writer_agent = agents.writer_agent(self.topic)
|
| 12 |
+
|
| 13 |
+
planner_task = tasks.planner_task(planner_agent, self.topic)
|
| 14 |
+
researcher_task = tasks.researcher_task(researcher_agent, self.topic)
|
| 15 |
+
writer_task = tasks.writer_task(writer_agent, self.topic)
|
| 16 |
+
|
| 17 |
+
crew = Crew(
|
| 18 |
+
agents=[planner_agent, researcher_agent, writer_agent],
|
| 19 |
+
tasks=[planner_task, researcher_task, writer_task],
|
| 20 |
+
verbose=True
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
result = crew.kickoff()
|
| 24 |
+
|
| 25 |
+
# Debugging: Print the structure and content of the result
|
| 26 |
+
print("DEBUG: Result structure and content")
|
| 27 |
+
print(json.dumps(result, indent=2))
|
| 28 |
+
|
| 29 |
+
return result
|
| 30 |
+
|
| 31 |
+
def display_result(result):
|
| 32 |
+
st.write("## Research on Topic")
|
| 33 |
+
st.write('-------------------------------')
|
| 34 |
+
|
| 35 |
+
# Debugging: Print the result to ensure it has content
|
| 36 |
+
st.write("DEBUG: Displaying result")
|
| 37 |
+
st.json(result) # Streamlit's way to print JSON data
|
| 38 |
+
|
| 39 |
+
if 'content_plan' in result:
|
| 40 |
+
st.write("### Content Plan")
|
| 41 |
+
st.write(result['content_plan'])
|
| 42 |
+
|
| 43 |
+
if 'references' in result:
|
| 44 |
+
st.write("### References")
|
| 45 |
+
for ref in result['references']:
|
| 46 |
+
st.markdown(f"- [{ref['title']}]({ref['link']}): {ref['snippet']}")
|
| 47 |
+
|
| 48 |
+
if 'images' in result:
|
| 49 |
+
st.write("### Images")
|
| 50 |
+
for image in result['images']:
|
| 51 |
+
st.image(image['url'], caption=image['description'])
|
| 52 |
+
|
| 53 |
+
# Streamlit UI
|
| 54 |
+
st.title('Content Creator Chatbot')
|
| 55 |
+
st.write('-------------------------------')
|
| 56 |
+
|
| 57 |
+
topic = st.text_input("What topic do you want to write about?")
|
| 58 |
+
|
| 59 |
+
if st.button('Generate Content'):
|
| 60 |
+
if topic:
|
| 61 |
+
content_crew = ContentCrew(topic)
|
| 62 |
+
result = content_crew.run()
|
| 63 |
+
|
| 64 |
+
# Debugging: Print the result to ensure it is not empty
|
| 65 |
+
print("DEBUG: Result received")
|
| 66 |
+
print(result)
|
| 67 |
+
|
| 68 |
+
st.write("## Here is your Content Plan")
|
| 69 |
+
st.write('-------------------------------')
|
| 70 |
+
display_result(result)
|
| 71 |
+
else:
|
| 72 |
+
st.error("Please enter a topic.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|