So guys, now we are going to continue the discussion with respect to our end to end project.
Already we have trained our simple RNN.
We have saved the H5 file.
We are also able to do the prediction.
Now let's go ahead and create our Streamlit app.
So here I'm going to basically go ahead and write main.py.
And inside this main.py I am going to write my code.
Now with respect to prediction dot ipynb it's almost similar like this.
Like uh, there will be a D code review, there will be a pre-processed text.
So we need to probably go ahead and combine each and everything.
Okay.
Uh, I need to also load my model itself.
Right.
So let's go ahead and do it.
So first of all I will go ahead and import my model libraries.
So let me do one thing.
Let me quickly import all the libraries that I have.
So here we are going to import all these libraries like IMDb sequence load model.
Then uh I'm going to load the word index specifically for the IMDb because I need to convert that based
on, uh, our decode reviews.
Uh, basically all the reviews needs to be converted into vectors.
So that is the reason we require index, uh, and that we will be specifically getting from this particular
word index right along with this two helper functions, uh, that I have actually shown you.
We can also create this in another file and call this particular file.
But let me just go ahead and put it over here so that it will be easy for you to refer.
So here I have my decoded reviews.
Here I have my pre-processed text.
Now, finally, uh, this is important.
We will go ahead and create our.
Step three will be creating our prediction function right now.
And inside this prediction function I have already shown you what we basically do.
So if you go over here down this is the prediction function write predict sentiment.
So I'm just going to copy this same thing okay.
Model dot predict positive.
If this is then we are going to return this.
So the same thing will also be pasted over here.
Right.
So this basically becomes my predict sentiment right now.
Uh let's do quickly one uh very important thing uh, in this is that when we are, you know, when we
are probably using our Streamlit, you know.
So Streamlit app needs to be providing some input boxes, some buttons and.
All right.
So we can go ahead and do that.
All the things over here.
Right.
So uh quickly uh uh I'll keep this predict sentiment and let's see whether we will be requiring it or
not.
So I will go ahead and design my Streamlit app.
Okay.
So first of all I'll go ahead and write SD dot title.
so quickly.
First of all, I'll also import Streamlit as st.
Okay, then I will just go ahead and give my title and some information over here.
So I'll give a text which says IMDb Movie Review Sentiment Analysis.
Enter a movie review to classify it as positive or negative.
Right.
So this is there.
Then we will go ahead and create a user input by again using Streamlit.
So for that we use s t dot text area.
And this will be my movie review.
Then what I'm actually going to do is that I'm going to probably go ahead and create one button okay.
And if I click this button this should classification should basically happen.
Now when I'm giving this user input, this user input.
First of all, once we click this particular button it should be passed to our preprocess underscore
text function.
And here I will just give my user input.
Through this we will be getting our preprocess underscore input value right.
So this is how we will be getting this preprocess underscore input value.
Then here the next step will be that I will go ahead and make my prediction.
Now this prediction I'm going to basically use prediction is equal to model dot predict.
And here I'm going to use my process underscore input okay.
So this processed underscore input I'll just keep a spelling which looks like this okay.
Then uh once we get this specific input then I'm just going to go ahead and calculate my sentiments
and sentiments will be nothing.
But here we are going to use this positive or negative right.
If this is greater than 0.5 it's negative I'll say.
Then we will display the result in my in my Streamlit itself.
So we will go ahead and write SD dot right SD dot right, else SD dot right right.
So here uh let me do one thing.
Okay.
So here, this else should be here.
And here I will go ahead and.
Right.
So here I'll say if I go ahead and click the classify button.
So I should basically do the prediction of this processed input.
I should be getting the sentiment.
I will probably display the sentiment in prediction.
Else if I don't click it, it'll just give me a message saying that.
Please enter a movie review.
Okay, so, uh, this is done over here and, uh, you know, uh, uh, you can probably also display
how the sample review should look like, write sample reviews.
Also, we need to properly display.
So that is the reason we are using this code review and pre-process text over here.
So let me do one thing.
Let me just go ahead and run this.
And I think we have almost done each and everything right.
If you want you can also display your sample review below.
You can just write SD dot write.
Hey, this should be a sample review.
That is one way, but here.
In short, let us revise what all things we did.
We imported all the libraries.
So here is my word index that I am actually able to get.
I'm reloading my H5 file, so let me just rename this file like this.
Then here is my helpful uh, helper function.
Helper function of decode review.
Here is my with respect to pre-process preprocess input.
So this function is basically just giving you the vectors with padded sequence, right?
Not vector indexes with padded sequence.
Then this is your prediction function.
I have not even used this prediction function.
I can also use it over here, but I have written it.
So let me just remove this over here.
Okay, I don't require it.
Then we are importing Streamlit.
Then we have created our text area.
We have created a button.
If we click the button, it should probably predict it and give you the sentiments.
So finally guys, now we are going to run this and see that whether everything is working fine or not.
So I will just go ahead and open my terminal.
Please make sure to go to the simple RNN folder.
Then only you will be able to execute it because as you know, I have also created simple RNN and similarly
when LSTM will be working, we'll create another folder and we will be working in the similar way.
Okay.
So now here what I'm actually going to do is that I'm just going to go ahead and write Streamlit run
main.py file.
Okay.
So here is my URL.
Uh that has been loaded okay.
Let's do one thing.
Let's I have also already created in my prediction dot ipynb some text and all we have used, right?
I'll copy that same text.
The movies.
This movie was fantastic and so thrilling.
Okay, and then we will try to use this.
Let's see.
So quickly.
Uh, here I'm going to copy and paste it.
This movie was fantastic.
The acting was great and the plot was thrilling.
So once I classify it, you'll be able to see, wow, this looks good, right?
My sentiment is positive prediction is 0.811.
Let's go ahead and try something.
The movie was scary.
I did not like it.
But the critics is good, right?
I'll just go ahead and classify it.
So sentiment, it shows positive because it does not care about my feeling what exactly it is.
But the prediction score that I am able to get is 0.85, which is good enough, right?
Now the next step is that you can go to the Streamlit cloud, okay and do the deployment.
I've already shown you how to probably do the deployment.
So this will be one assignment for you.
Go ahead and upload all the files in your GitHub.
And from here you can just go ahead and deploy in the Streamlit cloud.
Again I'm going to keep this as an assignment guys.
Uh but I'll not be uploading that specific video, so I hope you like this entire session wherein we
discussed about so many things we discussed about, uh, how to probably create or work with RNN again,
completely end to end projects, from embeddings to training, a simple RNN to creating this H5 file.
You know, everything we basically did, right?
So yes, uh, this was it for my side.
I hope you liked this particular video.
I'll see you in the next video.
Thank you.
Take care.
Bye bye.