Spaces:
Build error
Build error
File size: 2,594 Bytes
354a414 175e903 354a414 dd025db 354a414 3d0d20d 00db182 3d0d20d 9640348 3d0d20d 9640348 3d0d20d 9640348 3d0d20d 684a9de 00db182 9640348 3d0d20d 73c75f4 f9ea1eb bbeb693 3d0d20d 599bf2c |
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 74 75 76 77 78 79 80 81 82 83 84 85 |
from crewai import Crew
from textwrap import dedent
from agents import ContentAgents
from tasks import ContentTasks
from dotenv import load_dotenv
import json
import streamlit as st
from image_search_tool import image_search_tool
load_dotenv()
class ContentCrew:
def __init__(self, topic):
self.topic = topic
def run(self):
agents = ContentAgents()
tasks = ContentTasks()
planner_agent = agents.planner_agent(self.topic)
researcher_agent = agents.researcher_agent(self.topic)
writer_agent = agents.writer_agent(self.topic)
planner_task = tasks.planner_task(planner_agent, self.topic)
researcher_task = tasks.researcher_task(researcher_agent, self.topic)
writer_task = tasks.writer_task(writer_agent, self.topic)
crew = Crew(
agents=[planner_agent, researcher_agent, writer_agent],
tasks=[planner_task, researcher_task, writer_task],
verbose=True
)
result = crew.kickoff()
# Debugging: Print the structure and content of the result
print("DEBUG: Result structure and content")
print(json.dumps(result, indent=2))
return result
# Function to display the result in Streamlit
def display_result(result):
st.write("## Research on Topic")
st.write('-------------------------------')
if 'content_plan' in result:
st.write("### Content Plan")
st.write(result['content_plan'])
if 'references' in result:
st.write("### References")
for ref in result['references']:
st.markdown(f"- [{ref['title']}]({ref['link']}): {ref['snippet']}")
if 'images' in result:
st.write("### Images")
for idx, image in enumerate(result['images']):
img_path = f"image_{idx}.png"
WebSearchTools.download_image(image, img_path)
st.image(img_path, caption=f"Image {idx+1}")
if 'content' in result:
st.markdown(result['content'])
# Streamlit UI
st.title('Content Creator Chatbot')
st.write('-------------------------------')
topic = st.text_input("What topic do you want to write about?")
if st.button('Generate Content'):
if topic:
# Instantiate ContentCrew and run
content_crew = ContentCrew(topic)
result = content_crew.run()
# Display the results
st.write(result)
image_search_tool(topic)
image_path = 'images/image_1.jpg'
st.image(image_path, caption='Image1', use_column_width=True)
else:
st.error("Please enter a topic.") |