In continuation of my previous application and post, I am introducing a new tool designed to assist influencers in efficiently preparing for video uploads on platforms like YouTube. After completing video creation, influencers often face the challenge of crafting an engaging title and relevant hashtags. This application leverages the Twelve Labs API to streamline this process.
Rather than starting from scratch, users simply upload or index their video and click 'Generate' to receive accurate title suggestions, topic recommendations, and hashtag ideas within seconds. By eliminating the need to explain the video content to the AI, this tool empowers influencers to quickly access tailored suggestions, enhancing their upload workflow and engagement potential.
Let's delve into the step-by-step process of building this application.
The app consists of five main components; GenerateTitlesAndHashtags, VideoFileUploadForm, Video, InputForm, and Result.
‘/gist’
endpoint)The app also has a server that stores all the code involving the API calls and the apiHooks.js which is a set of custom React Query hooks for managing state, cache, and fetching data.
Now, let’s take a look at how these components work along with the Twelve Labs API.
This app only works with one video, which is the most recently uploaded video of an index. Thus, on mount, the app shows the most recent video of a given index by default. Below is the process of how it works.
So we make two GET requests to the Twelve Labs API in this flow of getting the videos and showing the first video on the page. Let’s take each step in detail.
Inside the app, the videos are returned by calling the react query hook useGetVideos which makes the request to the server. The server then makes a GET request to the Twelve Labs API to get all videos of an index. (💡Find details in the API document - GET Videos)
The returned data (videos) looks like below.
Based on the returned videos, we’re passing down the first video’s id to the GenerateTitlesAndHashtags.js component.
Similar to what we’ve seen from the previous step in getting videos, to get details of a video, we’re using the react query hook useGetVideo which makes the request to the server. The server then makes a GET request to the Twelve Labs API to get details of a specific video. (💡Find details in the API document - GET Video)
It returns the details of a video including what we need, the url of a video! You might have noticed that the video url was not available from GET Videos. As a reminder, this is why we’re making the GET Video request here.
One more note here is that as this app only allows a user to upload/index a video file from a local device, the video url will be inside the “hls” object. (while in my previous app, as the app supported uploading by youtube url, the youtube url was available inside the “source” object)
Based on the returned data (video), we’re passing down its url to the Video component where the React Player is rendered using the url.
GenerateTitlesAndHashtags.js (line 105 - 111)
In this app, a user can upload and index a video by selecting a video file from the local device. We’re assuming that a main user of this application would be an influencer who has a video ready to be published but not yet publicly available.
Once you submit a video indexing request (we call it a ‘task’), then we can receive the progress of the indexing task. I also made a video visible during the indexing process so that a user can confirm and watch the video while the indexing is in progress. Please note that the video url is not instantly available from the beginning of the indexing process; it becomes available about at the middle of the indexing process.
Let’s take a look at each step one by one.
When a user selects a video file from his/her local device and submits the videoFileUploadForm, the video indexing process starts.
indexYouTubeVIdeo puts together the necessary data that needs to be sent for making the API request (e.g., language, index id, video file) as a form and makes a POST request to the server. The server then makes a post request to Twelve Labs API’s ‘/tasks’ endpoint. (💡Find details in the API document - POST Task)
It returns an id of the video task that has just been created.
With the returned task id from the previous step of getting details of a video, we will use this task id to get details of the task and keep updating the task status to the user.
So I’ve set the Task component to render inside the VideoFileUploadForm when there is a task id.
VideoFileUploadForm.js (line 144 - 149)
Inside the Task component, we’re receiving the data by using the useGetTask React Query hook which makes a GET request to the server. The server then makes a GET request to the Twelve Labs API as below. (💡Find details in the API document - GET Task)
It returns the task details as below.
Unless the “status” is “ready”, the useGetTask hook will refetch the data every 5,000 ms so that a user can see the progress of the task in real-time. Check how I leveraged the refetchInterval property of useQuery below.
Now we’re at the core and fun part - generating topic, title, and hashtags of a video! We’re receiving the user input then using the Twelve Labs API’s gist endpoint to generate the written topic, title, and hashtags of a video.
Let’s dive into each step.
InputForm is a simple form consisting of the three checkbox fields; Topic, Title, and Hashtags. Whenever a user checks or unchecks each field, each field name is added to or deleted from the ‘types’ state which is a set of types. This is because the ‘types’ property is required to make the request to Twelve Labs API’s ‘/gist’ endpoint in the next step.
I’ve set the field1, field2, field3 names in the GenerateTitlesAndHashtags.js.
GenerateTitlesAndHashtags.js (line 28)
When the form has been submitted and the video id and types are set, useGenerateTitleTopicHashtag hook will be called from the Result.js. The hook will then make the request to the server where the API request to Twelve Labs API is made. (💡Find details in the API document - POST Titles, topics, or hashtags)
Just so you know, we can generate title, topic, and hashtags by a single API request while we had to make 3 separate requests for each of the summary, chapters, and highlights in the previous application (See 3-2). Find details on the ‘/summary’ endpoint here.
It returns an object consisting of response “id” and the corresponding types that you included in your request. For example, if you included all three types in your request, you will see the result data including all three types; topic, title, and hashtags like below.
Based on the response we get from the above step, the results are shown in the Result component. Note that “topics” and “hashtags” are in the format of an array, while the “title” is a string.
With the Twelve Labs' “/gist” API, you can easily generate the title, topics, and hashtags of any video. It can be your best friend when you've already created a video and now need to come up with an engaging yet accurate title and hashtags before publishing it on platforms like YouTube. This tool can serve as your title/topics/hashtags generator, highly specialized in videos. I hope this app and tutorial were helpful in providing ideas for you. As always, Happy Coding!
Learn how to build a semantic video search engine with the powerful integration of Twelve Labs' Embed API with ApertureDB for advanced semantic video search.
Whether you're looking to find the perfect berry-toned lipstick or just curious about spotting specific colors in your videos, this guide will help you leverage cutting-edge AI to do so effortlessly.
Leverage Twelve Labs Embed API and LanceDB to create AI applications that can process and analyze video content with unprecedented accuracy and efficiency.
Harness the power of Twelve Labs' advanced multimodal embeddings and Milvus' efficient vector database to create a robust video search solution.