SwatGarg commited on
Commit
3d0d20d
·
verified ·
1 Parent(s): db236f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -84
app.py CHANGED
@@ -1,84 +1,72 @@
1
- # app.py
2
- import streamlit as st
3
- from crewai import Crew
4
- from textwrap import dedent
5
- from agents import ContentAgents
6
- from tasks import ContentTasks
7
- from dotenv import load_dotenv
8
- import json
9
-
10
- load_dotenv()
11
-
12
- class ContentCrew:
13
- def __init__(self, topic):
14
- self.topic = topic
15
-
16
- def run(self):
17
- agents = ContentAgents()
18
- tasks = ContentTasks()
19
-
20
- planner_agent = agents.planner_agent(self.topic)
21
- researcher_agent = agents.researcher_agent(self.topic)
22
- writer_agent = agents.writer_agent(self.topic)
23
-
24
- planner_task = tasks.planner_task(planner_agent, self.topic)
25
- researcher_task = tasks.researcher_task(researcher_agent, self.topic)
26
- writer_task = tasks.writer_task(writer_agent, self.topic)
27
-
28
- crew = Crew(
29
- agents=[planner_agent, researcher_agent, writer_agent],
30
- tasks=[planner_task, researcher_task, writer_task],
31
- verbose=True
32
- )
33
-
34
- result = crew.kickoff()
35
-
36
- # Debugging: Print the structure and content of the result
37
- print("DEBUG: Result structure and content")
38
- print(json.dumps(result, indent=2))
39
-
40
- return result
41
-
42
- def display_result(result):
43
- st.write("## Research on Topic")
44
- st.write('-------------------------------')
45
-
46
- # Debugging: Print the result to ensure it has content
47
- print("DEBUG: Displaying result")
48
- print(result)
49
-
50
- if 'content_plan' in result:
51
- st.write("### Content Plan")
52
- st.write(result['content_plan'])
53
-
54
- if 'references' in result:
55
- st.write("### References")
56
- for ref in result['references']:
57
- st.markdown(f"- [{ref['title']}]({ref['link']}): {ref['snippet']}")
58
-
59
- if 'images' in result:
60
- st.write("### Images")
61
- for image in result['images']:
62
- st.image(image['url'], caption=image['description'])
63
-
64
- # Streamlit UI
65
- st.title('Content Creator Chatbot')
66
- st.write('-------------------------------')
67
-
68
- topic = st.text_input("What topic do you want to write about?")
69
-
70
- if st.button('Generate Content'):
71
- if topic:
72
- content_crew = ContentCrew(topic)
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.")