With the help of njs and react and with the power of AI we are going to build short video generator application with the help of AI this application is full stack application and we are going to build completely from the scratch going to learn how to generate the video script then how to generate the audio MP3 file then also we're going to learn how to generate the caption for our video and the AI images as well and not Only that but this complete application we going to build with the help of a various new text
tag as well so let's walk through the application first and let's then talk about the text tag which we are going to use to build this application now once you uh come to this website you have option to go to the dashboard and if you did not log into your application you need to authenticate with the help of clerk so we going to add the clerk authentication For our application now you have option to select or login with the Facebook Google or you you have option to login with an email as well once you click
on the Gmail and boom if you see it will redirect you to the dashboard page now currently I already have the some of the video which I created with the help of AI let me play one of them and then you will understand much better if I open this video you will see this beautiful popup and over here you will have option To integrate this player now if I play this one po boy living on the street you will see the image is little bit moving also the caption which is um align with the audio
as well and you will see the complete video right now this video is a short video of 40 second and obviously this complete uh application only building the short video okay now if I go back you have option to explore more obviously this all the video is generated by this particular user now uh Also user will get some free credit once they join it so that they can test and they can create this uh short video as well so this application is a SAS application okay and you can uh start earning money from it now
if you want to create a new video just click on this create new tab and boom if you see we have this form you have option to select the content type what kind of content you want to generate if if you want to motivational or historic fat or you have Option to add a custom prompt as well if you select let's say motivational you have option to select this image Styles or video Styles okay so you can select the video style let's say waterc color video style you want to use and the duration you have
50 second 30 second or 60c video If you select the 30 second and simply click generate short video you will see this beautiful loading effect and right now uh AI is taking care of generating your video so we will Wait and boom if you see the video is now generated you will see this images which is in the form of watercolor every morning is and as soon as I play it you will see that all the audio is U matches with this caption as well let me show you fresh start a new opportunity to chase
your dreams like the sun rising over the mountains a new day is filled with possibilities even in the face of challenges you have see how beautiful it Is right and once you close it it will redirect you to the dashboard and obviously anytime you can see your video from the dashboard where you can access it any time say okay so that's how you can generate the video not only that but over here you will see for each video it will detect the 10 credits from your uh wallet okay and anytime you want to upgrade you
can just upgrade it so as I told you in the beginning that this is a complete SAS application now let's talk About the text tag which we are going to use to build this application the first and very important the react based NE web framework called neck JS okay which is very popular and many my many of my video I use this nextjs for styling we are going to use a Tailwind CSS along with the UI Library called chatan which is twiin CSS based library and if you are new to this one don't worry because
everything we are going to learn from the scratch for authentication I'm going To use my favorite clerk authentication the first thing is free to use and also uh they provide the component which is very easy to integrate the authentication Service for a database we are going to use a free neon based postgate SQL database and again it's a free to use and very easy to integrate with the drizzle orm because we are going to use drizzle orm along with this neon postgate SQL database to generate the text based AI we we are going to use
A gini API AI model it's a free to use and very easy to integrate in our web application to generate the caption from the audio file we are going to use this assembly Ai and in order to export our video uh or to generate our video programmatically we are going to use this remotion do JS okay which will help us to generate program uh any video programmatically also if you are looking for a uh source code of this particular Project or any of my project uh you can find it on tub guru.com here you will
get the exclusive access to the all my source code source code along with the courses and not only that but you can have a track of each of the courses uh chapter by chapter also you have own personalized dashboard and you can go in any of the chapter you will see all the content of the chapter here you have option to get the source code that you can check the application demo or you Can watch on YouTube for free and in order to join this tube gji Pro membership you can join it by just less
than $9 so go ahead and join it now so if you did not subscribe to my Channel please do subscribe press like button press notification Bell icon so you will get an update from me so guys without doing any further delay let's begin to develop this beautiful AI short video Builder application for your social media in order to develop the react Application we are going to use a negs negs is the react framework for the web application it provide a lot of different feature and it's very easy to build an a big application because it
provide a folder structure routing a c server rendering and lot of other uh features so in order to create this nextjs application you will see this command line called npx create next app at latest so go to the folder open the terminal at that Folder and simply you need to type npx create next app at latest now at latest will install the latest version of the next application every time now if I click enter it will ask you do you want to proceed say yes and then you need to give the project name here we'll
say AI short video generator and click enter now we like to use typescript we are not going to use typescript in this particular application if you want to know how to Use typescript in the nextjs you can watch my previous video also uh if you're are beginner it's better to go with a JavaScript and not a typescript then say no to es link uh say yes to TN CSS so it will automatically install the twiin CSS for us um say no to uh Source directory and obviously we want the app router so say yes to
that one uh import allly say no and then if you see it will start installing the dependency like react react Dam Dom and the de Dependency like TN CSS and post CSS so now you don't need to install the TN CSS manually again okay now if you see our project is created successfully now I will open a vs code and inside that you can just uh open the folder or project folder where you just created the project and in this case I will select this folder say yes I trust the author on this popup and
boom if you see on the left hand side we have some folders and file obviously we will walk through one By one so the first thing is app folder inside that all our nextjs code or the all the pages which we are going to render everything will be inside this app folder now inside that we have font obviously you can add your own custom font or you can use Google font and I'm going to tell you how to change the application font as well then we have this Global CSS uh inside that obviously whatever the
uh styling which you want to apply Throughout the application you can uh mention inside This Global CSS then the layout. CSS which is the root layout of our application you can consider like a base of our application okay so inside that you will see this uh the local font they applied along with the metadata which is quite helpful when you want to add the SEO for your application and the root layout inside that uh we have this HTML and body tag and whatever the children which you are going to pass to This root layout it
is going to render in between this body tag now this children is nothing but the actual page which we are going to render it okay and then we have this page.js file which is the default page of our application now once we run the application you will get to know much better then we have this node module folder uh which basically contain all the uh install dependency packages okay obviously we are not going to touch to this particular folder any Time then we have this git ignore now git ignore is basically use whenever you want
to push uh your code to the GitHub right and you want to uh make make sure that okay you don't need to push some of the files that file path you need to mention here so that GitHub will not push that particular file for example the environment variable file okay we don't want to push that uh API keys and all and you can mention that over here then we have this next. config MGS and JS config which is configuration for the JavaScript uh the next. config which is helpful for configuration related to the nextjs application
the package log and package doj on file which contain the name of the uh application the version the script to run or to build the application the dependency which you install and some de dependency as well and then we have post CSS and T.C config.js file which contain the telin CSS related configuration now in this is Very important so inside this content whatever um uh path you mention or provide over here in that path or folder only the telin CSS is applicable if you want to apply T CES at some other location and the path
is not here make sure to add that uh path over here okay and these are the some of the colors that we are are going to add but right now let's go to the terminal and inside the terminal click new terminal and over here just type command npm run Dev now This command will run your your application on the port 3,000 and Local Host is the basic base URL if I open this one you will see it opened the local 3000 and now our application is rendering on the screen right now if I go over
here and let me bring this side by side and go to this app page.js file and inside that you will see this image nextjs logo is showing then this get started by editing and everything is showing on the screen Now let's delete everything because we don't want this homepage at all and let's add some du and here I will add h2 tag we just simply say subscribe to tube guruji so if you did not subscribe to this Channel please do subscribe and as soon as I type it you will see on the screen the text
is rendering on the screen without reloading your browser manually as soon as you save inside the uh or your code inside your vs code it automatically Render or reload your uh page okay now that is called hot reload now over here you can want add a button let's add a button and we'll say subscribe and save it now this is the button if uh you will see if I hold on this button you see the cursor pointer is change right so this is the basic setup or the way that you can create this nextjs project
now next step uh is to install the T CSS based a component Library called Shad CM which is quite popular Nowadays and the reason is you have complete control and you have complete customization option to the Shaden okay now first thing uh if you are new to the Shaden go to this ui. shen.com go to the components and here or maybe you can go to the docs and here you will find option called installation now inside here you have to select the framework so in this case our is nextjs then over here you have option
to create the project so copy this command and you Need to follow some of the step okay now we already created the project so uh we just need to initialize the shats here and that's all okay so copy this command go back to your application let me increase this size and inside the terminal I will add a new terminal and I will paste this sh command click enter and then say yes to proceed and now it will ask you some of the questions so first thing uh you need to select which tile do you want
to use I will select the New York one okay or you can select default one then you can select the base color we select the neutral and you want the CSS variable for the theming say yes and then if you see it's created a new file called component.js Json then is updated these two uh files and yeah that's pretty much now as soon as you install the shat CN you will see inside this uh root directory the new folder get added called lib and inside that we have this .js file okay also the component.js get
also added along with some configuration related to your Shaden and most important thing if you go to the T.C config.js file here you will see inside the theme under the colors you will see a lot of different colors like for card pop primary secondary and lot of other right if want to change this any color you can just replace with your hash code obviously I'm going to tell you how to do it later on in this particular course But for now this is the basic information I want to tell you now next thing if I
scroll down little bit and obviously we install everything now let's install the button component now each of the component in the shat right it has own command in order to install it right if you want to use uh or you want to add this alert obviously you have to add this alert or you need to run this npm command first so that you will add into your um application Now in this case we want to use button component okay and this is how it will look like obviously it has a lot of different um variant
okay which you can use it but for that one you need to install this button first so copy this command go over here add this button right and as soon as you added this button you will see the new folder get created all components outside of this app folder okay and inside under this UI we have this Button. jsx file now inside the button you will see some of the code which is already return but you have option if you want to edit this button okay and obviously this once you edit this button and you
can use it in your application okay now if I want to remove and I want to use the Shaden Button as soon as I type this button you will see uh you got the suggestion that you can import this button from this UI button company and inside that you can write like Subscribe see and if I go over here inside our application you will see this beautiful Button getting render on the screen right now as I told you before that we have a different variant say if you want to uh provide the variant as a
secondary you can provide secondary the destructive as well just inside this um button component you just need to provide a variant called let's say destructive and as soon as provide you will see the button color get changed Now all this variant is already defined inside this button. jss component see the default destructive outline secondary and if you want to change it with some other color or some you want to add some T styling to that you can do that as well how cool it is right so that's how Shaden is giving complete control uh on
your own components now it's time to uh set up a database for our application and for that one we are going to use a postgate SQL as our database and we are going to use a neon's postgate SQL database neon provide a free postgate SQL database to use it and most important thing it's very easy to integrate with any other omm as well also uh it provide a lot of different feature and you can scale it according to your requirements you can directly use this with the help of nextjs or you can with the use
it with the help of drizzle orium Prisma and lot of other now if you are not aware of how To uh write a query or SQL query or Pate SQL query don't worry because for that one we are going to use the drizzle Orum if you are new to this diesel Orum don't worry because everything we are going to learn uh step by step from the scratch okay and this diesel orium which is quite easy to access or to do the screwed operation on our database with the help of this neon Pate SQL so first
thing let's go to this or. drizzle.com and go to this documentation section uh Inside here select this postgate SQL okay from the left hand side and make sure to select this neon now this is the some of the step you need to follow in order to install the neon postrate SQL with the help of drizzle so first thing I will copy this command and go back to your application inside the uh terminal just paste this one so it will install the drizzle orm with the neon database okay which is serverless database and then you need
to add this Drizzle kit as well so I will install this dzel kit and then if you scroll down little bit this line of code we need to add so I will copy this first for line only and go back to your application inside here we'll create a new folder inside the directory called configs and inside the config we create a new file called DB do JS file okay now paste this line of code now over here if you see you need to add this dzel database URL okay so this Particular environment variable We'll add
it inside the env. loal file so create that one and here you just like next public underscore and then this digal database U L now here you need to provide the connection string right and that you can get it from the neon so if you don't have account with the neon just create a new account or you can just login so in this case I already have account I will log in it and once you log in you have option to create a New project if you're uh using this first time but if you use
already select the existing project and over here you will see a lot of different option okay but we want to create a new database so on the dashboard you have have database option uh select this database option and click this create new database if you see with this neon postgate SQL I use or uh use this particular uh neon in many of my project okay so just create a new database here You need to give a database name here we will say AI short video generator and select the account and simply click create now as
soon as you create without a second it will create this connection string copy this connection string as it is go back to your project and paste it here cool right now you you are good with the connection string copy this environment variable go to your db. jsx just paste it here I will remove this exim Mark and You're ready to go now one more important thing over here make sure to export this constant DV so that you can use this reference throughout your application and simply save it now most important thing that how to create
a table inside our database so for that one in uh through the or with the help of drizzle you need to create a schema okay and if you don't know how to create a schema you can anytime you can go to this D and learn how to create a schema And everything but don't worry let's do it line by line so inside this config only we'll create a new file called schema. JS and inside this schema. JS here first thing we'll say export um constant you need to give the name of your schema uh here
we can call users okay so here we say is equal to PG table PG is stand for post grades SQL table you want to create and make sure it is inputting from this PG core okay then inside that you need to give the table Name so let's give users you can make it small keep it everything small as a table name and then you need to provide the value inside this curly braces okay so let's say you want to provide the ID uh this ID need to be incremental so you can add the as a
serial PG core and then inside that we will provide the name of the column so in this case it is a ID dot make it primary key so once you make it primary key and Mark it as a serial so it will Be incremental and it's a unique okay then the username so here we say name is of type whereare right make sure to import it from the PG core now this is the data type okay and then uh the name of the actual column which is inside the database which is we say name okay
uh here you can provide as a not null okay so obviously when you inserting this name we have uh database will check that name should be there then the email again this is a Ware we'll say Email do not null okay then we'll say image URL which is the profile image URL if you want to add you can or you can keep it as it is as well where oh sorry here will say image URL then uh I think we can add is uh member is premium or not or we'll say subscription and subscription is
type of BU with the user bought the subscription on not and here we'll simply say true or false depends on your requirements okay uh so here we'll say Subscription and we'll say default to false okay so you can even add the default value this need to be just default as a false I think for now we are good with this one if you want to add a new column we also going to learn how to add the new column in the existing table as well but for now we are good with this one okay and
then Simply Save it now another important thing we need to do let's go back to the documentation and select This drizzle kit inside this drizzle kit okay let me yeah and just scroll down to the configuration part okay see this configuration now we need to add this D.C config.js file because we are using JavaScript so copy this content go back to your project and inside here we need to create a new file called drizzle do config.js and simply past this all line of code now here you need to provide your schema uh path okay which
is inside This config so here we say SL configs SL schema. JS okay and here you need to provide the uh URL of your connection string so sometimes in the this JS file uh it is not directly accessible the whatever the URL is so you just need to paste this complete URL like this okay and then save it okay and now last important thing we need to do let's go to this package.json and we are going to add two new script So first we'll say DB push okay and inside that we'll write drizzle Das kit
and push okay so what it will do it will uh push your schema with the updated schema structure to you the your post get SQL database and in order to run the studio okay now studio will provide uh the access to your database or all the tables and column so here the command is digel kit and Studio okay and let's save it now let's run it and let's say whether we are getting any error or It's running successfully now in order to push your siga you need to write npm run DB push because that is
the script we just provide over here see and click enter now as soon as you enter it you will see that is saying the pulling schema from database and changes are applied now whatever the schema you wrote it right the table you created now it is applied now in order to check it you can either check it from the neon database okay so if I go to this tables Section inside the dashboard okay under this branch and simply select the uh appropriate table or sorry the database and if you see in the new uh user
table is get created under that you will see ID name and everything right but if you want to run this studio in the same way or in your own uh local you can just run npm run DB Studio click enter it will open this local. D Studio URL just open it in your browser and and boom whatever new one provide the structure and UI Everything is same on the rual studio as well over here you will see this user option and the all the column which we created also you can run the SQL command or
you can even run the dzal query as well okay obviously you have all the settings uh once you run the or add the rec you have option to add a record obviously over here or you can have uh edit and delete option as well uh you can filter The Columns and lot of option they provide same thing everything you Will find in inside the neon uh dashboard as well so you don't need to run it if you don't want you can directly access from the neon uh dashboard as well okay so that's how uh we
successfully set up a database for our application now next we'll learn how to authenticate to our application and how to save the authenticated user to our database now it's time to add authentication for our application in Order to restrict user to access our application obviously once user uh authenticate to our application then user can able to create a shorts video so for that one we are going to use my favorite clerk authentication clerk is the one of the best authentication service provider and it provide a lot of predefined UI component so that you don't need
to build anything from the scratch It's Kind kind of fer plate for your authentication now not only that But it provide a lot of different provider where you can able to sign it like Google Facebook GitHub Microsoft and there are lot of others also you can add the multiple uh multifactor authentication or email SMS onetime password authentication or simply email password authentication as well also you can add magic links a different different social sign on and you have complete control on your data along with how the authentication work will flow so That's pretty cool right
also they provide a different hdk where you can sign in with so simply go to this clerk.com and create a new account if you don't have uh one of the best important thing that clerk is free to use okay so you don't need to pay or add credit card for that one now once you sign in or created the account you can simply log and here you have option to create a new application if you see I already have lot of application which I Created with the help of clerk but let's create a new application
here you need to give application name I will simply add it at a AI short uh video generator and then you can add the different signin option which you want to enable Okay you can enable email Facebook uh Google okay right now if you see I have enabled Google and Facebook and then simply click create application now on the right hand side you will see that UI how it actually look it on the Screen now uh you have to select this um different framework which you want to use obviously we are going to use nextjs
and first thing you need to do is to install install this nextjs um hdk to your application now the link of this cler documentation is in the description so you can directly check out uh without searching now I will just jump on to this negs clerk documentation which is quite in detail so just copy this command go back to your Application and inside here inside the new terminal just add this clerk nextjs uh then you need to copy this uh both the keys and inside this.l file we'll simply paste this two uh uh clerk key
which is one is publisher key and another is a secret key next you need to add this middleware file now this middleware file is very important uh in that file you will specify which route you want to protect and which you route you want to uh make It public okay so I will just copy this name and go back to your uh your root directory over here we'll create a new file make sure it's a JS and simply copy all of this code as it is okay and save it now next thing if you scroll
down the third point is mentioned that uh right now the cler middle whe will not protect any route and in order to protect the route you need to go to this cler midle whe reference just click on this one so it will jump on this clar middleware uh Configuration part okay if you scroll down little bit over here let me scroll down I think this one over here you need to add this line of code okay where we mention uh which are the protected route and in the logic it will check whether this route is
protected or not just copy this two line of code go back to the middle beer and I will just replace this with the line which we copied then make sure to import this create route matcher so it will add It to your import statement and currently if you see the dashboard and the Forum route is uh restricted I will just remove this one for now and obviously we want to restrict dashboard in the uh in this application so I will keep this route as it is and then save it okay next I will go back
to our documentation again and now next thing we need to wrap uh our application into the uh into this cler provider component so simply go back to your Application and inside the layout. JS file so inside this app where we have this layout. JS file which is the root layout I will just wrap this inside this clerk provider like this okay and then make sure to import this clerk provider as well now one more important thing over here um right now we are rendering this children inside this layout file right so instead of that one
I'm going to create a new file inside this app folder And we can call it as a provider. JS and inside this one we are going to add uh or we are going to render the pro uh children okay now here if you see I added this RFC which stand for react uh fun function export component which will automatically write me this um theme or template for us okay but if you want to uh use this particular extension you can just go to this extension in the vs code and search for the react uh snippet
tool and just install it now over here make Sure to replace this with the provider okay so export it as a provider and inside this provider just add a children so that you can just render this inside this children like this and inside the layout. Js file I will just wrap this children inside the provider okay so basically we are passing this children to this provider and inside the provider we are rendering this children okay next thing once we add this one you will see uh Let's go back to your application and right now if
I refresh this local 3000 it's saying missing publisher key wow so that's because we forgot to save this un. loal file let's save this one let's say uh this layout. JS file and now if I refresh see nothing get changed right but right now this particular route is not protected okay it's a public route and if I try to go to the dashboard page now it will redirect me to the signin page see okay but the Thing is the domain is not belong to what we are right now using okay it's supposed to use a
loc 3,000 so for that one we need to create a custom signin and sign up page so let's see how to do it so if I go to this uh documentation again over here you'll see the next step is to create a custom sign up and sign up page just simply click on this one it will redirect to this uh documentation where it simply explain how to create a custom signin and sign up page and very Easy okay so copy this complete path and I'm going to tell you the shortcut how to create a nested
folder okay so inside this app folder uh first what I will do I will wrap this or I will create a new folder but it start with this circular bracket that for just organized purpose okay and inside that I'll click on this new file and paste the all the path now instead of this page. TSX we'll make a jsx click enter and boom it automatically create the folder for us Along with this file how cool right and now just copy this content and let's paste it here and save it see same thing I'm going to
do for this signin page as well so just copy this path and inside the earth let's paste this make it jsx and then simply copy this all the things and save it okay next thing uh we have to make sure to mark it as in the sign in and sign up in a CL inside the cler Middle where as a public route but you don't need to Because by default in the Middle where all the routes are public then cop copy this uh two environment variable and then inside this env. loal file just paste it
here oops like this and save it and the last that's all we need to run okay now if I go to the local 3,000 nothing get changed but if I try to access the dashboard boom it will redirect it to our local signin pay see okay and that's how it works now over here we have this Option signin page the email address and everything now obviously on this particular page right uh we can obviously modify this one little bit so it's very easy let's go close this all of this tab and on the left hand
side I want to add a image and I want to keep this on the right hand side so simply uh from my download folder I'm going to use this image and then let's go to our application and inside this public folder right now we don't have so let's Create a new one as a public and we'll keep all our assets like image and here I will just rename this as a login okay perfect and then save it now inside this signin page. jsx file over here I will add the DU inside du I will add
two more du okay now inside the one do obviously we'll keep our sign in component as it is and in the first de I will add the image source now this image tag I'm importing from the next SL image next is Providing their own image component and inside that we can directly use the login dot I think it's a jpj right uh let's see yeah jpg so if you see over here in the next just we don't need to provide a complete URL nextjs will automatically detect that you are trying to access this particular file
or access from this public folder and over here we'll add the login you can provide the width or height okay and save it now these are The two de obviously we want to divide the screen into two parts so I will add a class name we'll make grid grid column one when the screen size is smaller and when the screen size is medium we'll make grid column two and then Simply Save it now if you see on the left hand side we have this image and on the right hand side we have this um component
but let's uh add some style so in the class name here we'll make Flex justify Center and then item to be in the center and Height to be screen see now it is in the center for this image We'll add a class name we'll make width to be full and object contain okay let's see how it looks perfect see okay now we have this image on the left hand side and on the side right hand side we have this beautiful sign in uh component how cool right now if I select the Google account and here
you will see that you can able to select the uh account as well okay now I will go to this local 3,000 and Then I will just simply go to this signin page okay and select account once you select this account you will see you'll redirect to Local Host okay it means you are able to sign in successful but uh clerk also provide one component from where you can check whether you sign in or not right so simply if I go to the page.js which our default page and over here I will just add user
button component from the clerk nextjs okay and save it now you'll see the Magic and if you see over here uh the user profile picture will appear and if I click on this one boom you will see this beautiful uh UI to manage your account or to option to sign out as well if I click on this manage account you will see this option to manage your complete account how qual it is right and that's everything uh you can build it with the help of clerk I did not write any code for that one clerk
is taking care of everything and this Beautiful UI also provided by clerk only without writing any components with the single component it is taking care of everything okay so that's why uh in this particular application we are going to use clerk authentication because there are a lot of things that we are going to to need it from the clerk okay so uh next we're going to learn how to save the data uh once you sign into to our application now it's time to save our user we already set up the backend uh it Means database
as well as uh authentication as well and when user come very first time to our application we will check if user is a new user or not okay with the database and if if user is new user then obviously it will go uh uh to the function where we are going to save the user information to our database but if user is existing user then we will directly give access to the uh our dashboard and once user save to the database very first time and Then we will uh show or we will give access to
the dashboard very simple and straightforward uh workflow so let's go back to our application and right now uh inside our application the user is not login okay so let's go back and inside our provider. CHS right here in order to access the login user information clerk is providing the one hook okay and from that one you'll get the user information so the hook is use user and if you see It is inputting from the clerk nextjs now from this user information you will get all the user information like name email image URL and lot of
other things here we'll write a new method called is a new user okay we'll check if the user is new or not here we'll write constant result is equal to await DB which is inputting from our config SL DB which we already exported dot we will first check if user is already there inside our database or not so we need to write db. Select from so which table we want to get it so in this case is a US users table okay and if you see we are getting suggestion that you can access it from
this config schema as we are using await here I will make a sync then here we need to write we claws okay and inside the we Clause we need to check if current user is matches with the user which is inside our database obviously in the in the database we don't have any user right now if you see it's a Completely empty okay so here we we can write users oop sorry user users do email if it matches with the login uh users U email so here we'll say user. email address. email address which we
are getting from this user okay and then that's all now here we can write if results of zero if it's not there okay it means result is empty then we'll simply need to add user to our database okay so here we can write await DB do insert this new record inside the user Table and then we need to provide the value now first thing we need to provide the name of the user which is user do full name okay which we are getting again getting from this user then we need to provide the email as
user. primary email address. email address okay and if you want to provide the image URL you can also provide that one using this image URL okay and that's how you can check the user and then if it's Not there then you can insert it now here for your information I will just console the result okay whatever result we are getting from this particular uh query now this is new user we need to call inside the use effect so whenever this application get launched at very first time it will check if the user is available then
only we will call this method okay obviously if user is not there they not make any sense to call this method okay and That's the reason I wrote this user and add e user means if user is there then only uh execute this e new user method and this user effect will execute whenever the user information is available let's save it and let's go back to your application so right now we got one error saying we use use effect and inside the uh server component you cannot use that one so obviously you need to mark
this provider as a client side and you need to make this client Side you need to write this use client at the top of the file and simply save it and boom right now obviously user is not loging to our application and that's the reason it's not inserting but if I simply go to this sign in and let's log in and boom if you see now I'm able to see the user profile and obviously we very first time we it right and boom if I refresh the database you will see inside our database the name
of the user the email image URL and everything is Saved into our DB or into our table right and inside the console now very first time the ARR was zero and that's the reason it went to that if block to insert the new record cool right now if I try to refresh it again you will see that you already have the record and that's the reason it will not insert to your database because it's already there right so that's how you can manage the user and we'll check if the user is new then only insert
that new record to your Database let me talk about the tub guru.com where you will find all of my exclusive courses along with the source code for each of the project not only that but you can track each course chapter by chapter here you'll get the source code the application Depot or you can even uh watch this complete video for free on YouTube how cool it is right also you can find your own personal dashboard and you can track your course depends on your how much progress you Did it okay and in order to join
this particular tube guruji Pro membership it will just add $899 per month okay and you will get an access to the all the courses and the source code for for free now let's update the font of our application and along with the primary color so let's go back to our application and inside the root layout so this is our root layout and inside this one if you see we have currently Using this local font so I will just remove this local font okay we don't want this import statement as well and we are going to
use a Google font so here if you want to import it you just need to write next or you need to import it using font SLG Google and here you can just search the font which you like it so if I go to this Google font and you can explore whatever the font you are interested to use it let's say uh in this case I want to use this outfit I Will just search it just remember the name and just try to add this name over here and you will get this suggestion so in this
case the outfit font I want to use it just import this one and now you just need to initialize this one so here we'll say constant outfit is equal to outfit and inside here you need to provide the subset so the subset let's say Latin and then inside this body class name I will remove all of this and then inside here we'll say Outfit. class name and that's all you are ready now if I go back to our application and Str this you will see the font of our application is now changed cool right so
that's how easily you can change the application font next if you want to change the primary color okay so what you can do just go to the uh tail. config.js and you can apply the primary color or you can apply the color to specific uh section that you can also apply but if You want to apply primary uh to some default primary color you can just add the hex code so in this case I want to use this primary color with this hex code and I will save it and inside this page.js let me remove
this variant okay and save it you will see this primary color now it's kind of purple color which we just set it inside the tailin doc config.js file okay so that's how you can also update the color combination for your Application now it's time to uh design a dashboard for our application and this is the simple layout for the dashboard okay so at the top we have the header along with the logo the dashboard button and the user profile icon button obviously this header we are going to use for our Landing screen as well which
we are going to develop at the end of this course and then we have this side navigation bar along with the all the option which you want to keep it there Okay and in this particular space uh we are going to render all our component or the pages okay keeping the sidebar and header constant throughout the dashboard section so let's go back to our application first and then we are going to create a new route so inside this app folder in order to create a new route here you need to create a new folder or
inside the app only make sure you are inside the app and just create a dashboard and inside that we'll create a Page. jsx or you can write JS file whatever file you want to write uh I will just rename this to jsx okay and then you can add the default template something like this just rename this to a dashboard and then save it now if I go back to our application and if I try to go to the dashboard you are able to see the dashboard text on the screen it means you are on the
dashboard screen now also you have to make sure this particular Route we need to protect it from the unauthorized right user so inside the middle we you inside this protected route you will add the dashboard route something like this so uh you are protecting dashboard and all the sub route or Ned route under this dashboard also you are going to protect so that's what is the meaning of this particular line now inside the dashboard we are going to create there here we are going to create dashboard's own layout okay so Simply inside the dashboard we'll
create layout. jsx file add the default template and we can just rename this to dashboard layout and save it now in this dashboard layout all the children which is going to render under the dashboard we are going to render through this children and so I will use it like this and then save it obviously on the screen you will not see any changes okay now first thing we need to design the header for our application so inside the Dashboard I will going to create a underscore component folder so whenever you use underscore it means this
is just for grouping and nextjs will consider that this is not a route okay and that's what we wanted and inside that we'll create header. jsx file add a default template and save it now this header we need to add inside the uh layout. jsx so I will just make sure it is in the DU and again we'll use the header something like this and save it okay Perfect now you will also see the header at the top now let's go to this header. uh jsx file and inside this one we are going to add
the logo and all of these things so in order to display the logo I already added that in a public folder so if I go to this public folder you will see this logo.svg and this is just a uh SVG code for the logo and here I will add a de inside that in order to show the logo we'll use image next SL image The Source tag and inside here we'll use logo. SVG will give width of 30 height is of 30 and let's save it and if I go back to our application the logo
image is showing on the screen also over here I will add h2 tag and we say AI short vid okay something like this the name of the application here we add a a class name as a flex so it will be in one line we'll give some gap of three and we'll Make item to be in the center for this is two We'll add uh font bold text Xcel perfect okay next uh we'll give some padding to this particular du so we'll add a padding of three padding X to maybe let's say five let's save
it and let's see how it looks see now on the right hand side as per this MO up we want to add dashboard button as well as this user profile icon button so let's go over here let's add a new de and here we'll add a button and We'll just simply say a dashboard and then we need to add a user button from the clerk neck JS in order to show the profile icon something like this okay now let's uh bring in one line so we'll add a class name make it Flex gap of uh
uh let's say three and we'll make item to be in the center so it will be in the one line now we need to bring in one line and we need to put it in on the rightmost side so for this du we'll make it Flex we'll make it item to be in the Center and just simply add justify between see okay and let's add the shadow as well see okay perfect so that's how our header is now ready next we need to add the Side Bar side navigation bar and there are some setup we
need to do so first thing we'll create a new file called side now. jsx file add a default template and save it now this side navigation bar is also face similar like a header so that we will add it inside The dashboard layout so here I'm going to add a du and inside that we'll add a side now okay and now inside the side now we'll add some class name so when the screen size is small smaller or uh then we'll hide this one and when it's medium then we'll show this side navigation bar also
we'll make height to be screen and background to the white we'll make mark it as a FL uh fix and on from from the margin top We'll add 65 pixel now Here If You observe I Gave the size which is customized site means whatever size I want to give so that you need to give inside the square bracket when you are writing the tail CSS classes okay and most important thing we need to specify the width of this particular side navigation bar let's save it and if you see we are able to see the side
navigation bar also once you define this one right we have to make sure the children so let me bring this children over Here uh this whatever the content we are going to render which we need to add whenever the screen size is medium we give a margin left to 64 so that you can able to see this dashboard see perfect now let's implement the side bar so I will go inside this uh side navigation uh just make sure you'll add the class name width of 64 over here height to the screen and we'll add Shadow
medium okay and we'll add padding to five and save it something like this perfect Then uh we need to render the list of options okay the menu options so I will create a list for that one and we'll add menu option is equal to and inside that we'll add a ID name as let's say dashboard then we need to add a path okay so path is just a dashboard and then the icon now in order to add a icon we are going to use one Library called Lucid uh icons okay just go to this Lucid
do da and inside that go to this icon section okay and here you will find Bunch of Icon but if you want to uh install this icon SL uh get go to the get started go to the installation and obviously we are going to use we are going to using the react so just click npm copy this command go back to your application and simply inside the terminal paste it here okay and so that you can directly use this icon as a component so let's say in this case I want to use a panel top
left as icon and as soon as I enter it you will see it is Imported uh inside this uh file and also this is the preview this is how it will look like okay but if you want to search how which icon do you want to use you can just some search something like this and here you can just use this name uh to import uh into your uh application okay how cool it is now over here I will add couple of more options I will say create new then upgrade and here we'll say account
okay obviously path I will also add something Like this and account for the icon let's say for the create new will I file video then for upgrade I will add Shield icon so Shield plus icon and here we'll add Circle user icon okay and save it obviously all of this name I already get it from this Lucid icon so I it's easy for me to add it immediately now next thing we need to just render this one so I will add a du inside that we add menu options. Map item comma index and the arrow
function inside here we need to display the icon first so we'll add item do icon as a component and then the name of the menu option so this is item do um name okay obviously you need to wrap it inside the d i we just wrap it inside the D something like this and save it okay now uh for this particular du if let's see how it looks on the screen now see we are able to see this icon and the option but here we'll Add a class name make it Flex item to be in
the center we give gap of three and most important we need to provide the padding as well see uh for this de let's add a class name we'll make it grid okay so that we can give a gap of two okay now we have this options um if you want to give more padding you can give it I will just add Gap more Gap then uh we'll add a h effect so on H we'll just add a Background as a primary color and also on Hover we need to make sure the text is also white
so if I hover on this one you will see the background is changes along with the text and icon color as well next uh we'll make this rounded MD and we'll make it cursor pointer so whenever I hover on this one you will see this change and the corner also rounded so it look quite beautiful next uh whenever you want to uh use a click on this one right you can use this Link uh component from the next SL link it provide uh it has a h reference uh property so it's similar like a anchor
tag inside the HTML and inside here you can just pass the icon. path okay so whenever user click on this one it will just navigate to that particular uh route okay how cool it is so that's all uh just make sure the ID you are providing correct one and also one more important important thing that you need to provide the key which is the unique Okay so index will be the unique key so that's the reason I provid it as it is and most important thing whenever the screen size is smaller it will automatically hide
your side navigation bar okay and so that you can just add a button so that it will open on the smaller screen as well also we have to make sure whenever you use a select any of this route we should um mark it as active one so in order to implement that um simply we need to get the current Path name in order to get the path name you just need to write constant path is equal to use path name which is importing from this next SL navigation and this will return the current path if
I console this uh inside the terminal or inside the inspect panel go to the inspect and inside the console clean this and if I refresh this screen okay so here we are using hook so we need to mark this as a client site and now if you see over here on the Line uh number 36 inside the side navigation file the path is rning as a current path and nothing but this one okay now we will just compare it and then we are dynamically apply some styling so in order to add Dynamic styling you need
to wrap inside the curly braces with this tag or quat and remove this single cat and we can write a condition so if the path is matches with the menu options do path okay then we can simply add background as a Primary and text as a white see so right now the dashboard is active one and automatically it is showing as the active uh option okay so that's how if I go to this create new obviously we don't have page for create new but once we have it will show this create new as active one
now once user on the dashboard page and when user come to the first time and he don't did not have any short video created then on the dashboard we are Going to Simply show the dashboard text along with the button to create a new dashboard obviously it will navigate to the new screen once user click on this button and then over here we'll add the this empty state it means um user have option to create new and once user created any shot obviously we are going to display this short video list over here on the
dashboard okay so let's Implement that so let me close all of this tab and simply go to this page uh Under this dashboard because this is our default page for the dashboard and inside here we are going to add a du inside du let's add h2 tag we'll say dashboard and then we'll add a button as well inside the button we'll simply say create new okay and we'll add a plus icon something like this now if I go back to our application here you will see the dashboard also we'll give some padding so if I
go to this dashboard Layout over here we can give padding so it will applicable to all the uh route which which is rendering from this dashboard layout out okay now uh let's add some width and height so first we'll add a styling to this dashboard text here we'll make it font bold text to Xcel and then text primary okay and uh we want to bring everything in one line so we'll make Flex justify between an item to be in the center so something Like this okay and that's how our dashboard will look look like next
uh as I say we need to add a empty state so in order to check with the empty State obviously we'll check with the help of list of video so here we have let's consider we have the state called video list and whenever we have the list of video we will simply save it inside the video list but if it's empty then we will show the empty state so here we'll add Empty State okay something like this and inside this we'll add a de we just need to write a condition if video list do length
is equal to equal to zero and and operator then only show this particular du and for that one I'm going to create a component called empty state. jsx add a default template and simply add this empty State over here okay if I go back obviously uh we need to mark this component as a client side perfect and it's showing as a empty State perfect now let's go to this empty State and let's implement it so it's quite easy we just need to show one test called here we'll say you don't have any short video created
okay and then we'll simply add a button we'll say create new short video okay and that's how it will look like but we'll add some styling so we'll add a class name We'll add a Padding of f we add a flex item to be in the center and flex column because we want one below each other and then margin top to 10 We'll add a border to two but I want a border is of dotted so we'll add that one and padding y to let's make it 24 and this is how it will be look
like in the center okay now once user click on this one we will navigate to the create new page okay so right now we don't have the route for the create new Okay so we'll create a new route in under the dashboard only and here we'll say create new okay and click enter now inside here we need to create page. jsx file add a default t template and I will just rename this page as a create new video or you can say just create new and save it okay now when a user click on this
button we need to make sure it will navigate to the create new page so simply I will add link tag with the path as a slash create New and I will wrap it something like this and save it now if I click on this create new dashboard it will navigate to the create new somehow it is okay so this need to be under the dashboard because we we created this create new under the dashboard right so maybe you can write something like this dashboard and then create new now if I go back and click on
this create new now it will navigate to the create new see Okay because we want to keep it inside the dashboard only same thing you need to update inside the page do not page but inside the dashboard oh side navigation bar so if I go to the side name where we have menu option and over here make sure it is under the dashboard okay and save it also uh same thing you need to do it so over here I will also wrap it but I will just copy the existing one from the empty State and
we'll paste it here and save now even though if I click on the if I go to the dashboard so link is not defined okay make sure to you I will add the link in the side now not here so maybe inside the dashboard so if I go to the dashboard page right make sure you will import this link tag from the next SL link and boom if I Click on this create new it will also navigate to the dashboard create new and automatically you will see this option okay if I go to the dashboard
and click on this create new you will see the selected option as well now let's create this create new page where uh user can select all the options in order to create create the video the first uh we are going to have drop down to select the topic on which user want to create the video then the Style of image uh whether the user want a realistic image or cartoon image or comic image okay and the duration whether is a 30 second video or 60c video okay and once you the click on the create then
we are going to generate it with the help of AI so let's go back to our application and inside this vs code let me close all of this tab we have this create new page already okay and inside here let's simply uh add S2 tag over here we'll say Create new now inside this du We'll add a m uh uh add a class name with the padding X to 20 when the screen size is medium or larger uh for this particular de uh sorry the h2 tag will add a font as a bold text for
Excel and we'll change the color to primary and make sure text is in the center and this is how it will look like then we'll add a do and inside the DU we need to add the select topic component okay and Obviously for each of them we are going to create a component then uh select style component and the last we need to add a duration component okay and at the end of this one uh we are going to show create button okay so let's create uh the each component one by one so under this
create new we'll create a new uh folder let's create a new folder called components and all the components Related to this uh create new page will keep inside this underscore component folder inside this one we'll add select topic. jsx file add the default template and save it now make sure to add this component inside this page.js file as a select topic and save it okay now if I go back to our application you will see this component get added perfect for this du I will add margin top to 10 also We'll add a shadow medium
and Marin top uh let's add padding to 10 as Well okay so we'll get S this kind of Border perfect uh let's go to the select topic and inside this select topic uh we'll give some title and subtitle so heading or sorry the inside the h2 tag we'll say content here we'll add a class name make font bold text Excel and text primary and then we'll add add P tag for we'll say what is your what is the topic of your Video so this will be a class name text I will make it gray little
bit and then save it if I go back to application this is how it will look like perfect if you want we can make this 2 Exel and then we want the drop down where from where we can select the options okay now in order to implement the drop down let's go to the shat CN and search for the component called select okay so if I if you see over here this is a component and this is kind of Drop down we want where user click on this uh box and then we'll get the list
of other option where user can select the one so in order to use it let's uh install this component first so copy this npm command and simply paste it inside your terminal then copy this all the input statement and paste it here next uh you need to copy this uh use case and I will paste like this Okay and save now if I go back to application so it's saying fail to compile that's interesting let me go back to your application and let's try to add use client as well and make sure it is imported
successfully so obviously it is not installed so that's the reason and now if you see if I say yes then it installed now perfect let's save it go back and check and boom if you see we got this drop down perfect obviously uh We will uh we will add some style and obviously we need to add options as well so over here we'll add some options so here we say custom prompt if user want to add a custom prompt then we'll say random AI story then scary story and I added all of them now okay
now save it and over here we just need to iterate this all the options map over here we'll say item Comma index and obviously we need to uh use this select item because in that one we need to show it right and here we'll say item and value will be the item only because it's just a string array of string okay now I will remove this one and for the placeholder we'll select content type and save now if I go back to your application you will see all the option is now listing okay now also
let's add Some styling so here width I will mark it as a full then we'll add some margin top to two padding to six and we'll make a text larger and boom see okay also now uh whenever user select the option let me go back option as a custom prompt we have to give a text box over here okay where user can enter his own prompt so we need to write a condition so what we'll do first uh we'll Define one state so here we'll say constant select option or we'll say Selected option set selected
option is equal to use State okay and whenever user select any option we need to make sure it is stored inside this particular state so in this select component has one method called on value change and it will return the selected value so simply we'll set the selected value as a value okay and save now over here we're going to write a condition so if selected option is matches with The custom prompt okay so if it matches with this custom prompt then we'll add and operation we need to show the text box now in order
to add add a text box I will go to the shat and it has a component called text area okay so I will just copy this npm command and we install inside our vs code or inside our project so that we can use it inside our project uh inside our code obviously so here simply add text area from this text Area component and simply save it now if I go back and if I select the custom prompt and here you will see the text area Okay obviously we add some styling so here we'll add a
class name so margin top to three then here um we can add a placeholder and we'll simply write write prompt on which you want to generate video okay and this is our prompt and if I save it see the text area but if I select the different one You will see now that text area is gone only when you select the custom prompt you have option to add the um your own prompt okay so that's how it works now one more important thing we need to implement is whenever you select some value we need to
pass back to this parent component and we'll create a new method we'll say constant handle on handle input change okay so whenever user select any option we need to uh add It inside this on handle input change and obviously we need to save in one state called form data okay so inside here we'll state it obviously it will take the field name and then field value okay and save it now uh in our case right in this uh whenever user select any value uh we need to pass that value back to the p and component
so I will W this in a curly braces and over here I will write a Condition if value is not equal to custom prompt then we'll set on user select so on user select method I will write and in that method we'll select the name uh of the field which is the topic and the value which is the just a value and this on user select will pass back to the parent component okay only when the custom prompt is not there because it doesn't make sense to pass the value if the custom user select the
Custom prompt right but obviously in this case uh we'll add on change method so in onchain method it will emit the event e and then here we will say on user sorry on user select and in that method we'll pass the topic along with the whatever user type inside this particular text area so that value we can get it from the e. target. value okay and this on user select we passed now if I go back over here for this select topic it has a method called on User select and simply call this method which
is on handle input CH okay now if you want to test this we'll just console this field name along with the FI value and save uh we use the use state in the select topic so make inside this page. jsx so we'll make this as a use client and save perfect now if I go to the inspect panel and go to the console see now if I select this car story see it's showing The topic with the topic name but if I select the custom prom nothing get printed until unless I type something see and
then topic is coming up along with their value perfect okay so that's how it works next uh we need to implement the style so let's go to the underscore component and we create a new component called select style do jsx add a default template and simply add this component under this select style oh sorry under This page. jsx and here we'll say select style and save it now if I go to the select style over here first thing we we need to do is to um create the uh options okay so here we'll say style
options is equal to and inside that we'll add a name say let's say realistic then image obviously I added all the images under this public folder and whatever the images you want you will find it in the source code in Assets folder the link is in the description so you can get it so in this case uh for the realistic I use this real. PNG I think yeah real. PNG uh same thing I will copy it a few times and then I want to use a cartoon if user want to select the cartoon image they
can select the cartoon image as well then uh here we'll say comic as a comic then watercolor and we'll say GTA I think Let's try this one as well GTA style and save it okay now we have the all the style options uh ready you we just need to iterate that one but before that let's uh copy this H2 and P tag okay because we need need this one and inside this just paste it here okay next I will just replace this we'll say style select your video style and then we'll Define du inside the
DU we'll just iterate the Uh option list so here we'll say style options do map item comma index we'll iterate each item and then uh inside the DU let's add a du we'll add a image from the next SL image the source and the source will be item do image okay then we'll give width let's say 100 height let's say 100 and let's save it let's see how it looks whether it's showing on the screen or not so right now it's showing the real. PNG it must start with the leading slash perfect so over here
we are trying to F from the local so make sure it will start with this uh Slash I forgot to add this one now if you see image oh it's not showing let's see why so all the images had extension jpg so that's the reason it was not showing let me replace it quickly for all of this image and now if you see all the image is now showing on the screen perfect now let's apply some style so uh for this D We'll Add a class name make it grid let's add a grid column to
when the screen size is smaller grid column 3 when it's medium and grid column 4 when it's uh large and on Excel We'll add grid column column five okay also We'll add some Gap so gap of let's add gap of five perfect okay let's make it six actually perfect okay now um over here we'll add a class name and for this one we'll add height to 40 We'll add object cover because it's Right now is not not correct so we'll add object cover rounded large and width full let's see how it looks see you can
add a height more height let's say 48 perfect okay now we have this image style option uh for this de let's add a class name margin top to 7 so we have some distance between this one also for the image as well we'll add margin top to three so that we can have some Gap okay and now we have this beautiful Option obviously for this option we need to uh provide the text as well so here we'll add h2 tag inside that we'll say uh name of the option so item do name and this is
how it will look but we want on the top of this image so I will add a class name when Mark it as absolute okay we'll add a padding to one we'll add a background as a black color and we'll add bottom to zero also make sure to add a width to be full okay this is how weird it is Looking that's fine let make class name and relative oh this need to be a so for this de you need to position it as a relative okay and now if you see it's showing it but
obviously we need to make the text as a white so it will be visible on a black background see something like this then um also make it text to be in the center and then we'll add the rounded corner to this one as well so simply you can mark it as a Rounded large but we want only bottom side so you can also make a make mention rounded bottom large something like this see now whenever I H on this one we have to make sure we'll add some animation effect as well so over here we'll
add H effect we can just simply scale to 105 and for smooth animation we can add transition all now whenever I H this we'll see this beautiful popover right and uh we'll Make cursor pointer whenever you hover on this particular image perfect now whenever you user select any of this image we have to make sure we will show a selected kind of uh options so for that one uh let me close this one and then we'll simply add one option called selected option comma set selected option is equal to use State and when you do
select any option right obviously on the click of this du we'll add Onclick and set selected option as item dot you can add a name okay item do name and then save it now obviously if I click this one right now this item is selected but we need to show that as a selected one so for this particular de uh let me bring this down we will add a dynamic styling or a conditional styling whenever uh depends on the S section of the user right we will change the style so simply here I will add
a dollar sign and we'll Write condition called selected option dot uh or section option is equal to equal to item dot name if it matches then we'll add a border uh is of width two and border is of color primary I will just make it to four okay and save it now if I if you see this is one is selected and that how the Border get added perfect obviously to this border uh we'll make rounded Excel perfect now if I select this comic one see it's selected perfect right so That's how you can uh
add that effect if you want to change the background of this text with the primary that also you can do it but I for now I will keep it uh simple and uh obviously the last thing we need to send the user selection option so inside the on click only will wrap inside the curly braces so that you can call a multiple method or something like this right and here we'll just simply say on user select and we'll just Add the fill name obviously which is the uh image style I will say and then the
value will be item do name and this on user select will pass back to the parent component and inside the page. jsx we get over here and we simply call on handle input change and save it now if I go back I go to the inspect panel go to the console and whenever I select any of this one see is you are getting the result okay next the last thing we need To do is the duration so for that one I will create a new component called select duration. jsx add a default template and then
make sure to add over here so select duration now whatever we have in select topic right it's it's a similar one so I will just copy everything as it is except this prompt thing we don't want that one and I will simply paste it here make sure to close this tag and also Make sure to copy this import statement as well for the select only okay perfect uh obviously we don't have option and we don't need it so I will remove this option for the select item right we need to add a 30 seconds as
a one option and make sure to add a value say 30 seconds and another option for the 60 seconds if you want to add more option you can okay it's up to you but right Now we'll keep these only two option make sure to update this S2 tag and here we'll say select the duration of your video see okay obviously we'll give some margin top so here we'll say class name margin top to seven and boom we have the duration option quick right obviously we don't have any on user select method set and here here
we'll change this field name To duration and then we'll pass the value what we want and make sure to pass this on user select over here and save it okay and perfect so obviously uh we need to change this to select duration perfect okay uh one more important thing we miss over here we don't want to set this options and then in over here make sure to call this method Okay perfect and then simply we need to save it in our uh form data so in order to save it we have to add set form
data over here we have to make sure uh we'll get the previous value whatever the previous value it is in the form data and then we need to get the spread operator with the previous data with the field name and the respective field value and that's how you can set the form information okay and that's how your create new page is now ready but Just add the button as well so here we will say button create short video over here um we'll add a class name margin top to 10 and width oh margin top to
10 and width full and save it make sure to import this button I think we forgot to import yeah and now we have this create new short Button as well perfect okay so that's all now once we have all the information Which user selected into our uh form we have to pass it this all the information to the jinii AI which will generate the video script for us obviously along with the video script for each scene we are also going to generate the image prompt which will help us to create an AI images and obviously
we are going to write our own prompt and then whatever values are selected that value we are going to pass to our AI prompt and obviously with the with the help of jini AI it will generate the video script along with the image prom for us after that once we have the script for our video then that with the help of that text script we are going going to convert that script into the audio uh into the MP3 format and for that one we are going to use a Google Cloud text to speech API obviously
it's a free API so you don't need to worry about this one the G API also free okay and once we generate this audio MP3 file that audio MP3 file we are going to store into our Firebase storage okay because we need to store it somewhere and the Firebase storage is free to use and that's where we are going to store that one next Once uh we have this audio MP3 file we need to generate the caption file okay in order to show the caption on the text so whenever we uh convert our video right
on that one we are going to show the caption as soon as the audio start playing and obviously this SRT File which is a caption file which also we are going to store into our Firebase storage and later on at the last we are going to generate the AI images for our video depends on the script which we generated at the first step okay and then everything we are again we are going to store that images AI generated images also into the Firebase storage and everything once we have all the information generated from the AI
we are going to store in our database and then We are going to convert our uh all the information which we have into our video okay and that video you can then download it and then post it to uh YouTube or Instagram okay so this is the complete process that we need to follow in order to generate this um content from the AI first and then we'll convert that into the video obviously we will going to follow step by-step process so first thing we are going to get the script for our video along with the
Image prompt okay so very first thing you need to do go to this ai. google.de which is the Google's gini API model I'm using this gini API that's because it's more powerful than Char GPT and also it's free to use okay uh open means J uh chat GPT is paid and this Google uh J API is completely free so once you go into this website click on this get API ke Google studio so it will jump to the um AI Studio where you have option to generate the API key okay and it's free So you
don't need to worry about that one now here you have option to play around it okay so just click on this create new prompt and you can paste The Prompt so in this case I'm pasting this prom and it's saying write a script to generate 30 second video on topic and obviously we are going to add the users topic over here along with the AI image prompt in the format of the image obviously for each scene this is very important and give me the result in Justum format with the image prompt and the content test
as a fill okay so this image prompt I added into this uh or passing to this Ai and if I run this one it will give me the Json formatted uh result along with the contact text and if you see everything all the details you will find over here okay so it will give me the image prompt along with the text for that particular scene and obviously it will give me the it give me the four to five uh object list of Object yeah I think that's correct okay and that's how uh we will get
the script with the help of AI now once it generated you have to click on this get code and over here make sure to select this JavaScript and here you will find all of this code okay now first thing you need to do to install this generative AI hdk so this is the npm command in order to use it or install this jinii API into your application so go to your vs code And simply inside the terminal paste this uh npm command so it will install the generate you aisk mean Jin API and then copy
all of this code as it is then go to the config folder so I will go to this config folder and over here we'll create a new file will call AI model do J or we can make it JS only right now and then paste this all the line of code okay now uh obviously we are going to update little bit so first thing we need to add this jinii API key so go to This.l file over here we'll write next underscore underscore public underscore J mini API key is equal to and paste this key
oh obviously we need to get this key uh let me close this tab and and we'll go to this get API key here I already have the API key so I will just copy this and then I will paste it inside this do. loal file okay then make sure it's a next public Okay next uh we'll keep everything as it is uh over here inside this generative config you can obviously change the um uh field depends on your request but most important thing the response type I'm going to put application SL Json because we want
Json format request okay then we don't want this function so I will remove this function obviously this run method along with this result and all because we are going to call inside our API call and Make sure to export this one okay and what it will do it will start we we're going to pass the information this history content is very important so depends on the uh history content right it will generate the response for us okay the similar kind of response so whenever you uh pass any prompt to this AI model it will make
sure that your response will be based on this particular history so that's the reason we kept as it is and just save this one Now next thing uh we are going to keep or make this API call on the server side so inside this app folder we are going to create a new folder called API and inside that we'll create a new folder again we'll say uh get video we'll make it small gate video script and inside that we'll create route. jsx file okay now inside here we'll say export a sync function is of type
post and it will take the request okay and the Function now uh inside the tri block so we'll add a try catch block over here and inside this triy block uh first thing we'll get the uh prompt which uh user is passing to this particular um uh API call so here we'll say prompt is equal to await and from the request we'll get that one using Chon something like this okay obviously we'll console this inside the uh console so whatever the problem we are passing we'll make sure it is Getting over here next thing we
need to get uh s uh um send this prom to the uh AI model so here we say constant result is equal to await we'll say chart session and make sure that chart session we you are accessing from this config AI model then we'll say dot send message and here we'll pass the prompt which we are getting from this uh request okay now we are going to get this result if you go check over here in the form of Result. response. text okay so we'll simply pass like this console.log result. response. text okay we'll make
sure it's getting and once we have the uh response we'll just simply return this one so here we'll say uh next response. Json obviously we'll return the result and here we'll say result as json. pass because we want to pass this Information and we'll pass it here like this okay if uh if there is any error we'll just say next response. Json error and then we'll add it as a error message something like this okay so this is simple request let's save it and let's make a API call so if I go to this page
dot not page dot but if I go to the dashboard where we have this create new and inside the page. jsx here we'll get video script and we'll create new method Called constant get video script and over here we need to make an API call to this uh get video script uh API okay so simply for that one we are going to use exos AOS is the HTTP client okay and is similar like a fet if you use before but if you want to learn more about that one go to this exos do HTTP and
over here you will find all the information in order to install this one you just need to add npm I exos which will install the exos for you okay now Over here in order to make a call here we'll say uh constant result is equal to await exos dot post because we are making post call and then over here we need to write API SL getet video script okay comma and then we need to pass the request so here we'll say prompt and here we need to pass the prompt information now first thing we need
to get the or write the prompt so what I Will do I will go back to our um AI model and I will copy this prompt from here as it is okay and for now I'll put it over here so prompt is equal to and we'll paste this prompt okay now only thing we need to do is to replace this value so from the form data we'll get the duration okay so that's what uh we pass but you can just confirm from the component that what is the FI name so Duration see okay so this
duration will pass then the topic this is also important so over here we'll say um form data dot topic and then we want the image format so this one the image format here we'll say form data dot image style make sure that that is correct yeah image style okay and then we have this complete prompt now before making any call I just want to make sure that we are get the correct prompt so I will just console This one I will I commented this line of code and whenever user click on this create new okay
so I don't know whether we have method so here we'll say on click and let me see so over here constant on create on create click Handler so this method I will write and in this method we'll just simply call get video script first okay Now on create click Handler we're going to call over here okay and simply save it now if I go back to our application Let me refresh it once and go to the inspect panel go to the console and let me clean everything so choose the topic so here we'll say historical
fact the style you can select whatever style you want and the duration you can select 30 seconds 60 seconds is up to you okay and simply click create short video and boom if you see it give Me the exact prompt that what we are looking for okay now this prompt obviously we are going to pass to our API so let's go back again now we are good with this prompt I will just uncomment this line of code and this prompt I'm going to pass over here okay as this is await let's make this as a
sync and once we have the because this is the promise once we have the result we just console it so here we say console. log response. data Okay perfect um I think that's all we need it let's save it and let's test this out now over here uh we already selected all of this thing now simply click on create short video obviously it will it give us other prompt okay and along with that if you see we got the result okay inside the this result we have six items okay and each of the six item
has a contact text and the image prompt as well how cool it is right and everything is it is here if you want to Change let's say you want to get the motivational uh content you selected you want in the format of watercolor or let's say G here and you select the 30 second okay and simply click on create short video obviously this is the prompt but now once it is generated you will get the result as well see and in that in that one you have all the information how cold right so that's how
guys you can generate the video script from with the help of AI gini Model now before uh generating the audio clip uh we'll make sure that whenever uh we are making any API request we are going to show some kind of loading effect right so that user will not refresh any screen and user will get to know that okay uh there is some process going behind uh his video okay so for that one we are going to add a loader effect and in order to implement it we are going to implement custom and we will
build our own custom loading so Simply uh we'll use this alert dialogue in order to show the loading and if you see this is dialog how how it look like so in order to use it first import this uh component so let's go back to your application just paste this command so that it will install this alert dialogue let me close all of this tab for now and then inside your create new component folder we create a new component called custom loading okay do jsx now let's add a default Template and save it oops sorry
now next thing uh once you uh added this alert dialog copy this import statement go back to your application and simply paste it here after this you need to copy this all the sample example and then you need to paste over here now currently with the help of this trigger uh this alert dialogue content is getting open but we don't want this trigger and you want to open it programmatically so this alert dialogue Has method called open and through this open method we pass the loading whether this loading is true or false if it's true
then it will open this dialogue otherwise it will close the dialogue also we don't want this uh header or footer anything so I will remove this and we'll only keep this alert dialogue content okay here let's add a du and let's add that loading text okay for now and in order to use it right you just need to to import this component uh In any page you want to use so in this case in the page. jsx we want to use it so over here I will just simply add custom loading and to this custom
loading I will pass loading now currently I if you see I'm passing it as a true right and if I go back to our application Let me refresh it once and boom if you see the loading is showing on the screen but obviously it's a it's showing as a um just a border but over here if I add the class Name we'll make our background white let's see whether it's coming or not it's coming but we need to give class name over here and let's see see okay so that's how the loading text is now
showing obviously if pass the loading as false it automatically close the dialogue now it's not look that much good right so in order to add a loading kind of effect just go to this Flash icon.com where you will find all the free icons now go to this animated Icon option and just search for any kind of Icon which you want let's say I want to add loading icon okay and here you'll find a bunch of different icon I'm going to use this uh loading uh or animated icon just click download and download it as a
gif file okay and just copy this file go back to your application in your vs code and inside this public folder I will just paste this progress. J JF file now inside this custom loading inside this do we'll add this Image source and over here we'll just access it using slash progress dogf okay here we'll give width and we'll give height and save it now if I go back to your application you will see this beautiful loading perfect but let make it in Center so over here uh we'll make it Flex Flex column item to
be in the center and we'll give margin y To 10 and we'll make justify Center so it will be in the center something like this say also uh I will add some more text so here we'll say generating your video do not refresh and you will see this text how cool right so this is our loader uh Whenever there is uh some API call going on okay now in order to M uh uh change the status of the loading you need to define the loading State initially I will make it as a false and whenever
uh the gender video script is loading for example this method is going to load here we set loading it as a true and once it finished we set the loading as a false okay so that's how we are going to show the loading and obviously here we need to pass it as a loading and save it now um from the previous uh API call right we are getting this response. data and obviously do result and inside that We have our video script let's save that script in one state so here we Define constant uh uh
we'll say video CP or we'll say uh just say video script for now set video script is equal to use State and then simply over here we'll set the video script as response. dat do result okay and save it now if you want to Tastee this let's go back back to your application and I will select the Content so let's select this uh motivational I will select this uh comic one and select the duration and simply click on this create short video and boom if you see the loading effect is showing on and boom it
went away it means we CAU the result if I go to the console here you will find the information okay that we got the information from the AI model let me talk talk about the tub guru.com where you will find all of my Exclusive courses along with the source code for each of the project not only that but you can track each course chapter by chapter here you'll get the source code the application Depot or you can even uh watch this complete video for free on YouTube how cool it is right also you can find
your own personal dashboard and you can track your course depend depends on your how much progress you did it okay and in order to join this particular tube guruji Pro Membership it will just at $899 per month okay and you will get an access to the all the courses and the source code for free now after uh generating the video script from the AI now we are going to convert this script into an MP3 audio file and this audio file then we are going to save inside our Firebase storage in order to generate this uh
MP3 audio file we are going to use a Google Cloud text to speech API now it's free To use at certain it means up to 1 million words it's free to use it means it's a lot of uh uh million words are there so you don't need to uh pay anything okay you might need to add the credit card or debit card for the verif verification purpose but they will not charge you a single penny Okay now in order to implement this one we are going to use a Google Cloud text to speech uh npm
command okay so this is a command copy this command go back to your Application in vs code and let me add new tab and just paste it here okay so it will install the text to speech API for us or the the hdk for us and if you see these are some uh logic in order to implement it okay so before implementing this one we need to get the API key from the Google Cloud so just go to this Google Cloud on a Google and then if you don't uh log to that one just make
sure to log in it and then go to the console inside the Console just search for the text to speech okay and then uh you will find this API called text to speech okay Cloud text to pitch make sure to enable this one so right now for me if you see it is already enabled but for you it might not enabl so you you will see the button called enable and just make sure to enable it okay then from this panel you can go to the API and services and inside here you need to create
a new API key so let me refresh This once okay yeah and over here go to the credentials and inside the credential make sure to create a new credential and select the the API key now in my case I already have created one okay and once you open this API key make sure you will restrict this to the text to speech only okay this this is important so that user will not uh even they've got your API key they they cannot use other uh Services okay and after the deployment of your application You can just
restick it to your application only now once you get this API key copy this API key go back to your application and inside this env. Lo file I will just paste this API key so here we'll say Google API key is equal to and paste this key and save it now if I go back to this uh documentation again I will just copy this line of code go back to your project and over here let me close all of this tab we are going to create a new API so under this API we create a
new folder called audio and inside this audio we create a new uh here we just rename gen generate audio okay and inside here we'll say route. jsx we'll do export a sync function this is a post request with a request and the um brackets so over here I will put this constant client text to speech now make sure to import this text to speech uh um from the text to spe I don't know Why it's not showing but I will import this one and this need to be a text to spee only let me copy
from this command oops sorry I think I did not copy it correctly and make sure it's text to speech and you are importing from the text to speech only so I will just remove this and import it from the Google Cloud take to speech okay now inside text to speech you need to provide the API key okay so API key in This case is from you can access from the environment file using this Google _ API _ key and then save it now you already uh initialize this reference of this text to page and with
the help of this client we are going to implement it so after that uh whatever the text you want to convert it that text you need to get it first so from here we say constant now whatever the text you want to convert into speech that text will pass to this particular API and then Along with the unique ID okay now obviously I will just destructure it from this request. Json so from that I've got the text and ID after this uh we are going to get this request with all the configuration okay so whatever
text we are getting we are passing to this one uh this is the voice whether you want the female mes or neutral VI if you want a female Vice you can just pass this as a female Vice currently the Language code I'm passing as a English USA and the type or extension of this file will be a MP3 okay so that's the reason I'm uh save it as a MP3 only and in order to convert it this is a simple uh line of code in order to convert it into an MP3 file so over here
I will just paste this one and if you see uh from this CLI reference we have this Pro um um method called synthesis size speed with all the request we passed then whatever the response we are getting That response we are going to save in the output. MP3 file in your local directory okay this is a simple example now over here I will just write NE uh return next response dot Json and over here we'll say result as for now I'll just write success okay because once it generated it will generate uh to your root
directory and later on we are going to save in our store into the Firebase storage but first we'll check whether it's getting Generated or not so now let's go back to your um dashboard create new page where we have a method called create audio file oh I don't think so we created let's create a new method called constant get audio we say generate audio file generate audio file a sync and the arrow function now inside here we'll say constant result but before that obviously we need to get the script now the whatever the uh Result
we generated right from that result we need to um pass all the uh script Okay so so what we can do let me go back to this go to the inspect panel inside the console we have this array right and from the array we need to attach all the context text okay so simply here I'm going to write a method for now we just just add let script is equal to empty and then uh whatever the video script we are getting With this text we'll say video script dot for each item and then we'll say
script is equal to script plus item Dot and the field name is contact text okay something like this and make sure to add a space and that's all and then once we have all the script ready just console it first okay like this and this generate audio file we are going to call inside this method once uh the script is generated okay okay let's Save it and let's test this out so let me close this one and we have everything ready just I will cck click on this create short video as soon as the data
is generated oh so I don't think so we did console we did console over here we call this generate audio file and this is the script it's supposed to work but it's not working somehow now over here um we we will pass this into this generate audio file we'll pass this result instead of using this State because State takes some time to uh uh uh update the data right and then here we'll say video script data and whatever the script we are generating we are just passing directly to this method and then from this video
script data we'll pass over here to this for it and then let's test this out okay now I selected everything click create short video and then boom if you see we got this complete script data perfect now once we have this script That script we need to pass it also if you remember we also uh try to get the ID now this ID is a unique ID which we want to generate and for that one I'm going to use uu ID uh npm okay so which will generate the unique uh Global identifi identification number so
let's in install this first and now in order to use it you will see this use case it's quite easy right it will generate this ID with this method so let me go back to this one Over here we'll get the ID is equal to and you id4 make sure to import this so I don't know why it's not importing but I will just copy this import statement so that we can use it okay perfect now let's call the method so here we'll say await exos do Post over here we'll call Api slash uh generate
audio and in order to pass the Information the text we want to pass the text is nothing but our script and then we want want to pass ID as a ID okay here this is the promise so we'll make a then response and then we'll simply console the response. data now let's save it and let's teste this out so obviously right now what is happening every time um we need to make a call to uh to get the script right and I don't want to waste this all the calls it's even though it's a free
right so what I Will do I will just add this uh script data over here in the form of string okay and I will call directly this audio method so instead of calling this get video script I will call get uh what we can call over here get uh or generate audio file and to this generate audio file I will pass scrip data nothing but the text okay this is only for testing Obviously we will uh make sure we'll pass it from here so I will just collapse this and we'll make make sure the audio
file is getting generated now if I close this one and click on this create short video right now if you see we have error that video script data for is not a function again okay wow so we pass the script data okay we are trying to uh generate it because it's already there so we don't need to do that okay and Uh for this example purpose I will just pass it here like this okay so whatever the script data we are passing to this one and let's try to generate it now right now it's getting
generated I don't think I don't think so it's okay if you see in network call the generate audio is still in pending mode okay and okay we got error at least something is happening okay so right now we have some error if I go to this network Tab and generate Audio we don't see any error but but inside the terminal you might see over here see so you can just debug this code and it's saying util is not Define okay so inside the route you need to define the util so if I go to the
documentation you'll file this util and Fs is getting imported so make sure to import this as well okay and then save it now let's test it again so if I go back over here clean everything in Console as well so before that I will just keep the loading over here so inside the page I will just set the loading as a true so that we will get to know it's whether it's generated or not and if I click create short video If you see we are getting uh loading effect so we'll wait so that it
will generate the audio file for us if I go to the network tab now it's done let's see in the output and if you see in the root directory we got the output now if I try To run this output file let's say it was a cold Dark Night the wind howed see okay now he generated the output file for US cool right so it means our audio file is generated successfully now once you generate the audio file from this Google Cloud text to speech API now it's time to save it into the Firebase storage
okay so that we can use it later on so let's go back to your application and in order to integrate the Firebase to your Application is quite easy so first thing you need to go to this firebase.com and the reason that we are using Firebase storage because it's easy to integrate and free to use then go to the console if you're using first time then you need to create a project but if you want to use existing project just open the project which you want to use over here you have option to add a new
project okay so just click on this web project give the project name here We'll say AI shop video generator then click on register app so it will register this application to the Firebase and then you need to install this Firebase hdk using this npm install Firebase command so inside the terminal just paste this command and then copy this all the config uh code and inside your config folder We'll create a new file called Firebase config.js and over here we'll paste this uh line of code now over here we don't want analytics so I will remove
it and here we'll say export constant we want to use a storage um uh feature from the Firebase so that's the reason we are defining storage here you need to Define it as a get storage and pass this app reference then make sure to import the get storage from Firebase SL storage okay That's all so once you export it right so that you can use it uh throughout the application also move this your API key to your env. Lo file so here we'll say nextore public Firebase API key and then paste this key copy this
environment variable so that you can refer it over here using process do EnV Dot and the environment variable name okay and then save it now next thing inside the route. jsx you need to Define the reference of the storage but before that let me go to the console and over here make sure to go to the storage okay and if you not enable make sure to enable the storage uh inside the rule section make sure to add this future date so that you can access it and you it will not deny for the permission now
over here you can create a new folder and here we'll say AI short video files okay I will give the folder name like this and add a Folder now if you want to store everything in this folder you have to define the reference in a such a way so first thing I will Define constant storage reference is equal to reference make sure to input this reference then the storage from the Firebase config and then the path in which you want to save the folder and then the file name now file name we will give with
the help of this ID which we are passing which is the unique one Right and then the extension as a MP3 okay so this is the reference uh of the Firebase storage next if you want to save it now right we'll just scroll down little bit and first obviously we don't want this line of code I will remove this because we don't want to save in a local storage but if you want to store it to the Firebase first we need to convert this audio file into audio buffer format okay so here we'll say buffer
oop Sorry buffer do from then we'll say response dot audio content and we need to pass it as a binary okay so it will come with into audio format and in order to upload it you need to provide a we upload bytes then you need to provide the storage reference which we just Define the file which you want to upload it Which is the upload uh buffer and then we'll Define the content type as audio SL MP3 that's all okay now this line of code will store your file to the Firebase and in order to
get the URL of the stored file okay we we can call it as a download URL which is equal to await get download URL and then you'll get the storage reference okay that's all now we'll return result as a download URL I will also console this as a download URL okay perfect now let's test this all together because we are we want to generate the file from the text and then we want to store it to the Firebase so let's click on create short video and right now if you see it's generated the audio and
hopefully the file is get saved and in the result we got the this download URL okay but if I go to this Firebase storage refresh the Storage because it was empty now you will see this file and if I open this file it was a cold Dark Night the audio file is generated and save inside the storage and not only that but we also got the uh the URL or download URL or file URL okay so that um we can use to store it now once we got this audio file URL we'll store it in
one state so over here I will define state called constant audio file URL comma set audio file URL is equal to use State and over here we say set audio file URL is response. data. result and that's all okay so th that's how easily you can generate the audio and store it in a state now it's time to generate the caption for our audio file so that we can use it to our video and in order to generate the caption we are going to use this assembly AI API okay now this particular API is free
to use and in their free tie You can generate 50,000 video caption of 30 second video or you can generate 25,000 video caption for a 60c video okay so in order to uh use this caption AI just go to this assembly AI let me search on Google so that we can I can show it to you okay so this assembly uh ai.com I will put the link in the description and this API will help us to generate the caption for our application now if I go to this pricing section you will you will see it's
a free and you'll Get the $50 of credit which will generate you the 50,000 plus video okay now in order to use it first you need to log to your application then you will jump to this dashboard where you will find how to integrate this particular HD gate to your application and the most important thing is very very easy to use so right now select the correct um hdk so in this case we'll select this typescript hdk obviously uh there is none of the code is based on typescript It's just a JavaScript only but what
you need to do you need to copy all of this code as it is but before that make sure to install this assembly AI uh to your application so go to the terminal copy that npm command and paste it here so it will install this assembly AI then let me close all of this tab and then we are going to create API for it and we'll call it as a uh let's make it folder and we we'll say generate caption inside that we'll create route Doj file and let's add export a sync function post request
and here we'll get the request like this now we'll copy this import statement and after that we need to copy all of this code as it is so I will copy everything and then paste it here okay now let me uh explain you one by one so once we call this one uh if you see this is the API key that uh it at generated for us okay but you can find it on their dashboard I will just remove This API key from here and I will put it in the. loal file for the security
purpose here we'll say uh caption API only okay keep it simple and save this one then over here in order to access it you can access it using process. NV do the environment variable key then you need to pass that URL of the audio file which you want to convert it right or you want to generate the caption so obviously we will get it from the constant here we'll say file URL we'll Say audio file URL audio file URL is equal to uh await request. Json okay now whatever the Json are request we are getting
um that I D structure it it and that audio file URL we are going to pass over here okay now obviously in my pre uh previous uh API call only right once we generate the audio we are getting that um download URL that uh that is nothing but the uh our file URL which we are going to pass over here then let me Remove this all of this comment then this is the data that we are passing it as a audio to the audio field and let me remove this line of code because we don't
want this one and simply we are going to pass to this uh client transcript and transcribe method okay which will return the transcript and then from the transcript if you uh want the text you can get the text but if you want the typ uh the the Tim stamp right here you can get it using the Words okay so transcript. words obviously I conso it so that you can also uh see what is the output or look like okay also let me wrap everything uh in try cach block so I will put everything in a
try catch block something like this and here we'll add catch with the exception and we'll return next response do Json and here we'll say error as error message and I'll so I want to Return the all the list of word as a result and we'll copy everything as it is and we'll paste it here okay so this is the uh all the result we are passing back or we will return to the this response okay and that's all you are ready now let's go back to our uh dashboard create new page. jsx uh after creating
the script we generate the audio file and after generating the audio file we are going to uh Generate audio caption okay perfect now in order to generate the audio caption here we need to pass the file URL and here we'll make a call so here we say first we'll set the loading as a true then we'll say await exos do poost inside that we need to pass the uh we need to make a call Api SL generate caption then the Audio file URL which is nothing but the file URL which you want to pass okay
and as this is a promise we make response and we'll simply console log the response. data. result okay that's all now this is await let make this as a sync and then we'll set the loading as a false now this generate audio caption obviously we need to uh call it inside this generate audio file once the file is generated but right now for the testing purpose I will call it On the click of this uh create Handler okay create button Handler and in order to pass this um testing file right let me get it from
the Firebase so here maybe we have inside the inspect panel let's see whether we have that or not okay so we don't have I will just get it from our uh storage because we just want that file URL right so let go to the storage and over here we say AI short o short Video oh what is the name of the path let me copy it from the audio file video files that is called files perfect and this file URL I want to pass so here we'll say file URL I will just put it at
the top so that we can use for the testing purpose okay and once we pass it uh it will pass to the uh as a post request in the post body sorry post body request and then We'll get the result okay let's save it and let's test this out so let's clean everything and just simply click on create short video obviously on that call we we are calling the generate caption method and we'll wait if you see now we generated the caption now we consol it because I want to show and if you see for
each word it mention the start time and the end time right when to display this one and when and when we want to remove this text and start Another Text SA okay when it ends this one is start and then that time in that time frame we want to show this text okay similar like the video which I show in the int introduction that how it that caption is displaying on the video okay and if you see we have this I I think 177 words and that's the reason for each word Dimension start time and
end time and this is very important now this information we are going to save in one state so let's define one state say Constant captions comma set captions is equal to use State okay and then we'll Simply Save over here we'll say set captions as response. data. result perfect okay and that's how guys you can generate the caption now you might have question now it's a free but you can generate 50,000 of video and as this is a SAS application obviously you can make money very easily and obviously in the Free tile only you can
make a money then buy the uh uh credits okay which help us to grow your business more more more and more now it's time to generate the AI images with the prompt which we generated at the first step okay so over here we already have the video script and along with that we have the um uh image prompt as well okay and this image prompt we are going to pass to the AI model and then that uh that AI model Will generate the image for us and after getting that image we are going to save
this image to our Firebase storage okay but first thing obviously we need to get the images from the AI now this will cost you a little bit once when I say little bit it means a very very less okay and for that one I'm going to use this replicate Doom model where U many of the big companies or open source model is deployed on this particular Replicate and it's you can use it uh so that um you can generate this awesome effect now in my last or previous video I use this flux Channel model but
in this video we are going to use this HDX lightning for St because that is more cheaper okay now if I open this model click on this view on replicate and if you scroll down little bit you will see in a $1 you can generate up to 74 images which is a quite large image under $1 because if you try TR open AI Uh image model which is d d 3 which cost you a lot okay but this model just cost you 0.0014 for single image so in $1 you can generate the 714 images and
most important thing it's very easy to use and it provide you the best result let's try this one so if I want to uh generate the image for this image prompt okay and if I go back to the model obviously uh first thing you need to do go to the replicate Docomo to this uh explore section and inside the explore section you need to select the model which you want to try it okay so in this case I will use this model so I will say view on replicate then you can replace with your prompt
okay you can give the quality how whatever the quality you want the width and height uh of the images as well okay so I will decrease this WID little bit and then the height I want means we want vertical one you can select the number Of output how many output you want and all the required field and simply click run oh so this height need to divisible by eight so I updated this height and simply click run now within a couple of second it will generate these beautiful images with the prompt which we mention and
if you see how cool cool and how clear and how beautiful the image is generated with the help of AI and which cost you a very very less amount okay so uh in order to use this particular uh API you need to click on this API section then once you select it make sure you are selecting nodejs the first thing you need to do uh to copy this replicate API token go back to your. loal file and over here I will just paste this one here will say replicate API token let's save it go back
to your project and over here you need to install this replicate so let me close this and paste this npm install Replicate then you need to copy this code as it is and then we'll create a new API under this API folder and we we will call it as a generate or let's it's need to be a folder so generate image now inside that we'll create a route. jsx file here we'll say export a sync function post request obviously we'll get the request and that's all and inside here inside the Try catch block will push
the copied code make sure to move this input outside of this function and then we have this replicate uh function and everything now inside here we need to pass the API key so simply inside that we'll have Au and here we'll pass process. EnV do the environment variable uh name key name so which is the replicate API token okay now inside here you have option to pass the prompt Whatever the pr you want to pass so if you see uh when you run it right so this is the uh uh the model which you are
using okay that model name we pass and then simply will conso the output now if I go to this uh schema right here you will see what are the input schema and output schema which you can pass it okay so first and very important thing we need to pass is the prompt okay now in order to pass a prompt we need to get the Prompt information from the request so here we say constant prompt is equal to await request. Json okay so from this one we'll get the prompt and that promt we are going to
pass over here then we need to pass height and if you see this is the height we need to pass I will pass one to8 Z and then we need to pass width as well uh in this case we'll pass 1024 as a Width and then uh if you want to pass number of output that also you can pass obviously number of output I will make it as a one okay and then this input we obviously pass to this uh replicate okay in order to run it so that we we will get output and once
you have the result here you can just return the next response do Json and inside the result you'll get the result in the form of Output of zero okay so this need to be the just on object perfect okay and then save it and that's all now in order to test it let's go to this create new page where we have the uh gate video script okay after that in that gate video script we are calling the generate audio file I just uncommented this code okay so that it will run the video script data with
a for each and all the text we are going to s in a script this script we are Going to pass to the generate audio API in order to generate the MP3 and then from there we are calling the generate audio caption method to generate the caption okay now another method we'll call called generate image and inside there uh in the generate image right we are going to generate the list of images so over here uh I will remove the loading from here and I will put in a generate image Okay so that until in
everything is finished the image uh once the image is generated then only we are uh disabling that loading indicator then over here we'll call await exos but before that obviously um from the video script because we generated the video script right we need to get the image prompt so we'll use for each Loop so here we'll say for each element we'll get the image prompt so every time if we have the five image From the five times we are going to call the API currently I'm not sure whether this uh replicate is supportting uh with
the uh what do we say the bulk image of upload or bulk image prompt so that's the reason we'll do one by one so over here uh now we'll say await exos do Post method inside this post method we are going to call Api SL generate image and then we need to pass the prompt so prompt will be in this case is element Dot image prompt because that is the uh fi name so I will just copy this field name as it it is and I will pass over here um make sure we'll make this
as a sync okay and once the image prom be generated we'll make then response and from response we'll get response. data do result okay so inside this result uh once we have the image prompt URL right simply we are going to um save one state so constant image list comma set image list is equal To use State and uh obviously we are going to set but before that inside this uh generate image I'm going to Define oops over here we'll Define l images okay mty array and we'll simply push images. push with the resp response.
data do result okay and once we have all the information not over here but we'll set the image list with the Images okay obviously this will be the array but let console over here as well so console.log images perfect okay and then once we then with that one we'll set the loading obviously here I will call generate image uh method okay and let's save it now for testing purpose I don't want to generate everything at once so what we can do we can copy this all the Json file Okay and uh I will paste over
here so constant script data script uh or we video script you can say video script is equal to and paste everything as it is okay this is for just for testing purpose now I will just generate these first two images okay because I don't want to spend my money so I will just generate these two images From the video script so what we can do on the click of this Handler like a previous testing uh we will generate the images only and to this image um let over here I will use this video script for
testing okay obviously later on we we are going to change here I will use use to generate AI images now let's save it and let's taste this out so let's go back to our application Let me refresh this ones and Then simply click generate short video so right now let's if I go to the network tab if you see we got the two images which is generated if I open this images you will see boom see we got these beautiful images generated with the help of AI okay and if you see how quickly it generated
it's a much much faster than op AI dlay 3 Model perfect now once we have this image obviously this image we need to store it into our Firebase storage okay so that logic we Are going to implement over here only because we don't want to uh pass to the client side and then upload it now in order to let me close this one and in order to save the data to the Firebase so here we'll say save to Firebase okay first we need to convert these images to a base 64 but we are getting the
result in the form of the URL the question is how to generate it so for that one I'm going to write one method called constant convert Image okay and inside this convert image we are going to to pass the image URL okay and inside this one obviously this method we are going to call over here as soon as we get the output so output will be in the form of URL okay and this URL will be passed to this this need to be a convert image okay and inside this convert image we are going to
Simply add try catch block and inside this try block we'll simply write constant Response is equal to await exos doget so I don't know why we got error but let's say a Sync here we'll say exos dot gate request and inside the gate will pass the image URL and the most important thing you need to provide the response type as array buffer okay once you done with this one we'll simply say constant base 64 image is equal to buffer do from Response. data do two string and here we'll say base 64 okay so it will
generate into the base 64 image and simply we are going to return it as a base 64 image that's all okay otherwise we'll just return error okay obviously doesn't make sense just consolle it as a error with the E okay perfect now this convert image we are obviously calling Over here and then we got this Bas 64 image uh over here I'm going to do constant base 64 image is equal to okay okay and then we need to make sure to attach B 64 format so this need to be like image PNG and base 64
okay so this is very important to attach it to the start of this convert image okay so it's called data image PNG base 64 okay then plus and then we'll use a to convert the image now once we have the base 64 image URL we we need to generate a file name okay now this file name we are going to store in the same folder so I will just get the folder from the audio we'll get the folder name so this folder name we want to use it so simply here we'll say AI short video
files slash and over here I'm going to generate do now okay so it means it will get the current timestamp and it will be unique every time and Then PNG file but perfect right so this will be our file name now generate the image storage reference I we will call it as a is equal to uh reference then storage from the Firebase config and then you need to pass the file name like this after this we'll say await upload uh string so we can say string then here we'll say storage reference comma base 64 image
and then it will be the data URL Dot then simply call snapshot to this one even though did not call that's also fine okay so this will upload our image to the database or this need to be a storage reference so this need to be a storage reference okay and basic image with the data URL as a type and then once we upload it we can get the download URL is equal to await get download URL from the Image uh this need to be a storage reference so whatever the storage reference will be passed from
that one we'll get the download URL I will just console if you get any error we'll get to know whether it's printing or not and then this download URL we are going to pass okay and it will return from this API and let's save it and that's all so that's how you can save uh your images to Firebase because the reason that we Are saving this one because replicate will store your image only for hour okay and after that they will just remove it from their server so that's the reason we need to store that
into our uh database or into our storage so before testing I just realize we need to add a comma over here and and then save it okay because otherwise this format will be wrong and then we'll get the error now let's test this out I will open the inspect panel and inside the console and Network tab as well and click create short video If you see the generate image is getting called and is pending at the moment but we'll wait and this is generated if you see we got the preview with the Firebase storage URL
and if I go to the Firebase if you see uh if I reload it boom if you see we got this two beautiful images perfect right now obviously this images is generated with the help of AI only okay and now we also got the URL if I go to the console you will see this two URL getting uh return from that API and now obviously uh that both the API we already uh pushing into the let me go to this page.js into our state okay so over here we already pushing it through this images okay
so that's how guys you can uh generate the images so it depend on how many images you have and then you can simply generate it now let's test End to end okay now what I will do I will just un comment this one and I will comment the video script now this particular method will get the video script this will uh generate oh sorry generate audio file and save to Firebase storage then this file will uh audio file okay this file will generate the caption used to generate caption from audio File and then this will
generate the AI images so at the last what I will do I will just console everything so here we will say images then I will say video script then also we'll say uh audio file URL and the captions as well okay so everything we just consolid to make sure that we are getting all the data okay and make sure inside this generate image now we'll pass the actual video script okay so that it will iterate it let's Save it and let's test this out and one more important thing once we have the audio file then
we need to call this generate image okay um over here I will ask I will add a condition or another way that you can do it instead of using then you can just get the result over here but for now I will just use this condition and and okay and save it now over here uh inside the generate Audio file we are passing this video script data right and with this help of video script data this video script data we are also going to pass to this generate audio caption so here I'll be pass it
as a video script data so whatever uh the script for the video along with the image prom that we are going to pass from the audio caption or audio generate file to the audio caption file so over here I will say video script data and again from this video Script data I will pass it to this generate image method and here I will accept it like video script data and then we'll use it as a for each Loop okay if you want to print I will just print it here like this and I think we
are good for now also just want to make sure that I I remove this uh dot then okay and the response so it's better you can get it inside this response and you can get the result because this await ex your post will return value to this Response okay and same thing I did it for this audio caption as well so let's save it and let's test this out now one more important thing over here that inside the for a wait uh this is not not how it going to work it okay so I will
just remove everything from this one and let me remove this console for now and over here we want to use for with a constant as a element off and then we'll use video script data okay and inside that we'll Add try catch block and inside this try block now we'll say constant response is equal to await xos do Post request to get the a make a call to this API generate image okay and then obviously in that one we are going to pass a prompt as element do image prompt okay something like this after that
one uh we'll get the data so I will just console it as a response do data do result and then Inside this images we'll just push it so images dot sorry dot push and we'll say response. data. result okay so we also console but also make we will make sure um we'll console it also over here we'll just say error in the console if if you get any error with the E okay perfect and later on we are saving this information inside this particular State now one more important thing here we need to make sure
um we need to save all of this information in one state and for That one we are going to use a context because we want to pass this information uh in order to render our video and then we can EXP export it right so it's little bit um uh easy way okay but don't be confused so first thing in order to create a context we are going to create a new folder called underscore context and inside this we'll create new file called video data context. jsx now over here just make sure to export this video
data context is equal to create contact From the react make sure it is importing from the react now this context will help us to share your data along the multiple uh component it doesn't matter it's a parent component or child component but we have to make sure we have to wrap this inside this dashboard layout okay either you can make this as a client or you can uh make the provider and then you can make the provider as a client I will make it simple and I will just add over Here then inside this we'll
add video data context do provider and inside that we need to provide some default value now over here I will just make sure to wrap it so all the component which come under the dashboard or any route come under the dashboard it will share the uh context data the default one I will put as a video data is equal to use State okay it's empty obviously first initial and then this video data I'm going to Pass over here perfect and save it next Once We this uh use this one the video data and set video
data and we are passing as a default one to the this context now it's ready to use it so I will just copy this and save it and go to your page. jsx inside this create I will remove all of this code now because we are done with the testing we know that everything is working all the API is working as expected right now inside here we'll make sure you are using curly Braces uh when you want to use context and here you say use context and then you need to give the context name so
in this case the context name is video data context okay perfect next whenever at every method whenever the data is generated we need to save in that particular state so first thing let me remove this console and over here we'll simply add set video data here we have to make sure you'll add the previous data along with so here I will add Spread out operator along with the fill name so in this case here we say video script and then the value so value will be response do data do result okay now same thing I'm
going to copy it to generate audio file over here as well I'm going to set if you don't want to this this state you can just remove because we are maintaining in this context okay over here uh will say just audio file URL as a fi name then for a caption I will remove this console and Here we'll say captions and the last we need to generate uh save the images so here we'll save image list okay and then save everything so now in order to check whether you are getting data or not what we
can do we can just write one use effect and we are going to execute this use effect whenever the video data uh going to when it's Chang we are going to display or console the video data okay so you'll get to know at each uh Progress that uh we are getting the value or not let's test this out so let me refresh the screen once and let me clean this so let's select the content type let's select the motivational the style realistic duration we'll select 50 seconds and just run it now initially if you see
it will generate the script and if you see this us effect will get execute as soon as it has a data into that one then it generated the audio file URL If you see this audio file URL and it is Sav into the our state as well now it also generated the captions that's how cool right and now we are waiting to generate images the first image generated now this image is printing one by one the reason is inside the generate image we already put this console okay but at the last once all the images
are generated one we have the error the response is not defined maybe uh but let's say whether we are getting All the data we got all the data but somehow we have one error that respon data is not a result oh so my bad so over here okay instead of this response data we need to save it as a images okay because inside the images we have the list okay and not this response data. result because we skipped it outside of this for Loop okay so we have to make sure we'll put the images over
there but other than that everything is working as expected now okay now once you have this Context data with the help of this context data we are going to uh render the video along with the all the information and that's the magic going to happen okay everything we are going to keep it and for that one I'm going to use a very popular Library so I will see you in the next chapter now whatever data which we generate uh like generating the uh script audio file or the audio file URL uh captions even the AI
images we need To store this into our database okay and for that one we need to create a new table so obviously in order to create a new table we need to update our schema file so let's go to this config folder and where we have the schema inside the schema we need to create a new schema called video data is equal to PG table and here I will give the table name as a video data and inside that we'll provide all the uh information so let's Say this primary key with this ID and all
then we need a video script okay so for that one we'll add Ware not Ware but we want to save it as a Json so make sure to import it from the PG core so you can also save it as a uh Json only okay instead of this we can just write a script that will be little bit meaningful then again this is not null after that we want to save the audio file URL again this is simply a Ware so here I will give the F column name as The audio file URL this is
also not null after that we I want to save the captions okay the caption is in the form of Json and the column name will be the captions again let's add it as a not null and the last we want to save the image list okay now this image list we want to show the um list of array okay but it is of Vare so you need to Define Vare with a column name as a image list and then you can make it as a array okay and the last the created By the users email
ID who created this video data right so that's email ID we want to save so here I will simply add the created by column okay with a not null perfect and all of this information obviously you want to save obviously in order to create this table you need to run the DB push command so here we say npm run DB push so what it will do it will create a new table for us okay and if you see it's saying changes applied now You can run the studio and if I go back to the studio
and refresh this screen you will see the new table is now created perfect right now next thing whatever data we have in the context from there we need to save inside this table so let's go to this uh create new page and I think yeah over here and over here we I'm going to create a new method called constant save video data and inside this this save video data we going to call um from this use Effect okay so here I'm going to simple write a condition if object dot keys and we'll pass the video
data so this not to be this small case video data do length is equal to equal to 4 then I'm going to call this save video data Okay the reason that I'm going to use this uh condition because video data is just a object okay it's not a list of object and again in order to get the length this is the method or this is the way That you can get the object length that it means you can just check in that object how many fields are there and if there are four Fields it means
uh like script uh the audio file URL the captions and the image list if this four field are there then you are going to call this save video data and to this one I'm going to pass a video data here let's get it as a video data only and in order to save it just simply set the loading first as a true then you need to Add con result is equal to await DB do insert here you need to provide the schema name which is the video data dot o sorry let's add a DOT values
and inside that let's add the script first so script data we can get it from the video data dot make sure the name is correct so this need to about video script the field name then we want to call audio file oops audio file URL as a video data do audio File URL then we want to call captions which we are getting from the video data dot captions and the last created by I think we forgot one more but let make this ass sync first and along with that we want to pass image list and
video data do image list and then created by obviously in order to get the created by you need to get a user's email so over here I will WR get it from the hook call use user from the clerk and then you can use over here so Simply we can call it as a user. primary email address. email address and that's how you can get it in order to return that data you can simply return the ID which is inserted newly so that you can get it from the video data do ID and test is
pretty much let's console. log result and then we'll set the loading as a false okay perfect and let's save it and let's T this out now if I go back to your application go to The inspect panel and go to the console and I will s s the content typee as a historical fact the realistic image and the duration I will select as a 15 and click generate video content so now we'll see now the video script is ready if you see the video script is showing because we just console the context or video data
context inside the use effect that's the reason it's showing now the next the video URL or sorry the audio file URL is also Generated next the captions uh is ready now here we also got this data but somehow let's see in the database or maybe in the network tab uh our method did not get called we are supposed to get called this save video data but is not getting call over here and uh let's see in the database yeah it's not there let's see why it's not showing so this is correct the object. keys and
we are passing video data with the length and four and Then it's supposed to call this method so the thing is I just refresh this screen again and now it's working if you see the length is one me the new record is inserted with the ID3 and there is no change okay just I refresh this because maybe the update update was not successful in the browser sometimes so make sure in the crucial way time you have to refresh your screen because even though the logic is correct and it's not getting updated on the front end
side Right but let me show you the data and if you see we have the script which is in the form of Json the file URL which is the just string the caption again this is Jon the main important thing the list of image if you see this is the list of array how cool right and then the user email ID who created this particular data now it's time to build a video from the content which we generated so once we save the data into the database we Have the ID of the inserted record so
for example this is the record or latestly we are inserted right and that ID we are going to get it and then with that ID we are going to fet all the information from the database in order to display the record or or display the video now for that one we are going to use very popular the remotion DJs Library which convert the programming code into the video okay and I'm I'm going to um go in the detail in a moment But before that let me explain so we are going to create a remotion video
component and to that component uh we are going to first displaying we are going to display the image then we are going to add an audio to that video or to that images and then we are going to add a caption on the top of that image and together everything we are going to build and complete video now uh let let me talk about the UI so as soon as the AI generated all the content it Automatically generate the video and it open a dialogue for us on that dialogue you will see the text call
your video is ready and you can actually see your video so over here we are going to integrate the remotion player where you can play the complete video and you have option to cancel it or you can option have to export that video as well now once you cancel it it will redirect you to the dashboard and then that's where we are going to show all the um user Generated video list okay so first thing simply go to the uh remotion so if I search on the Google you will see this site called remotion dode
and now this is free to use okay the license is also free to use also uh if you see the title it's saying the make a video programmatically and it's very easy to use they have support to the nextjs as well so with the help of nextjs you can build it they have some predefined template if you want to use that one as Well and they also have the remotion studio where you can actually try and edit it but we don't want to go in a little in in that detail it's little bit complicated but
you can explore this one and if you really like and want to see more video on the remotion dod please comment in the comment section so first thing let's go to this documentation and in the installation section you will see how to create the project now we already have the nextjs project created okay so You don't need to follow this step but if you scroll down little bit here you will see the option called installing in existing project so click on it and first thing you need to do is to copy this command go back
to your application and inside here inside the terminal I will paste it so it will install the remotion and the remotion CLI then if you scroll down little bit we need to create a new folder called REM motion and inside that we need to Add this composition. TSX file okay then we need to create this root. TSX file and the last we need to create this index.ts file so once anything install let's create a new folder called remotion so let's go back to your application let me close all of this tab for now and then
inside this root directory we are going to create a new folder called remotion now inside this remotion this my composition is nothing but the Uh video component okay we will design it in a moment but uh okay let's do one thing let's go to this uh app folder and inside that we have dashboard under that dashboard we have this component and over here we'll create video render or we'll say remotion video. jsx Okay add a default template and then save it now in that component obviously we are going to implement lot of other things but
next thing you need To create a root. jsx file and inside that you need to paste this composition okay so I will copy this one then go back to your uh remotion folder over here we create a new file called root. jsx or you can create with this capital r and then add a default template and over here I will just paste the code which we copied now inside this composition make sure this composition you need to import from this remotion And to this component we are going to use a video a remotion video component
the the component we just created okay remotion component from this dashboard component and now this contain the duration in Fame FPS with height and lot of other things and then let's go back again and then we need to create this index.ts file this is also very important okay here I will just rename this to remotion root so here you can REM rename this To remotion root so this is little meaningful make sure to export this one as well and then here we'll create an index. jsx file and in that one we are going to paste
this line of code as it is okay and save it and that's all this is the simplest way that you can um integrate the remotion now if you want to run the studio you can just run this command and it will run the studio now in the studio you can see Actual editing format and everything okay and in order to render video this is the command to render it but we'll do it in a moment but before that uh let's go back to your application and obviously right now you are not able to see anything
right because we don't have any output now for that one we are going to use a remotion player uh which we are going to integrate so inside the dashboard and under this component folder only I'm going going to add a new Component called um player dialogue. jsx okay and inside that let's add a default template and save it now over here we are going to add a dialogue but in this case I'm going to use this dialogue component from the Shad CN okay now in order to use it just copy this mpm command and make
sure to in install into your vs code project then copy this all the input statement paste it Here and then in order to use it you need to copy this line of code and simply paste over here okay now obviously with this with the help of this dialog trigger it is opening this dialog bit but we don't want this dialog trigger so I will remove it um also you can keep this title if you want and in the description we are going to add the ACT actual player now in order to add a player like
if I go back to our remotion uh document and over here on the left Hand side you will see this players uh documentation uh if you want to see the example this is the example and inside the API reference so you can jump to this API reference as well let me go back so let's let's uh copy this example so I will copy this player component okay and we'll simply paste it here make sure to import this dis player component so this is the import statement and simply paste over here Let's save it and in
instead of this component we are going to use this remotion video component okay which we just created correct so remotion video and save it now this duration in frame it means how long your video is then width and height which you can mention let's say you want to give uh some different width so that also you can add it here so over here I will just give 300 and 450 okay because it's kind of vertical uh 9 s to 6 or 1692 as I Think uh that ratio that we need to follow okay and I
will keep everything as it is next I will just change this title to your video is ready then I will add a class name and we'll add text is of 3 Excel and font Bol margin y to five and save it now next thing this player video we are going to use it inside our uh create page create a new page because uh as soon as the content is generated we Need to open this dialogue and we are going to open programmatically so over here I'm going to pass the uh we are getting some value
from the parent component and here we'll say play video it will be true and false and then we'll also get the video ID which you want to play so over here I will just Define one constant called open dialog comma set open dialogue is equal to use State initially it will be false and inside the use Effect as soon as player video is uh has some value it will execute the set open dialogue with the play video value okay so we'll pass the value true and false let's save it and inside this create new where
we have page. jsx at the bottom of this maybe after this custom loading you can add uh player dialogue okay and this player dialogue uh has the player video property which will be a true and false and the video ID property uh which whatever the ID you Will pass that ID information uh it will F inside this player video but in order to play the video we need to Define some state so over here I will say play video comma set play video initially it will be false and as soon as and also I will
Define one more and over here I will just rename this to video ID okay and over here I will keep it empty but if you scroll down as soon as You save this data into your database that's where we are getting this ID and over here we'll set the video ID as a uh result of result of zero do ID and then we'll just set play dialogue play video as a true okay so it will actually open this dialogue and over here we'll pass the video ID okay I will just make sure the video IDE
okay that's fine it's not big deal And I think we are good on this one okay now inside this player dialog um for now for the testing purpose only um I'm going to make this as a true and over here we'll pass let's say pass one as a video ID and save it so what what what will will happen if I refresh it right it will open the dialogue for us and it's not opening somehow so let's refresh it again just check so over here we make this play video as a true okay so inside
the player dialogue uh we have To make sure once we have this play video value we have to pass it to the open and over here we'll make it play video so if it's oh this need to be open dialogue because we set the value to the open dialogue and then uh if open dialogue is true then uh we pass to pass pass this to the dialogue and it will open the dialogue for us if you see the dialogue is open perfect but over here uh we'll add a class name and we'll make background White
okay perfect and if you see right now it's just showing the text called remotion video because inside this remotion video component we have only text called remotion video okay uh also over here I will make it Flex Flex column and item to be in the center so it will be in the center of the screen see perfect right if you want obviously as I told told you before we need to add two button one is for the Cancel and another is for the export okay now to this cancel button I'm going to add a variant
as a ghost and for this one I will make it flex and gap of 10 and save it okay two button something like this and one is cancel one is export perfect now it's time to get the data inside the play video okay depends on the ID which we pass so over here we'll say constant uh get video data from the Database okay now here we simply say constant result is equal to await select sorry DB do select from the database name so in this case we have the video data from the schema uh do
where because we need to pass a condition which is equal to video data. ID which matches with this particular ID okay so over here we say video ID let make this as a sync and over here we'll just console the result for Now and also once we have the result we are going to save inside the state if you confus uh while understanding this you can ask me the question in the comment box as well okay now over here I will just set the video data as a result of zero okay and this get video
data I'm going to call as soon as we have the video ID information so over here I'm going to call this method perfect right if you want to execute on video ID you can just Execute as well it doesn't matter because as soon as we have playar video right information it means we also have video ID information I will just make sure that uh because if you see the ID one don't have record let's let's pass the I will pass this four ID okay which has a good uh story so if I go to the
page.js where we have this video ID by default I pass it as a three and save everything and if I go Back to your application inside the inspect panel inside the console let's see whether we got the data or not so I will refresh this once and if you see inside the play video we got the information which contain the audio file URL captions created by image list script and all of this information okay now this particular data which we are going to we need to pass it to this remotion video component okay which we
integrated into our player okay me Format this perfect now we need to pass to this remotion video so what we need to do we just need to add the input props okay and to this input props we'll just dest structurize the uh all the video data so it will pass the all the field one by one and save it now if I go to the let me go to this remotion video now here we'll accept all of this information okay so it will we will accept it as a Script then image list audio file URL
captions and make sure everything is correct Script image list options audio file URL and perfect okay all of this information we pass it because we want it we want it in order to show now remotion has a lot of different component okay which help us to build the video with the help of the data which we are going to pass okay and obviously you can uh just go over here And you can find all of this information to their documentation and obviously uh I'm not going to explain everything but whatever is necessary the main important
component from that you can build any kind of application like this okay so first thing we need to do let me remove this de over here we need to pass an absolute feel from the LI motion okay it will give you the a kind of canvas or kind of D tag inside the remotion okay to this uh uh absolute field you can add The style and over here you can provide the background color Okay so the color I will say black okay and then save it now if I go back to our application over here
you will see the black color and the background okay and this is your actual uh video which going to render in this particular box okay now if you want to give a telin CSS classes you can also mention that one if I add a background as a white and Let me Refresh this once so if you see background is coming white okay we want to give black background and boom see okay so it's up to you how you want to mention it then we want to render the all the image list which we added over
here okay so simply you can iterate that one so using image list do map inside that you can add item comma index and the arrow function something like this okay now inside here we want to show this image list in the form of Sequence so it's kind of one after another right and we have to mention that when the image one will start and when the image one will end and then when image second will start okay so it's a kind of sequence so here we need to provide the sequence component from the remotion and
inside the sequence component let's add a key as a index and we have to mention the start time okay and then you need to mention the Duration in the frame so duration in frame is nothing but how much much duration it will stay into our frame and when it should start okay now we will calculate over here uh the duration in a frame and it's very easy to calculate so first thing in order to calculate the duration frame okay so over here I will Define method called constant get duration frames and inside here uh we'll
simply Return from the camshot so what we need to do from here we actually we will get the length of our video okay and that we can get it from the caption so if I go to this caption okay and if you grow at the bottom for example okay so this is that's where our uh um video is going to end okay so this is the time when the video is in it means this is the maximum time and this time we need to get it so in order to get that time you simply need
the captions of Captions. length minus one and do n okay so do n is the fill so we are just fetching this last uh object and from the object we'll get we are getting this end uh fill value and then we'll divide it by 1,000 and then we need to multiply it by the um frame per second so in order to get the frame per second so so we'll say FPS is equal to with the help of use video config from the remotion okay so with the help of this hook we will get This FPS
value and this FPS value will multiplied by this uh to this particular uh caption value okay in order to get the frame value uh in the form of remotion now this will simply return the value for us so now once we have this gate duration frame we'll pass it over here and in order to do that we need to get the index value whether this is a first image or second image then we'll multiply it by the gate duration Frame I will just frame rename this okay and then we'll divide it by uh number of
images so in this case we'll say image list dot length okay oh so this need to be [Music] dividation perfect okay so this is the way that you can um mention from the start what is start time and the end time and the form the for the duration we'll simply get the duration frame something like this okay and now inside The sequence uh the remotion has their own uh component called image okay and through this image we are going to render our every image okay so inside the source you can just provide the item because
this is just array and then inside the style you can provide the width as a 100% the height as a 100% And then you can mention object fit to cover okay and then save it and let's Teste this out so if I go back to your application and boom if you see we have the image I just want to use another one so I just change the video ID to four because I want to play this uh fourth record and if I go back here you will see uh the video is showing or the at
least image is showing right but you cannot control this one so in order to add a controller uh go to this player uh dialogue and inside to this player component it has a um auto play or Controller I think it has a controller uh component so let me add it here control is equal to true so it should be a controls and make it true and if I go back you will see the controller now if I play this video you will see the video is playing on the screen okay but it's right now it's
playing for only for 4 seconds that's because inside this player we mention the duration in frame only one 120 okay so that's the reason because each frame Is of 30 seconds so if I increase this one 30 millisecond I think so yeah but if I increase to let's say uh 1200 now you will see it changed the the uh size changed to 40 second the question is how to get the duration in frame whatever depends on our uh length of the video right so what we need to do uh we have to pass this duration
in frame to this player dialog so simply uh we are going to set duration in Frame and we'll set this value as it is and then this particular value we are going to pass to the previous component okay now let's let's save this one and inside this player dialogue I will accept it here like this okay and then whatever the value or here we will say frame value we'll set it to one state so here we'll Define one state called duration in frame comma set duration in frame is equal to use State okay initially I
will Just add a default value to 100 but over here you can set duration in frame as a frame value okay once you set it you can replace it over here so duration in frame so this need to be with the E I will update this text and then save it so right now uh so we have an error it's saying the player uh component must be integer but we got the floating or or double number right so this need to be a number okay so over here you can just make it as a two
fix to zero and then Convert it into the number so it will be in the form of number and now if you see whatever the length of our video it only show that particular time okay now if I play this video you will see after certain time it will render the second image and the third image and the so on see and this is your basic video is now ready but obviously into that video uh we need to add an audio as well and this is a uh in order to add audio I'm going to
do you the Simplest way to add it okay so let's go back and before that I want to uh give some space between these button so we'll add margin top to 10 so we have some button and I think that's fine and if I go to this remotion video right after this uh sequence over here you can add the audio file from the remotion and to this audio file you have to provide the source property okay now to This Source property you can provide the uh URL of your audio file so in this case we
already have the audio file URL see this one and that audio file URL will just pass over here okay now if I play this video you will see the audio file as well he was a poor boy living on the streets with nothing but a dream and a Heart full of ambition see okay and obviously this video length is equal to the audio file uh length as well so that's how you can add the audio to your Uh player as well okay perfect now next thing we need to add a caption that is very important
part of this particular video now in order to add a captions simply uh over here I'm going to add a new field called absolute field and to this one inside this we'll add h2 tag to render the uh caption and to this absolute field I will add a class name I will make the text is of white then we make justify to be in the Center then we'll make align item in the center then uh we'll make it bottom to 10 and we'll give some height to 150 pixel and just Define top to zero okay
and save it if I go back you will see this caption over here which is in the middle actually but let Define I don't know whether it's has undefined or not but if I remove this top it's still showing so over here you Can uh to this one this tile is not working but can make this Flex width full and if I save it the caption is coming at the top let's make height to be full so let's try to wrap these images inside the absolute field first okay and to this absolute field We'll add
a style with a justifi Content as a center and then uh align item to be in the center so everything will be in the Center make sure to wrap images and caption inside that so over here and then I will just remove this class name from here and we'll add a style so inside that we'll add a color as a white this is the text color then we add justify content to be in the center then we'll add a top as a undefined so it has a value undefined as well then to the bottom we'll
give a 50 and height let's add 150 and if I go back you will see this caption over here but let make this text align to be in the same Center and width 100% so it will be in the center see okay so the caption is showing on the screen now to this h2 tag We'll add a class name and we'll make it font uh or make it text is of 4 XEL let's see how it looks H it's quite big You can make it so I make it three let's see I think three or
two is uh fine okay and if you see this caption now what are the captions which we have we have to render it inside this h2 tag so for that one I'm going to use a method and from that method we'll return return the captions okay depends on the uh current time because we have the start and end time for each of this word in the captions okay so if you see in the caption we have the start and end word And whenever um the frame is running in between this then we are going to
show the text and it's quite easy actually so here we'll say get current captions and inside that first we'll get the current time so here we'll say current time is equal to frame now in order to get the frame information right we can get uh we will use the constant frame is equal to use current frame okay from the remotion so what it will do it will give the current frame time Whenever you play it okay uh so it doesn't matter even though you stop it will give you the frame time of that time as
well only and here we'll say frame divide by 30 into 1,000 okay so which will convert frame number to M seconds okay uh so if the time or your uh FPS is 30 then after that we will uh get the current caption so here we'll say current caption is equal to caption do fine oh so this need to be a Captions do fine now obviously this captions which we are getting from the our caption which we which the player dialog already passed and inside that we'll find the word okay which we want to use here
will say current time is greater than equal to word. start time and if the current time is less than equal to word do end time it means if the start time is and the end time whatever is between that Current time is there then only we'll get that word and that word it will be save in a current option then we'll return this current caption as it is okay if the current caption is there then we'll get the text otherwise we'll pass empty value because it will return this field and from this field we need
to write the text now this get current caption we are going to pass inside this h2 tag something like This okay obviously inside this curly braces and then save it now if I go back to your application and run this video you will see the text is playing on the screen he was a poor boy I just refresh it and if you see po boy living on the streets with nothing but a dream and a Heart full of ambition and as soon as uh the audio is started it's exactly matches with the caption as well
okay and that's how Scavenging you can add the caption to your video okay so guys that's how you can generate the video with the help of the AI generated image the script the caption the audio file as well now in the video if you want to add that effect like zoom in zo zoom out effect or bouncy effect or shaking effect you can also do that obviously if I go to the documentation here you will find the zoom in zoom out effect okay see so if I go over here I don't know but yeah you
Can just search it on the documentation and then you will get all the information so obviously I'm going to add that effect into the source code as well if you want it you can get it from the source code the link is in the description or anytime you can go to the tui.com to get exclusive access to the all the source code of my projects now in order to add an effect you need to make a little bit modification so first thing uh inside here I'm going to Wrap this inside the curly braces so let's
wrap everything inside the curly braces and then let me take this back and simply we are going to return this okay if I save this one and make sure that that everything is working as expected so if you see everything is working as expected next thing let me get this down and over here we are going to create constant called start time okay and to this start time we are going to apply This particular condition as it is okay so I will cut from here and simply I'm going to paste it here okay so obviously
uh this particular start time we are going to pass to this start time now every time whenever you make a change make sure it's working as expected and it's not breaking anything next thing uh we'll calculate the duration so duration will be is equal to gate duration frame okay which we already defined over here okay once we have the duration now we Are going to scale the image okay and for that one we are going to use the interpolate from the remotion now to this interpolate uh you can provide the some of the parameter so
if I go to the documentation and search for interpolate okay here you will find the example how the the why the frame size you need to provide the zoom in zoom out size and everything okay so that's how we are going to add it here now inside the interpr interpolate we are going to Provide the frame size now this frame size we already defined okay so each frame uh value it going to pass then we are going to pass the start time after that the start time plus duration ID by two okay duration divid by
two and then start time plus duration okay so this is the zoom in zoom out logic okay so here I will write zoom in and zoom out okay after that you need to provide the uh the start Zoom start time okay so where it is original Then the at up to what point we want to zoom in and then again it will Zoom back to the original position okay so that's how we you need to provide value and then these are the extra polish left I don't know what this about okay but I just put
it over here left to clamp okay and then here we'll say extraor right to clamp and save it now if I go back to Our application we caught an error let's see what's the issue so over here uh array is not iterable inside this uh array okay let's see why so after refresh it works sometimes next just need to reload let me close this and if you know see it's working okay but obviously it's not uh we did not apply this scale yet okay so just inside this image we are going to add a transform
and over here we'll Say scale and inside that we are going to Simply Define this scale we'll pass the scale value okay now if I pass it if you see it's slowly it moving okay and obviously if you see again it's very slowly it's moving from uh 1 to 1.2 so here oh I think I made this one point let's make it 1.8 and then you will see the actual effect Vision okay it means I'm just muting this audio and over here you will see the zoom effect okay now This Zoom effect you can change
it little bit depends on the condition as well for example if you pass the index over here let's pass this index and this index we are going to get it inside the scale property so let's go over here and we'll say index now whenever the index mod 2 is equal to equal to zero means for alternate image we are going to pass zoom in and zoom out if index Mod 2 is equal to this one then we'll pass this value otherwise we'll just rever this one little bit something like this okay let's try this and
let's see whether it's working or not see I'm just zooming in little bit but right now it's uh zooming in and now it's zooming out perfect right so that's how you can add zoom in and zoom out effect now from the remotion document you will find more use case of this one okay and you can add more effect to your Video now once user closed this dialog obviously we want to redirect user to the dashboard and on the dashboard we are going to show all the video which user generated on the screen obviously later on
he can come to the dashboard and they can he can see his video any time okay so if you see on this prototype uh we are just going to show the all the video directly on the dashboard and on the click of that one again we are going to uh show the Dialogue which is existing component in order to play the video so first thing let's go back to your application and let me close this tab and inside this dashboard okay so we have the page. jsx file and over here we are obviously right now
showing the empty state but also along with that one we want to show the list of video so over here I will add I will add like this up let's list of Videos okay now we'll create a new component for that one so inside this component folder we'll show video list. jsx add a default template and then save it now over here first thing we need to do is to get the list of videos so here we'll say get video list and inside that we'll say constant result is equal to await db. select from the
video data and here we write a we CLA okay so make sure you added dot where equal to The condition is video data do created by because we want to fetch only data which is created by that user okay so here we'll say video data. created by and then we need to pass the user name okay so over here we'll just add constant user is equal to use user and then we can pass user. primary address. email address and then from here we'll get the result so we can console this result if you want and
then uh inside our set video list we will push all the Result like this okay here we'll use use to get users video Perfect now we we got this one obviously this method we need to call inside the use effect so whenever the user is loaded or user information is available then only we'll call get video list perfect now if I save this one and go back to your application now obviously on the click of this cancel let's implement the option where let me go Back to this create new inside the page. jsx first thing
in order to programmatically route we need to define the router from the next / navigation and on the click of cancel so actually we are supposed to Define here this inside this dialogue component okay so I will add it over here now I import this use router and then make sure it is importing from the next SL navigation and then on the click of this cancel We'll say onclick here we say router. replace and then we'll navigate to the dashboard because we don't want user go back to the uh create new page okay so that's
the reason and uh if I click cancel okay so maybe I need to refresh it but it will navigate to the dashboard page now once we are in dashboard if you see now we have the video list and that's the reason that create new or empty state is not showing anymore and and if you see In the array we have the three result so let me close all of this tab now and we have this video list okay inside the video list we are going to accept the video list okay all the list of video
and inside the component here I will use video list component okay and to this video list component we'll pass the video list State now inside here first thing I will add a class name margin top to 10 and inside this video list we are going to Uh iterate all the list of videos okay so simply over here we'll add video list do map video comma index and the arrow function inside here uh we'll Define a du and again inside this one you can even show the player but in this case I'm going to uh Define
the another component so if I go to this player you will find uh go to this API reference and here you will find the thumbnail okay so this component only show the Thumbnail from your video okay and on the click of that you can open the dialogue box so just copy this thumbnail component code as it is and paste inside your de I will just format this one and then make sure to import import this thumbnail as well something like this okay now make sure to import the component which is the um oh I forgot
the component name remotion video so this need to be a remotion Video okay and then you can mention the specific height so I will provide 300 and 450 which we have previously the duration frame everything is added as it is but inside the input props now we have to pass each of the element that is nothing but this video okay also it will return the uh duration frame so if I go to the remotion video If you see it returning this duration frame okay obviously we don't need this for now so I will just console
this value okay but if you require we can add it but right now I don't think so we need this one so I will add it here something like this okay and save it now if I go back to our application boom if you see we got all the thumbnails along with this uh text as well see okay but it's look weird let's add some styling so over here we'll add a grid we'll make grid column uh two when the screen size is smaller we'll make grid column three and on last Screen we'll make grid
column 4 and save it and also we'll give Gap up let's say seven and if I go back I think Gap is not added let me so over here let's add a gap of 10 and if I refresh this screen I don't know why the Gap is not showing maybe the width is little bit higher than okay so let's decrease this to 250 I will make this 300 and 300 is very let make it 350 I think this is good now okay you can adjust from According to your requirement and if you see now the
video is showing on the screen uh you can even apply the style here okay if I appli the style like this and if I want to make border radius like 25 you will see it's uh showing this beautiful border as well okay I will make this 15 only perfect also uh for this de let's add a class name I will make cursor pointer And uh on Hover I just want to scale it little bit and for a smooth animation I will add transition all so whenever I hover on this one you will see the effect
okay now on the click of this one we want to open the dialogue so basically you need to add the uh player dialogue over here so we'll add a player dialog and to this player dialog if you remember we need to provide this two value okay so in order to get get these two value first we need To save this in one state so here we'll say open player dialogue comma say set open player dialogue is equal to use State and initially I will make this false and second constant we want the video ID comma
set video ID is equal to use state so okay so this player dialogue okay because uh I will I will tell you the issue what will happen but right now um let's add on click event to this de so here we'll say set open uh player Dialogue to true and along with that one I also want to add the video ID so set video ID which nothing but the video do ID oh video. ID okay so from there we will get the video ID and I think we are good on this one and just pass
this uh open player dialogue and over here we'll pass the video ID now let's save it and if I open any of this video let's open this video and boom see if I cancel it okay so right now it's not getting cancelled Somehow so on cancel we have to make sure inside the player dialogue we also closing the dialogue okay so on click we'll make make sure to close the dialogue okay so set open dialog to false and if I cancel it now it's cancel but if I try to open this one see it's not
working because we are passing this open dialogue true and false okay and because of that what what is happening Uh the player dialogue is we are executing this use effect whenever the players player video is changed okay but right now play video is true every time okay so we have to change this play video in some way that it will different every time so over here uh on the click of this one instead of passing the true I will pass the time stamp okay and inside the play video instead of this one I will just
pass the open dialogue the opposite of The open dialogue okay so something like this and now if I open this one see it's open it see okay so that's how it works and obviously you can even imagine yourself standing play it so that's how guys you can um add uh or show the video list on your dashboard now it's time to add an creit functionality where user can create only three video uh if you did not buy our subscription and this model convert our Application into a SAS model so that if you build this application
and convert it into a SAS you can start earning money as well by charging if user want to create more video okay so in free trial uh we are going to uh give um three credits okay so each credit will help us to generate one video or you can convert that uh uh 10 credit as one credit it's up to you how you want to uh add that logic okay but uh after three credits is over then you can uh start Charging the user on monthly basis or just to buy credits to generate uh the
AI videos so in order to build this one uh inside our database we need to add a new column called credits now you have to option and either you can go with a subscription model or you can go with the uh credits model in my one of the video uh we build this AI kid story generator application with where user can create a free story but uh user can create only three free stories and after That uh it will start charging you so this uh video of this particular application also uh I kept the link
in the description so you can go and watch on my uh Channel but now let's go ahead and add a new column and we will go with the subscript uh the credit base uh functionality so first thing go to this schema inside this config folder and inside here we are going to update or add a new column and we can just simply call credits okay now cred is a Type integer and make sure it is importing from the PG core we'll give column name as a credits and default as I say we will give a
30 credits which equivalent 30 cres is equivalent to three videos okay so something like this and save it now in order to update these changes first thing you need to stop the uh studio and then simply run npm R DB push command and if you see now changes Are applied now you can run the studio command in order to uh reflect the changes in the studio as well and if you see the default one now is 30 credits now whenever uh you update or you uh generate the video we have to make sure the cred
is get updated but before that uh we have to share this credit throughout the application so for that one I'm going to use a context okay so inside this context we'll create a new context called user detail context. Jsx file here we'll export the context so we'll simply say user detail contacts is equal to to create contact from the react okay and save it now inside the dashboard layout so let's go to the dashboard and inside that we have the layout. JS file over here we are going to add user detail context. provider to this
provider we are going to pass some default uh State value and make sure to wrap your all the dashboard component or pages Like this and just format this okay now here I'm going to create a new state I will rename this to user detail and set user detail and simply pass this value and save it okay now once you done with this one you can also uh get the user information over here so here we'll see constant get user detail and obviously we'll use the hook so Constant here we'll say user is equal to use
user and then in order to get the information we simply say constant result is is equal to await DB do select from users and here we can write a condition where equal to users dot email which matches with the user DOA do primary email address do email Address okay so that's how you can get the information so this need to be a constant here I will make this as a sync and this particular method we going to call inside the use effect now you might have question why we added this inside the layout and make
the use client it's up to you you can make a create a provider and in that one as well you can implement this all the logic okay it's up to you how you want to handle and Over here I will pass user and whenever the user information available I will call this get user detail method now once we have the user detail information we'll set the user detail data as result of zero okay and that's all now after this one let's save it and inside this page. jsx we can use this contact so here we
say constant user detail is equal to use context and here we will say user detail context okay so that we'll get the user Detail information actually we can instead of using it over here we can use it uh let me delete this and and we can directly use inside the header okay so that we can show the value of the credit and here I will make sure to import this use context as well as use detail context and just before the text dashboard so maybe over here we can show that so here I will add
h2 Tag uh let me add add a d inside that we'll add a h2 tag and here we'll say user detail dot credits okay and save it and if you see it's showing as a 30 perfect now from the Icon if I go to this flat icon here I will get the coins icon and let's download this icon it's completely free to use so I will just download this one and copy this icon go back to your vs Code and simply paste it here I will just make sure to rename this one as a start
so that we can use inside this D here we say star.png I will give with to 20 and height to 20 let's see how it looks on the screen so so that's where we are getting Crea that look good to me I will just make sure to add a class name Flex gap of two Item to be in the center perfect okay and that show the how many credits are there now so whenever even though you jump from this to next page right you will see that one now here uh we will check before uh
click on this button whether the user have the credits or not so in order to do that let me close all of this tab and inside this create new page. jsx okay uh I will make sure to import the Context is equal to use context as user detail context and when user click on this uh on create click Handler over here we'll check if user detail do credits is greater than equal to zero then only uh we will execute this otherwise I will write on of different condition and we return nothing okay and save but
here also we can uh show some kind of alert message or some kind of dialogue as well so you can Implement That as well so if you want to implement the toast message uh you can go to this chatan component where we have the toast components or you can use this sonar component which is similar to toast okay but more Advan and easy to implement so copy this npm command inside your terminal I will just paste it and once it install all you need to install this toaster to your layout file so maybe you can
Import in the root Layout that will be fine so if you want to implement over here you can Implement make sure to import it from this component uar okay and then you can just use it like this so whever you want to use you can just use it so in this case in page. jsx right uh when we are returning we'll just show the toast message saying uh you don't have enough Credits okay and then uh that's all and it will return nothing okay now if you want to teste this out uh you can do
that but before that let me implement the other logic now once user generate the video right here simply we are going to uh one make one call so here here we can write a method so we say constant update user credits okay and this method actually uh update our data so here we say Await then DB do update and here we'll need to provide the schema name which is users do s and inside here we we need to just set the credits okay so credit will be user detail dot credits minus 10 so 10 nothing
but uh to uh generate one video okay and here I will make this as async and here obviously we need to update the we clots where equal To users dot email is matches with the user do primary email address do email address okay and this particular method we are going to call once the data is saved okay so over here we're going to call this method and we'll say await and I think that's pretty much so if you want to write a console you you can just write a console as a result And inside here
we'll just update this user detail context as well okay so over here we'll write previous value along with the previous value and then the credits as credits or you can write like this user detail do credits minus 10 okay so it will update the contact as Well and then save it here I will write document right use to update user credits so the reason that we are updating the context because it automatically update the context without refreshing your screen okay so you don't need to make another call to update your data now let's test this
one so I will click on create new story let's create a custom prompt I will put this prompt uh here we say Story of McDonald's and you can select the style and the duration okay and simply click on create short video now I have the 30 credits so that I am able to uh uh generate this story so we'll wait and we'll see how the story comes out and boom if you see our video is ready and if I try to play this one you will see the wise the uh the caption and the images
also Generated if I close this one and if you see the credits is changed from 30 to 20 okay how cool and obviously once you um of the credits then you cannot generate the video and it will show the toast message saying that you need to add the credits now there is one quick fix whenever you generate uh AI content and that content we are saving inside this video data contact right now once you save in this one and uh after end of this all the methods right we are saving That into our database so
once you save that in the database inside this update user credit you can make sure to set this video data as a null means you have to remove everything from the video data context because otherwise next time it it will generate from the uh video data automatically because we have this method which will generate or save your data as well okay so we don't want to do that and that's the reason we simply um making sure the video data is set to Null let me talk about the guru.com where you will find all of my
exclusive courses along with the source code for each of the project not only that but you can track each course chapter by chapter here you'll get the source code the application Depot or you can even uh watch this complete video for free on YouTube how cool it is right also you can find your own personal dashboard and you can track your course depends on your how much progress you Did it okay and in order to join this particular tube guruji Pro membership it will just at $899 per month okay and you will get an access
to the all the courses and the source code for free now whatever application we build you can deploy this application to the worel for a free and the demo of this particular application the link is in the description so you can just go ahead and test the demo as well but when uh if You open any image we have this button called export and once you want to export this video that's uh where uh we uh we we allow user to download this particular video and for that one uh you need to use this remotion
uh rendering okay using this server side API now there are a couple of way that you can use it the rendering you can do it with the help of uh AWS Lambda which is the preferred one that the remotion suggested or you can also Use the nodejs API or GitHub actions as well okay so there are some of the way that you can use this and programmatically you can uh export this video and so that user can download it okay but this is little bit a longer it's going to be longer video so that I'm
going to cover this particular remotion export part in my upcoming videos and if you want to see how to deploy this application and how to render this server side uh to export the Video let me know in the comment section like this video guys so that I can build a next video if I get a 2,000 like to this video then definitely I will make uh the new video with the advanced feature and the rendering capacity as or uh rendering feature as well so guys that's all for this particular uh video if you did not
subscribe to my Channel please do subscribe like the video share this video with your friends and family and don't forget to press notification Bell icon