Summaries, chapters, and highlights
This guide shows how you can use the Analyze API to generate summaries, chapters, and highlights from videos using pre-defined formats and optional prompts for customization.
- Summaries are concise overviews capturing the key points, adaptable into formats like paragraphs, emails, or bullet points based on your prompt.
- Chapters offer a chronological breakdown of the video, with timestamps, headlines, and summaries for each section.
- Highlights list the most significant events chronologically, including timestamps and brief descriptions.
Below are some examples of how to guide the platform in generating content tailored to your needs.
Prerequisites
-
To use the platform, you need an API key:
-
Depending on the programming language you are using, install the TwelveLabs SDK by entering one of the following commands:
-
Your video files meet the format requirements.
Complete example
This complete example shows how to create an index, upload a video, and analyze videos to generate summaries, chapters, and highlights. Ensure you replace the placeholders surrounded by <> with your values.
Step-by-step guide
Python
Node.js
Import the SDK and initialize the client
Create a client instance to interact with the TwelveLabs Video Understanding Platform.
Function call: You call the constructor of the TwelveLabs class.
Parameters:
api_key: The API key to authenticate your requests to the platform.
Return value: An object of type TwelveLabs configured for making API calls.
Create an index
Indexes store and organize your video data, allowing you to group related videos. Create one before uploading videos.
Function call: You call the indexes.create function.
Parameters:
index_name: The name of the index.models: An array specifying your model configuration.
See the Indexes page for more details on creating an index and specifying the model configuration.
Return value: An object containing, among other information, a field named id representing the unique identifier of the newly created index.
Upload videos
To perform any downstream tasks, you must first upload your videos, and the platform must finish indexing them.
Function call: You call the tasks.create function.
Parameters:
index_id: The unique identifier of your index.video_urlorvideo_file: The publicly accessible URL or the path of your video file.
Return value: An object of type TasksCreateResponse that you can use to track the status of your video upload and indexing process. This object contains, among other information, the following fields:
id: The unique identifier of your video indexing task.video_id: The unique identifier of your video.
Monitor the indexing process
The platform requires some time to index videos. Check the status of the video indexing task until it’s completed.
Function call: You call the tasks.wait_for_done function.
Parameters:
sleep_interval: The time interval, in seconds, between successive status checks. In this example, the method checks the status every five seconds.task_id: The unique identifier of your video indexing task.callback: A callback function that the SDK executes each time it checks the status.
Return value: An object of type TasksRetrieveResponse containing, among other information, a field named status representing the status of your task. Wait until the value of this field is ready.
Generate summaries, chapters, and highlights
Function call: You call the summarize method.
Parameters:
video_id: The unique identifier of the video for which you want to generate text.type: The type of text you want to generate. It can take one of the following values: “summary”, “chapter”, or “highlight”.- (Optional)
prompt: A string you can use to provide context for the summarization task. The maximum length of a prompt is 2,000 tokens. Example: “Generate chapters using casual and conversational language to match the vlogging style of the video.” - (Optional)
temperature: A number that controls the randomness of the text. A higher value generates more creative text, while a lower value produces more deterministic text.
Return value: An object containing the generated content. The response type varies based on the type parameter:
- When
typeissummary: Returns aSummaryobject with an id,summarytext, andusageinformation - When
typeischapter: Returns aChapterobject with anid, array ofchapters, andusageinformation - When type is
highlight: Returns aHighlightobject with anid, array ofhighlights, andusageinformation