Spaces:
Sleeping
Sleeping
Prudvireddy
commited on
Commit
•
76466eb
1
Parent(s):
9b6561b
Update agents.py
Browse files
agents.py
CHANGED
@@ -1,147 +1,171 @@
|
|
1 |
-
from crewai import Agent, Task
|
2 |
-
from
|
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 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
#
|
108 |
-
# description=
|
109 |
-
# expected_output="
|
110 |
-
#
|
111 |
-
#
|
112 |
-
|
113 |
-
#
|
114 |
-
#
|
115 |
-
|
116 |
-
#
|
117 |
-
#
|
118 |
-
#
|
119 |
-
#
|
120 |
-
#
|
121 |
-
|
122 |
-
#
|
123 |
-
#
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from crewai import Agent, Task
|
2 |
+
from langchain_groq import ChatGroq
|
3 |
+
from tools import create_video_from_images_and_audio, image_generator, speech_generator, wiki_tool
|
4 |
+
import os
|
5 |
+
|
6 |
+
def get_agents_and_tasks(groq_api_key):
|
7 |
+
os.environ['GROQ_API_KEY'] = groq_api_key
|
8 |
+
llm = ChatGroq(model='llama3-70b-8192', temperature=0.6, max_tokens=1024, api_key=groq_api_key)
|
9 |
+
|
10 |
+
script_agent = Agent(
|
11 |
+
role='Senior Content Writer',
|
12 |
+
goal='Craft engaging, concise, and informative narrations for YouTube short videos',
|
13 |
+
backstory="""As a seasoned content writer, you excel at breaking down complex topics into captivating narratives that educate and entertain audiences. Your expertise lies in writing concise, attention-grabbing scripts for YouTube short videos.""",
|
14 |
+
verbose=True,
|
15 |
+
llm=llm,
|
16 |
+
allow_delegation=False
|
17 |
+
)
|
18 |
+
|
19 |
+
image_descriptive_agent = Agent(
|
20 |
+
role='Visual Storyteller',
|
21 |
+
goal='Design stunning, contextually relevant visuals for YouTube short videos',
|
22 |
+
backstory='With a keen eye for visual storytelling, you create compelling imagery that elevates the narrative and captivates the audience. You will ',
|
23 |
+
verbose=True,
|
24 |
+
llm=llm,
|
25 |
+
allow_delegation=False
|
26 |
+
)
|
27 |
+
|
28 |
+
# img_speech_generating_agent = Agent(
|
29 |
+
# role='Multimedia Content Creator',
|
30 |
+
# goal='Generate high-quality images and speeches for YouTube short videos one after another based on provided descriptions.',
|
31 |
+
# backstory='As a multimedia expert, you excel at creating engaging multimedia content that brings stories to life.',
|
32 |
+
# verbose=True,
|
33 |
+
# llm=llm,
|
34 |
+
# allow_delegation=False
|
35 |
+
# )
|
36 |
+
|
37 |
+
img_speech_generating_agent = Agent(
|
38 |
+
role='Multimedia Content Creator',
|
39 |
+
goal='Generate high-quality images and speeches for YouTube short videos based on provided script',
|
40 |
+
backstory='As a multimedia expert, you excel at creating engaging multimedia content that brings stories to life.',
|
41 |
+
verbose=True,
|
42 |
+
llm=llm,
|
43 |
+
allow_delegation=False
|
44 |
+
)
|
45 |
+
|
46 |
+
editor = Agent(
|
47 |
+
role = 'Video editor',
|
48 |
+
goal = 'To make a video for YouTube shorts.',
|
49 |
+
backstory = "You are a video editor working for a YouTube creator",
|
50 |
+
verbose=True,
|
51 |
+
llm=llm,
|
52 |
+
allow_delegation = False,
|
53 |
+
tools = [create_video_from_images_and_audio]
|
54 |
+
)
|
55 |
+
|
56 |
+
content_generation_task = Task(
|
57 |
+
description='Generate engaging and informative content on the topic: {topic}. Use the provided tool, only if you have no idea about the given topic.',
|
58 |
+
expected_output="""Good corpus of text about: {topic}""",
|
59 |
+
agent=script_agent,
|
60 |
+
tools = [wiki_tool]
|
61 |
+
)
|
62 |
+
|
63 |
+
story_writing_task = Task(
|
64 |
+
description='Write an engaging narration for a YouTube short video on the topic: {topic}',
|
65 |
+
expected_output="""A short paragraph suitable for narrating in five seconds that provides an immersive experience to the audience. Follow the below example for output length and format.
|
66 |
+
|
67 |
+
**Example input:**
|
68 |
+
Ancient Wonders of the World
|
69 |
+
|
70 |
+
**Output format:**
|
71 |
+
Embark on a journey through time and marvel at the ancient wonders of the world!
|
72 |
+
From the majestic Great Pyramid of Giza, symbolizing the ingenuity of ancient Egypt,
|
73 |
+
to the Hanging Gardens of Babylon, an oasis of lush beauty amidst ancient Mesopotamia's arid landscape.
|
74 |
+
These remarkable structures continue to intrigue and inspire awe, reminding us of humanity's enduring quest for greatness.
|
75 |
+
""",
|
76 |
+
agent=script_agent
|
77 |
+
)
|
78 |
+
|
79 |
+
|
80 |
+
img_text_task = Task(
|
81 |
+
description='Given the narration, visually describe each sentence in the narration which will be used as a prompt for image generation.',
|
82 |
+
expected_output="""Sentences encoded in <narration> and <image> tags. Follow the example below for the output format.
|
83 |
+
|
84 |
+
**Example input:**
|
85 |
+
Embark on a journey through time and marvel at the ancient wonders of the world! From the majestic Great Pyramid of Giza, symbolizing the ingenuity of ancient Egypt, to the Hanging Gardens of Babylon, an oasis of lush beauty amidst ancient Mesopotamia's arid landscape. These remarkable structures continue to intrigue and inspire awe, reminding us of humanity's enduring quest for greatness.
|
86 |
+
|
87 |
+
**Output format:**
|
88 |
+
|
89 |
+
<narration>Embark on a journey through time and marvel at the ancient wonders of the world!</narration>
|
90 |
+
<image>A breathtaking view of various ancient wonders, showcasing their grandeur and mystery.</image>
|
91 |
+
|
92 |
+
<narration>From the majestic Great Pyramid of Giza, symbolizing the ingenuity of ancient Egypt,</narration>
|
93 |
+
<image>The majestic Great Pyramid of Giza, standing tall against the desert backdrop, a testament to ancient engineering.</image>
|
94 |
+
|
95 |
+
<narration>to the Hanging Gardens of Babylon, an oasis of lush beauty amidst ancient Mesopotamia's arid landscape,</narration>
|
96 |
+
<image>The Hanging Gardens of Babylon, lush greenery cascading from terraced gardens, amidst the arid Mesopotamian landscape.</image>
|
97 |
+
|
98 |
+
<narration>These remarkable structures continue to intrigue and inspire awe, reminding us of humanity's enduring quest for greatness.</narration>
|
99 |
+
<image>Visitors captivated by the beauty and historical significance of these ancient marvels, exploring and marveling.</image>
|
100 |
+
""",
|
101 |
+
agent=image_descriptive_agent,
|
102 |
+
context=[story_writing_task]
|
103 |
+
)
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
# process_script_task = Task(
|
108 |
+
# description="Extract text for image and speech generation from a provided script.",
|
109 |
+
# expected_output="A dictionary containing lists of texts for image generation and speech generation.",
|
110 |
+
# agent=ScriptSynthesizer
|
111 |
+
# )
|
112 |
+
|
113 |
+
# img_generation_task = Task(
|
114 |
+
# description='Given the input generate images for sequence of sentence enclosed in <image> tag.',
|
115 |
+
# expected_output="""Acknowledgement of image generation""",
|
116 |
+
# tools = [image_generator],
|
117 |
+
# context = [img_text_task],
|
118 |
+
# # async_execution=True,
|
119 |
+
# agent=img_speech_generating_agent
|
120 |
+
# )
|
121 |
+
|
122 |
+
# speech_generation_task = Task(
|
123 |
+
# description='Given the input generate speech for each sentence enclosed in <narration> tag.',
|
124 |
+
# expected_output="""Acknowledgement of speech generation""",
|
125 |
+
# tools = [speech_generator],
|
126 |
+
# context = [img_text_task],
|
127 |
+
# # async_execution=True,
|
128 |
+
# agent=img_speech_generating_agent
|
129 |
+
# )
|
130 |
+
img_generation_task = Task(
|
131 |
+
description='Given the script, use the given tool to generate images',
|
132 |
+
expected_output="""Acknowledgement of image generation""",
|
133 |
+
tools = [image_generator],
|
134 |
+
context = [img_text_task],
|
135 |
+
# async_execution=True,
|
136 |
+
agent=img_speech_generating_agent
|
137 |
+
)
|
138 |
+
|
139 |
+
speech_generation_task = Task(
|
140 |
+
description='Given the script, use the given tool to generate speech',
|
141 |
+
expected_output="""Acknowledgement of speech generation""",
|
142 |
+
tools = [speech_generator],
|
143 |
+
context = [img_text_task],
|
144 |
+
# async_execution=True,
|
145 |
+
agent=img_speech_generating_agent
|
146 |
+
)
|
147 |
+
|
148 |
+
make_video_task = Task(
|
149 |
+
description = 'Create video using images and speeches from the forlders "outpus/images" and "outputs/speeches"',
|
150 |
+
expected_output = "output video path",
|
151 |
+
agent=editor,
|
152 |
+
context = [img_generation_task, speech_generation_task]
|
153 |
+
)
|
154 |
+
|
155 |
+
agents = [
|
156 |
+
script_agent,
|
157 |
+
image_descriptive_agent,
|
158 |
+
img_speech_generating_agent,
|
159 |
+
editor
|
160 |
+
]
|
161 |
+
|
162 |
+
tasks = [
|
163 |
+
content_generation_task,
|
164 |
+
story_writing_task,
|
165 |
+
img_text_task,
|
166 |
+
img_generation_task,
|
167 |
+
speech_generation_task,
|
168 |
+
make_video_task
|
169 |
+
]
|
170 |
+
|
171 |
+
return agents, tasks
|