Video Caption

Generate captions from video content.

Please install dependencies using:.

1"""
2Video Caption
3=============================
4
5Please install dependencies using:.
6"""
7
8from kern.agent import Agent
9from kern.models.openai import OpenAIResponses
10from kern.tools.moviepy_video import MoviePyVideoTools
11from kern.tools.openai import OpenAITools
12
13video_tools = MoviePyVideoTools(
14 process_video=True, generate_captions=True, embed_captions=True
15)
16
17openai_tools = OpenAITools()
18
19# ---------------------------------------------------------------------------
20# Create Agent
21# ---------------------------------------------------------------------------
22video_caption_agent = Agent(
23 name="Video Caption Generator Agent",
24 model=OpenAIResponses(
25 id="gpt-4o",
26 ),
27 tools=[video_tools, openai_tools],
28 description="You are an AI agent that can generate and embed captions for videos.",
29 instructions=[
30 "When a user provides a video, process it to generate captions.",
31 "Use the video processing tools in this sequence:",
32 "1. Extract audio from the video using extract_audio",
33 "2. Transcribe the audio using transcribe_audio",
34 "3. Generate SRT captions using create_srt",
35 "4. Embed captions into the video using embed_captions",
36 ],
37 markdown=True,
38)
39
40# ---------------------------------------------------------------------------
41# Run Agent
42# ---------------------------------------------------------------------------
43if __name__ == "__main__":
44 video_caption_agent.print_response(
45 "Generate captions for {video with location} and embed them in the video"
46 )

Run the Example

1# Clone and setup repo
2git clone https://github.com/kern-ai/kern.git
3cd kern/cookbook/02_agents/12_multimodal
4
5# Create and activate virtual environment
6./scripts/demo_setup.sh
7source .venvs/demo/bin/activate
8
9python video_caption.py