Hello guys.
So we are going to continue our deployment series already.
In our previous video, I have already shown you how you can deploy your generative AI application with
Streamlit web app with the help of Streamlit Cloud.
And probably the steps were quite easy.
We just need to put all the code in our GitHub repository.
And from this we just need to connect it in our Streamlit lab.
Now, uh, Streamlit lab or Streamlit Cloud, you can basically say in that way, now I am going to
deploy this entire code solution in hugging face spaces.
Okay.
Now spaces actually provides you, uh, you will be able to probably deploy your generative AI applications
over here or any machine learning applications over here.
So step by step, we will probably go ahead and I'll try to show you completely in a very much easy
way here.
If you just go in spaces, you'll be able to see many, many, many use cases which are specifically
deployed.
And you can go ahead and check it out.
And you can also check out the code.
Right.
So, uh, let's go ahead and do this.
Uh, there are many steps that it will be involved while probably deploying this entire solution in
the hugging face spaces.
Over here we are also going to use something called as GitHub action.
Okay.
So here if I go ahead and search for hugging face space okay GitHub action okay.
So here you'll be able to see managing spaces with GitHub action.
So if you probably go ahead and see this repository this is the code that we are specifically going
to use.
So we will be creating an YAML file.
And we will say hey you need to push in this particular hugging face space and probably do the deployment
okay.
So here I will be going ahead and showing you step by step how this things can be implemented.
So first of all, I will go ahead and create a new file inside this repository.
Now first of all here I will be using one folder called as dot GitHub.
So usually whenever you create a CI CD pipeline you really need to create a YAML file.
And the entire configuration inside that YAML file will actually tell you that how you're going to push
the code in the deployment servers.
Right.
So for that I will be creating this dot GitHub slash workflow okay.
Workflows.
So this is the folder that I'm actually going to create.
And inside this I'm going to create this main dot YAML file okay.
Now with respect to this main dot YAML file, what I'm actually going to do I will go ahead and copy
this entire thing.
So here you will be able to see this is the important code that I will be copying.
Right.
So this code is responsible.
And as soon as we do the commit in the GitHub repository, this will be pushing our entire code repository
into this particular hugging face token.
Okay.
So hugging face uh space okay.
Here, uh, please observe each and every thing carefully.
What is the necessary information here.
You will be able to see it out okay.
Okay, so let me just do one thing.
Let me just hide this if possible.
So first of all, over here, you'll be able to see that, uh, whenever we work with GitHub action,
most of the parameters will be in the form of key value pairs.
So this is nothing but syncing to Huggingface hub.
We are pushing the branch.
Main job is basically to run this entire thing in the ubuntu latest version.
We will check out all the code and finally we'll push this to the hub, which is my Huggingface hub,
and we will be using some secret token that is our F underscore token.
I will show you how to probably create this particular token and where we need to push.
We need to push on this specific space ID okay.
Now how to get this space ID.
I will be talking about it.
Okay.
So let's go back to our huggingface space and let us go ahead and create our new space here.
I'm just going to write, um search underscore engine underscore LM okay.
So this will basically be my, uh, application name over here, which I'm actually creating in my space.
After that, I will go ahead and select a license.
Let's say I go ahead and select Apache 2.0.
I know this is a Streamlit app, but other than this it is a for uh, for Grady.
Also it is supported for static templates.
Also it is supported if you really want to work with Dockers.
It is also supporting that.
Right.
And here you have a space hardware free by default.
They'll give you CPU basics with, uh, two Vcpu and 16 GB free Ram.
Okay.
You can actually go ahead and use this.
This will be more than sufficient to go ahead with right then.
Uh, whether you want to make this space public or private, let's say that I want to go ahead and probably
create this particular space in public.
So I will go ahead and click on Create Space.
Okay.
As soon as I probably click on Create Space here, you can see that I can clone this entire thing and
I can start working.
Okay.
If you want to go ahead and see how many files are basically present over here inside, none of the
files are specifically present.
So what I'm actually going to do from my GitHub, whatever files is there, I need to push to this particular
Huggingface hub right where this all files will be present.
Right now, the most important thing is that how do I generate this h.f underscore token or this particular
token.
Right.
So for that what I will do, I will go back to my Huggingface hub or Huggingface.
I will click on settings button.
Okay.
Now inside this settings button I will go and click on something called as Access Token.
Now over here you'll be seeing that I've created so many access token to start with, I will just go
ahead and write new and let's say I will go ahead and, uh, create my token over here.
But please make sure to select the type as right.
Okay.
So let's see whether it is right or not.
No, it is fine grained.
Uh, let me just go ahead and create my access token once again.
So I'll be going over here.
I will click on new token.
I will write token one okay.
This will be the name of the token and type I will go ahead and select as right.
The reason why I'm selecting as right.
Because I need to push something into the hugging face hub in inside this particular space.
Right.
So all the files I need to push it over here.
So for this I need to write I need to get an right access token.
So I will go ahead and generate a token.
And I'll make sure to copy this specific token okay.
And this particular token I will store it in my notepad so that I will be using this where I will be
using it and talk about it okay.
So let me just go ahead and close this after creating the token.
Now I'll go back over here.
This is the first step.
I've created my token right.
Now the next thing that you'll be seeing over here I have something called as git push git uh https
hugging face underscore username.
Now what is my hugging face underscore username?
It is nothing but Krishna zero six so I will just go ahead and write it over here.
Krish Krishna zero six okay, so this is my first hugging face token information that I have.
Sorry.
The username information that I have that is Krishna zero six.
Then I will be using the same hugging face token over here then hugging face dot o.
Then here you'll be able to see.
I have to also mention the hugging face user name here too.
So let me just go ahead and write Krishna zero six along with this.
My space name.
My space name is very simple.
I need to use this search underscore engine underscore LM okay.
So now here I will just go ahead and write search underscore engine underscore LM okay.
And then this basically goes to the end.
Please make sure to make the spelling right.
And finally this is going to my main branch.
So that is the reason we are pushing this entire information into the main branch.
And this is my main branch right inside my huggingface space.
So yes, this was all the information that I need to put over here.
Now the next thing is that I will go to my settings okay.
I will click on settings over here okay.
Uh, inside the settings uh there will be something called as secret and variable.
Okay.
Now inside the secret and variable I will click on actions.
And here I need to go ahead and create my secret key repository secret key.
The new repository secret key that I am actually going to go ahead and create.
Right.
It should be the same name right h f underscore token.
So as soon as we call this code secrets dot h f underscore token, it is going to take this particular
token from here.
Okay.
And this particular info that I have will be this key.
Right.
I will be assigning it over here.
And then we will go ahead and click on Add Secret.
Once we add the secret here you can see it is my F underscore token.
Perfect.
Now this work is done.
This is also updated.
This my entire uh this run where we need to push the code is also updated.
And as soon as I do this, I'll just go ahead and commit the changes.
Okay.
So once I commit the changes, now an amazing thing is going to happen suddenly.
Just click on this actions.
Now see this?
This entire CI CD pipeline is running.
If I go inside this, these are the steps that will happen on push.
Right now it is starting the job.
And here you can see that I am getting some kind of error okay.
let's see what is the error.
So here you can see two hugging face spaces.
Crush engine rejected.
Main fetch.
Failed to push some reference things.
Uh, this is usually caused by another repository pushing to the same reference.
Okay.
Now uh hint have locally this is used by another repository pushing to this.
Right.
So here uh what is it is basically saying is that I before this, I tried to test one of the repositories.
And based on that, I was just trying to push it.
Okay.
So I will go back to that particular repository and I'm pushing it to the same thing.
So that is the reason it won't make any sense.
Let me just do go back to my repository over here okay.
And let me open that particular repository okay.
Search engine.
All right.
So this is my repository here.
You can go ahead and see that I have my GitHub workflows.
And now again what I will be doing I'll be having this entire thing right over here.
Now let me do one thing quickly over here.
That what I will do is that I will go back over here in my code.
Okay?
And don't worry, because of this error, you may be getting confused because I just tried it before
earlier, right?
I will just go ahead and update it just to show you how things happen.
Right?
So here I will just update one of the file okay.
One of the file.
Yeah.
And then I will just go ahead and commit it okay.
So here let me just go ahead.
So here you can see I will just edit this file okay.
I will just go ahead and commit it okay.
I will just commit this particular changes as soon as I commit this changes if I go back to my code
one amazing thing is basically going to happen.
Go to the actions and here you will be able to see I have updated the app dot Pi.
It is telling me to sync to hub.
Now this entire code is basically with push.
Right now.
This push has actually happened in my huggingface space, right?
So I will go ahead and see this particular link.
Now you'll be able to see the magic right?
So once I hit this link right it is giving me an error okay.
Okay, first of all, this readme file.
It's okay.
We'll try to fix this.
But if I go and see in my file section, you'll be able to see that I have my API, I have my requirement
dot txt and along with this I also have my GitHub workflow right.
The entire GitHub workflow perfect.
But still we are getting an error how to fix that particular error, right?
So what I will do, I will just open my readme file okay.
And we need to edit this readme file.
Okay.
So what I will do, I will just remove this because it requires some special characters like I need
to add what kind of license is there?
I will go ahead and say, hey, this is my search engine.
Okay?
Then I will ask the SDK that is Streamlit.
I will add some kind of emoji.
Okay, something like this and I'll add some color form.
Let's go and add this and short description.
So this is nothing but search engine with LM okay.
Now once I update this quickly, uh, let's commit this changes to the main file.
Now here, if I go back to my apps in this huggingface space, now this see this entire thing, the
entire build will start running.
First of all, it will go ahead with installing all the requirements.txt.
Right.
So if I just go ahead and see this right see over here all the requirement dot txt is basically getting
hit and the container is going to get built up right now.
And once this is built my entire application will show up over here.
Right.
So we'll just wait for some time to just show up the things over here that we are looking for.
And uh, till then, uh, if I just go back to my files over here, okay, in In my files, please make
sure to download this readme file, because I need to use this same readme file, uh, inside my GitHub.
Right.
So I will make sure to update this entire thing.
So I will just copy this and I will go back to my app Dot Pi.
And let's go ahead and update it over here okay.
So in order to update it I will just remove this and I'll paste it over here.
I'll commit the changes.
Okay.
Now as soon as the commit will happen automatically this particular code is there.
But again the action will go ahead.
You know.
And this is all because the CI CD pipeline is running.
Whenever I do any kind of commit and all automatically the push will basically happening in the hub
right in my in my hugging face space.
Okay.
Now finally, you can see my entire application start up will start running.
It is taking some amount of time because there are lot of inbuilt uh, they all the all the requirement
dot txt libraries will get installed and uh we will just wait for some time.
It is still building the entire container and the entire application that we really want to run will
be shown over here.
And this is how you can actually do the entire deployment just by using the CI CD pipeline.
And this is what is an example of GitHub actions right here in this main dot YAML file.
What I have actually done is that I've told, hey uh, on push you have to push it to the main branch
where we need to push, we need to push it in our hugging face space.
And that is the information that I've actually given over here.
Right.
So this was one of the most easiest way to probably do the deployment.
And you can probably do any kind of generative AI applications that you really want to do.
Right.
So let's do one thing.
Let's wait for some time and let's, uh, let the build specifically happen.
And once it happens, I will probably show you the next steps, okay.
And we will also test out the test out the entire application over here.
So yeah, let's wait for some time.
So finally, you can see guys, uh, this entire application has started.
So we will hide this.
And here is our entire application working on this particular hugging face spaces.
And you can probably pass this particular URL, share this URL.
And you can show everyone that what you have actually developed right now, we will quickly go ahead
and I will be using my environment variable and I will update my grok API key.
You can probably get the grok API key over here, paste it, press enter, and after this I will just
go ahead and search for what is machine learning.
And I think I should be able to get the answer okay.
So thinking search thinking invalid tool Wikipedia no need.
Then from the search itself we are able to get all the information it did not think to probably go to
Wikipedia and here is my information right now.
Still, if I go ahead and ask what is generative AI, I should be able to get my response again.
It is searching from this DuckDuckGo search, um, search for generative artificial intelligence and
all.
So here you can see requested tool Wikipedia search arXiv and Wikipedia.
Right?
Wikipedia if I keep on second.
Okay.
And uh, it is saying that it is not a valid tool, it is not required.
And here is the information with respect to our generative AI.
So I hope, uh, you are able to understand this entire deployment mechanism.
So I hope you are able to understand this entire deployment mechanism.
You can probably go ahead and deploy anything that you want.
And I think this hugging face space will be more than sufficient.
But at the end of the day, I have actually shown you how you can create this entire thing with the
help of this GitHub workflows, uh, where we have also used GitHub actions.
So yes, this was it from my side.
I will see you all in the next video.
Thank you.
Take care.
Bye bye.