what is going on guys welcome back in this video today we're going to learn how to train an intelligent AI chatbot from scratch so no large language models training it from scratch and tensor flow and how we can then integrate it into a web application using flask so let us get right into [Music] it all right now before we get right into the coding I would like to show you what we're going to end up with here today this is the final result this is your motivational preview up front we have a simple heading here
in a flask web application saying intelligent web chat bot and then I have this button down here which I can click and it opens up a chat interface and here I can type something like hey and I will get an answer hi there how can I help then I can ask certain things now keep in mind this is not a general chat bot so this is not a large language model that you can just chat about uh chat with about anything uh this is a chatbot that is trained on certain intents so I have a
file full of categories for example here now I have the category or intent programming I have one about flask and how you ask the question is not that important so it's not hardcoded I can ask the same questions in multiple different ways but the type of responses or the type of um questions I can ask is fixed so for example I can say what is programming uh and I can also say uh tell me something about coding and it will lead to the same intent and I can also ask stuff like what is flask um
tell me stuff about flask and in this case now it's only one response but we can also get different responses you can see that with hello I can get hi there how can I help I can also say good to see you or it can also say good to see you again uh so it basically chooses a random response and I also have something like buy and this can be extended the way you want uh to Extended so you can just add 100 more intents the important thing is you have enough sample data so that
your neural network that is trained behind the scenes in tensorflow understands what you're trying to accomplish what kind of intent you're trying to to get here all right so this is going to be a quite comprehensive project today we're going to split this up into three different sections the first one will be about training the model based on an intense file so this is a file containing all the different uh request categories that we want to be able to respond to with sample messages for training with static responses to GI and so on the second
part will be the back end of the flask application so the code that interacts with our model and performs inference and the third part will be the front end so HTML uh JavaScript CSS that will interact or the JavaScript will interact with our backend uh to perform the inference and I'm going to be honest I'm going to copy paste most of the HTML and CSS stuff because I don't want to focus too much here on styling and animations and so on I will do the JavaScript uh or I will cover the JavaScript code in more
detail because that's the functionality of interacting with the backend but we're not going to spend too much time on styling here I'm going to copy paste it and I will uh hopefully upload the code to GitHub so that you can take a look at it and copy paste the HTML stuff as well so the first thing you want to do is you want to set up an intense. Json file and this is a file that contains uh this structure here now this is not the best formatting I know but I wanted to keep everything here
or I wanted to fit everything um onto a single screen and basically what you have here is you have intents which is a list and then you have these dictionary type object here where you have a tack patterns and responses the tack is basically just the name of the intent the patterns are um queries that are used for training so these are not static things you don't have to to enter exactly this message uh later on to get a response these are just training messages and similar messages will also be fine so for example I
don't have the message here what is up I only have what's up or uh what's going is also not part of off this um intent here but if I type what's going I'm probably going to get this category anyways same for programming if I type something like um give me an introduction into software development um I'm probably also going to get this intent here um so these are just patterns that we use for training but these here are static responses they're not responses that will be used to train how to give responses these are actually
what you're going to get um from the model so it's going to randomly pick one of them if you provide multiple if you provide just one you're going to get one so this is very flexible here you can extend this to be whatever you like just make sure you have enough diverse examples um so you can add 20 more intents if you want to you can add anything that is particular to your use case for example I could turn this into a neural 9 assistant I could say I want to have a tag um I
going to have a tag called neural 9 and in this tag I have the patterns what is neural 9 uh is this a YouTube YouTube channel or what's YouTube channel of neural 9 what can I learn there and so on and then it would give the responses uh or one response would probably be more reasonable here and you can extend this as I said to be whatever you like and this is the basis here so I have in this case a greeting intent a goodbye intent a programming intent how intent which is basically asking the
chat bot how are you uh and then a flask intent which gives me information about what flask is um once you have that we're going to install a couple of packages now I'm not sure if this is going to be a complete list or if we have to install something later on as well but we're going to use numpy we're going to use tensorflow now to make sure you have the same packages as me I have tensorflow 2.14 this can be relevant if you have some compatibility issues the reason might be you're not on the
same version of tensorflow so I use tensorflow 2.14 just because my code somehow now seems to break at 2.16 for whatever reason um we're going to also use nltk the natural language toolkit we're going to use flask obviously now let me double check if in the other files of my prepared code here I use something else that has to be installed I don't think so so I think that's actually it these are the packages we need to install and once you have them installed we can start by creating our first uh section or by working
on our first section I'm going to call this model training we're going to put the intense Json file here and we're going to create a new file here which we're going to call model training py all right so in this file we're going to take the intents we're going to lemmatize them we're going to tokenize them and then we're going to create a so-called bag of words where the individual words are just positions in a matrix and we have a one or zero depending on whether they occur in um a sentence in a request or
not so this is a very simplistic approach but we're going to do it like this uh now I'm going to start by importing OS and disabling tensorflow warnings just so I don't get a full screen of warnings here so I'm going to say os. Environ and then I'm going to set the environment variable TF CPP Min lock level I'm going to set this to three uh you don't have to do that I just do it because I don't want to have all the warning messages in the command line which I usually get and then we're
going to import a couple of core python packages random pickle for serialization Json obviously if we're working with the Json file and then we're going to also import numpy SNP we're going to import nltk um we're going to import from nltk do stem the word net litier um chances are we need to install a package using nltk do download but let's see if that's the case and then we're going to download uh sorry we're going to import from tensorflow the different um components of the neural network that we're going to build now you can choose
your architecture yourself if you want to play around with that I'm going to use a very simple one I'm going to say from tensorflow docos do models we're going to use a simple sequential model from tensorflow docas do uh lay lers we're going to use the following layers the dense layer which is a normal feed forward layer the activation layer and also a Dropout layer for regularization and then finally we're going to say from tensorflow doc. optimizers we're going to use D stochastic radiant descent so SGD all right so these are the Imports and now
we can start by lemmatizing tokenizing and then uh turning all of this into a bag of words so we're going to start by saying lemmatizer by the way this is all very similar to my to one of the most popular videos on my channel called intelligent AI chatbot in Python it's going to be slightly different but it's going to be very similar to the code that we've written there uh just because this part doesn't really change that much and the new thing will be integrating it into a flask web application so the lemmatizer is equal
to the word net lemmatizer let me just see if I have to download something for this no okay chances are you have to download something you will maybe get a message with something like uh run nltk do download and so on but if not it's fine so just keep uh coding lemmatizer is wordnet lemmatizer the intents are going to be equal to Json load and we're going to open the intent. Json file here and uh now we have basically a python dictionary uh containing a list and then we have in this list all the intents
so what we're going to do is we're going to say words is going to be an empty list classes is going to be an empty list documents is going to be an empty list and ignore letters is going to be a list of characters that we want to ignore in the request we're going to ignore question marks we're going to ignore exclamation marks we're going to ignore uh points or dots and commas um and now what we want to do is we want to go through all the intents through all the patterns so through all
the sample requested we have here we want to get a list of words and we want to add them to the total words list the total words list is basically what kind of words are existent in our universe here in our intents file so we're going to say for intent in intense intense which is our list for pattern in intent patterns so we go through all the intents all the patterns of the intent and we say the word list is equal to nltk do tokenize word tokenize sorry um and we're going to take the pattern
and extract or tokenize the individual words here and then we're going to extend our words list by that by the word list we're going to to basically append all these individual words to the word list and then we're going to say document append and we're going to append the word list and the TAC this is basically our XY training data combination so we have um documents append we add the word list and we associate it with a specific tag so the word list that we get by tokenizing for example what is programming this will be
mapped to programming and we do that for every single pattern that we have so for all these sample requests um all right and then we're going to say if intent tag is already part or actually if it's not already part of classes we're going to also add the intent tag to the classes list all right so what we're now going to do is we're going to lemmatize the word so um we're going to say here so this is basically word stemming we're going to reduce them down to the uh to the essence of the word
uh we're going to say word is equal to litier do lemiti word for word in words if word is not in ignore letters so we get all the tokens if they're not part of this ignore letters um or ignore symbols is probably a it's a better term ignore symbols um if they're not part of that we're going to lemmatize them and they're part of the words list and then we're going to say that words is equal to a sorted set of words the reason we do that is because set um eliminates all the duplicates and
sort it turns it back into a list and also sorts it at the same time and we're going to do the same for classes the classes are going to be equal to sorted uh actually we don't need sets here I think we're going to do it just uh in case I miss something here but I don't think we need sets here because we only append if it's not part of classes already but yeah let's let's leave it like that we have a list of sorted classes or sorted list of classes Here and Now what we're
going to do this is important because we need that also in our flask web application we're going to dump all of this we're going to write all of this to files using pickle so we're going to say pickle dump and we're going to dump uh the words into the following path model and then words. pickle I'm going to open this in writing bytes mode and we need to actually create model here um and we're going to do the same thing with a classes this is important because these words here and these classes are also important
then for inference so classes PK and now we're going to define a list training which is an empty list and we're going to say uh that we want to also have output which is going to be empty in the beginning so it's going to be a zero multiplied um depending on how many classes we have so we have basically zero for all the classes and then we have an empty training data and now we're going to go through all these combinations that we uh created here all these mappings of word list to int to intent
tag and we're going to train now we're going to turn this into a bag of words for training so we're going to say for documents in documents we're going to define a bag of words to be an empty list and we're going to say word patterns is equal or actually what did we call this up here word list word patterns I mean yeah let's let's call this word patterns doesn't matter uh is document zero so [Music] um yeah so basically that's going to be our it's going to be this part here the word list and
then we're going to say that we want to also lemmatize this so word patterns is going to be equal to litier litiz word for word in word list um word pattern sorry and probably we should remove also the ignore symbols if word not in ignore symbols all right so we have our word patterns here and now we're going to say for word in word and the idea now here is why do we iterate over words and not word patterns because words is the total the sorted list of total Words which means that we have all
the words that we know and we set them to either um existing or not existing in this particular word pattern here or in in this particular word list here so we go through all the word words and we fill up the back with zeros or ones indicating if that particular word is part of this particular message here so we say if uh or let me do that as a as a oneliner here back. append we're going to append to the back a one if the word is in word patterns else we're going to append a
zero so instead of having just just the words we now have a list of zeros and ones indicating every position is mapped to a specific word in the words list here indicating if that word occurs in the request or not so this is the basic idea of bag of words uh and then we're going to say output row is going to be the list of output empty so the list of the zeros here and then we're going to say output row is going to be classes index document one uh we're going to set this to
to uh one so basically we have our list of zeros and we take it we make a copy of it basically this is why we do that and um on the position of the respective class that we have here so remember we have the words and we have the intent so we basically look up what position does this in intent have in the classes list go to that position set it to one all the others remain zero so we have a binary encoding for the words and we have a binary encoding for the classes everything
now is just zeros and ones and then we're going to append this processed or pre-processed thing to the training data so we're going to append here the back and also the output row again repeating the back is zeros and ones indicating which words occur in this request and the output row is all zeros and just one one for the correct class and this is something that we can easily work with in our neural network structure so we're going to now perform a random shuffle of uh the training data and we're going to say that the
training data also is a numpy array so we're going to turn it into a numpy array and now let me just add a couple of lines here so that I can code up here uh we're going to define the train X data to be equal to the list of training uh all the data but in um but just taking index zero so just taking the backs and then the Y data is going to be just taking the output rows so we pass a one here and now we can Define our neural network we can say
that our model is a sequential model we can add a simple uh dense layer to it so we add a dense layer with 128 neurons input shape of that layer is going to be equal to the length of the training data uh so so basically one instance uh the length of one instance and we're going to have a comma here and we're going to say that there is an activation which is relu so rectified linear unit um just a basic uh but just the identity fun identity function if it's um above zero and otherwise it's
just zero and then we're going to add a Dropout layer so we're going to say Dropout 0.5 for regularization while training here then we're going to add a dense layer with 64 neurons also activation Ru and then we're going to add another Dropout layer now Dropout is only important for training not for inference uh and then finally we're going to add a um actually we don't need an activation layer can just use a dense layer with an activation function so let's do it like this we're going to add a dense layer that has the length
of train y so basically the length of an output row train y z um and the activation function here is important it's going to be soft Max because soft Max basically um make sure that the output adds up to one so basically a soft Max output is the probability for each intent so we're going to get different numbers all of these numbers are going to add up to one 100% basically and the highest one will be the highest probability so if it's something like 0.6 7 it's going to be a 67% chance that this is
the correct intent so we're going to always go with the highest probability here um all right now for the optimizer we're going to say SGD is equal to SGD we're going to use a learning rate of 0.01 a weight decay of uh 1 E minus 6 and momentum of 0.9 going to use nesterov um here as a as an optimization so we're going to say this is true um and yeah this is now the optimizer so we're going to compile the model we're going to say compile the L function here is going to be a
categorical cross entropy and the optimizer is d stas radient descent and the metrics we're interested in are accuracy all right so that is that and now we're going to fit the model by passing array actually does this make sense why not just um not sure if this would produce any problems this is not how I did it in my prepared code but I can just leave it like that so I don't need to type cast in I think this should work let's see train X train y we're going to train 200 EPO because we don't
have a lot of data so this is going to be quite uh fast batch size is going to be five and ver Bose is going to be equal to one so that we see some output and then we're going to say model save we're going to Output the model to model chatbot model. caros that is our code so let's see if I messed up something or if we can just run this and train our model uh we do have a problem what is that okay probably it's let me just do this the way I did
it in my prepared code so let's go and say this is a list this is a list and then let's go ahead and say this is an NP array NP array and let's go all right there you go 200 Epoch done you can also train more if you want to you can see we have a pretty good accuracy here but we also don't have a lot of data obviously so yeah if you have more intense more patterns yeah probably it's going to be a little bit more difficult um especially if you have overlapping stuff right
so if you have something like what is programming and then what is web development if those are two different intents then you might have some more problems there but that is now our training code we now have our chatbot model we have classes and we have words this is the section one done now what we're going to do next is we're going to build a flask application around this so we're going to uh I'm going to copy this I'm going to copy the model directory I'm going to create a new directory up here I'm going
to call it flask application and I'm going to paste the model directory in here so we have our resources here um and what we're going to also do is we're going to create a templates directory this is more for the for the front end but we're going to have one actually templates and I'm just going to put in a generic index HTML file in here nothing too special and then we're going to Define our app.py so we're going to create a python file app.py but before we even go into the flask application itself I'm going
to create another file called utils.py where we're going to have all the code necessary for interacting with the model and these are just going to be functions that we then call in the application the application itself will just be a basic API we're going to send a request with a message and we're going to get a response that's it but the whole logic of interacting with the model getting a result is going to be done here in utils so what I'm going to do is I'm going to go to the model training file and I'm
I'm going to copy the Imports that we had here um actually don't think we need all of them but I'm going to copy this part for sure this part is fine this part is fine um this part as well now we don't need all of that but we do need from tensorflow Kos models import load model because we're going to load the model from the model directory here and now we're going to Define uh four different functions first of all we want to have a function clean up sentence so we pass a sentence to this
function and what we're going to do here is we're going to say the litier is equal to a word net litier sentence word are going to be equal to nltk word tokenized basically doing the same thing that we did for the pre-processing when training word tokenize the sentence and then we're going to say sentence words is going to be equal to uh lemmatizer do lemmatize word for uh my space bar is somehow stuck let me just hit it a couple of times uh for word in sentence words and actually we should probably also go and
add the ignore symbols here I don't even know if that does anything to be honest but let's just do it so let's say we have have our ignore symbols if word not in ignore symbols and um then what we're going to do is we're going to just return this list here of sentence words so that's the first function the second function is going to be our back of words function this is going to take um a sentence again and this is going to turn this into a bag of words so again into this binary representation
for this of course to have the same binary representation since we're doing this with the positional encoding we need to have the same list of words that we used before so we're going to say words equal to pickle load and we're going to open up the model /w. pickle file we're going to load that and then we're going to actually we need to do that in Reading bytes mode uh we're going to have this um words list again and we're going to then say sentence words is going to be equal to clean up sentence so
we use this function from above applied onto the sentence which will return a list of uh lemmatized words or tokens and then we're going to do the same thing back is going to be zeros times the length of words so we have zero for every word and then we're going to say forward in um actually let's go for w in sentence words uh we're going to say for I word in enumerate words if the word is equal to W then we're going to say back at this position is equal to one it's the same thing
uh basically just going through it and uh by default we have zeros otherwise we're going to set it to one and uh yeah we have a one for all the words that occur and in the end we want to return NP array off the back all right so this is nothing new this is just pre-processing again how do we do an actual prediction we do that by defining a function predict class this function is going to ask the model for a prediction given a sentence so what we do here is we say classes is going
to be equal to pickle load from model SL uh classes pickle in Reading bytes mode oh actually we need to open open that there you go so we have the classes we have our model which is equal to load model which is a tensorflow function um and we're going to load model. chatbot model. caras and now what we do is we say back of words so B is equal to back of words um based on the sentence so we pass the sentence to bag of words bag of wordss passes it to cleanup sentence and then
process it processes it to be a bag of words and then we're going to get a response from the model we're going to say model. predict make a prediction given this bag of words so we're going to pass a numpy array we got to pass a list here because we could have multiple instances of the bag of words and we're going to get a prediction we're going to get index zero here uh and we're going to define a so-called error threshold which is going to be 0.25 in my case and we're going to say results
is going to be equal to I result for I are in enumerate result so for all the different um responses we could have if R is greater than the error threshold and then we're going to say results. sort we're going to sort the results based on the prob ability based on the soft Max output so we have uh Lambda expression X we're going to focus on index one so position two which is the probability we're going to sort in reverse order so that the uh highest probability is the first element and then we're going to
say return list is an empty list for are in results so for these different pairs of intent and probability we're going to say return list. append the following intent is going to be whatever the position is so r0 um we're going to get that index from the classes list so we have an actual name for it and then the probability is equal to the string version of R1 so this is going going to be just uh yeah the number representing the soft Max probability and then we're going to return this return list uh and this
can be used now to also make a probabilistic guess so you can also not go with the number one prediction you can also go with the second most likely one you can Implement a more complex logic what we're going to do for the purposes of this chatbot is we're going to always go with the number one so we're going to define a function here the last function get response and this function will get intense list which is what we get here basically this return list and this function will then um just return it so we
will say intense intense Json is equal to Json load uh actually we don't have an intense Json file do we no we need to copy that to to the same directory here so it's going to load the intense intent. Json file is this in the same directory though yeah it is it should work let's see um but we have the intense Json file or actually we can we can put that into the model directory so let's go and say model intense Json so we're going to load that from here and uh for this to work
we need to open this and then we're going to say that the tag is going to be intense list zero so we just pick the best one again you can Implement a mechanism here to pick one at random or with r weighted Randomness or depending on some other algorithm if you want to but we're going to go with the best guess we're going to get the intent from it so we're going to get this piece here which is going to be the class we're going to take that intent um list of intense is going to
be equal to intense Json intense and we're going to say for I in list of intents if I tag so if the name of the intent in the adjacent file is the same as our tag that we got from the model prediction if that is the same we're going to get a response at random we're going to say random Choice from the responses of this particular intent and then we're going to break and we're going to return the results all right so that is basically it um this is the uto part that we need and
now we can put that into code in the actual flask application so we're going to create a flask application that just sends a request to the backend for this we're going to say from flask import the usual stuff flask request jsonify uh render template to render the HTML file then we're going to also save from utils import all these uh or actually not all of them we just need get response and predict class because predict class already uses bag of words and cleanup sentence and then we're going to say the app is equal to my
spacebar is hanging again something is wrong with this keyboard okay so app is equal to flask we're going to pass name here and the template folder is equal to templates which I think is the default um but I always state it explicitly and then we're going to say app. rout the default route will be nothing but just returning uh returning render template so we're going to just render the index HTML file and the important thing is how are we going to to interact with a backend because we're going to do that with JavaScript so on
the index HTML file we will have a JavaScript code that interacts with the back end with this um other endpoint that we're going to Define here and this is going to be the endpoint handle message which is going to only accept method equals uh which is only going to accept post request handle message this is going to then get as a post um as post data we're going to get a message the message is going to be equal to request Json and then message we're going to pass Json object to this endpoint we're going to
get uh the message from it we're going to get an intense list based on the message so we're going to call the predict class function on the message and then we're going to get the response by calling the get response function on the intense list uh which could also be further combined into one function actually let's leave it like this now um and then we going to return to the um to the front end we're going to return a Json object of response pointing to the response and that is basically it we're going to then
say if uncore name uncore equals main we're going to run the application on 000000 0 so Local Host debug equals true and that is our flask application just interacting with our utos code that we wrote um a minute ago so this is now all of the back end we need to move on to the front end now because the front end will actually have the code that interacts with the back end now as I said I'm going to copy a large part of the styling because I don't want to type now CSS code I hate
CSS I hate everything that has to do with styling so I'm going to copy paste all of this but I'm not going to copy paste the JavaScript part because the JavaScript part is going to be relevant to understand the functionality the only JavaScript part I'm going to copy is all of the stuff that has to do with the animation so clicking on a button to slide up the chat window but as I said you will find a code um on my GitHub you will find a link to it in description down below so let me
just delete all of this and use my prepared code here for the basic structure I'm going to copy all of this here so let me just copy this I'm going to briefly cover it here in a second but um here we're going to have a script tag where we're going to put the interesting code and then after this we just actually need to do a uh closing tag for body and HTML and what we also want to copy paste now for the script here is just the base basic um is just a basic chat toggle
here so we need to have or actually I can code this myself as well so let me just restructure this here with my development environment so we're going to do reformat code and what we have here is just a basic So functionally speaking we have a lot of styling stuff here but functionally speaking what we have is we have um a simple heading which is our intelligent web chat bot heading and then we have here a chat boox diff a chat toggle button which is the blue button that you saw in the preview a chat
content diff again and then we have again a diff with the messages a diff with the input and in the input diff we have an input type text and a button with uh the ID sent button that says send the only important thing is that you have a text box and that you have uh a send button and that you have a pain for messages because that's everything that's functionally relevant now what we're going to do now is we're going to add one simple animation so that we actually get a toggle so I'm going to
show you how to do that we're going to say first of all here document dollar document uh. ready and we're going to define a function actually let me also reformat this um and in here now we're going to Define all the stuff that we're going to do once the document is ready we're going to define a function or an event actually which is going to be the chat toggle remember we have this button here with the ID chat toggle so we need to add functionality to it uh we're going to do this by saying want
to get the ID chat toggle and we're going to say when you click on it we want to have this function defined here and what it's going to do is it's going to slight toggle the chat content window so we're going to say dollar # chat uh chat content and we're going to call the slight toggle function with a parameter fast this is going to lead to us being able to slight uh yeah to slight the chat bot so let's see if I can actually already run this and see the basic what's the problem here
handle message methods I think this needs to be plural so methods equals post now let's open this in the browser and as you can see this already works so we have this slide toggle this is what we just implemented and the rest doesn't have any functionality yet so what we want to do is we want to define a function sent message which will do all of the work so it's going to be a function uh actually I need to close this with a semicolon uh it's going to be a function this function will be called
send message and this send message function will do something and I want to call this function whenever I press the sent button or when I press the enter key in in the uh text input so we're going to say uh what was it it was descent button if you click on the sent button I want to have a function being executed and this function will call send message and also I want to map the user input if I key press the key with the ID 133 which is enter I want to also call the sent
message function so I'm going to say here what was it input user input do key press if we do a key press function with an event e it's important to pass an event here to understand which key was pressed I'm going to say if e do which is equal to 13 which is the enter key if that's the case then we're going to send message as well uh so that's that now the actual code happens here in the send message function what we're going to do is we're going to get the value of the text
input we're going to trim it we're going to append it to our uh diff box so to our chat box uh history here to our chat messages history and then we're going to perform an Ajax request a post request to the back end so we're going to say here this is all now again still user interface the message is going to be equal to getting the content of the user input text box so user input. value. Val um and then we're going to say if the message. trim so if we remove all the spaces if
that's uh not equal to an empty message so if we actually do have a message what we're going to do is we're going to say um append the message to the chat to the chat content uh or actually to chat messages diff box and we're going to do that by appending the following HTML code diff class equals message and this plus message plus and then we're going to close the diff and also add a line break like this so we're going to append a message with class messages is important because we have a styling for
the individual messages here which we copy paste it and then we're going to say we want to empty the user input because we want to type maybe the next message so user input dot value is going to be empty going to be set to empty and that's as far as the user interface goals now the actual request is done like this dollar. Ajax and we're going to now pass here a dictionary and in this dictionary we're going to map URL to in our case slash handle message so it's going to be targeted towards this endpoint
here this route handle message the uh type of request is going to be post the content type is going to be uh application Json application SL Json and then the data that we actually want to pass is going to be json. stringify and we're going to pass here the message being mapped to message and finally we want to Define what happens when we have a success success is going to be mapped to a function that gets data and here we're going to say that we want to display the response of the clients so we want
to do a chat messages so # chat messages. aent and basically actually let me just copy paste this we're going to do the same thing but it's going to have a different class as well received so this is going to have a different styling um and we're going to add your data response and then finally we're going to also scroll to the top so we're going to say chat messages. scroll top uh and we're going to say here chat messages zero do scroll height I hope I did not mess this one up here so actually
let me see there you go no should work all right so that is the JavaScript code not my favorite part to implement the front I'm sure I made some mistakes so let's just go ahead and test it let's run this let's see if it works or what I have to fix here open and then we're going to say hello and I get a response from my chat bar let's try again let's try to see if we get a different response there you go uh what is programming programming coding or software develop vment means writing computer
code to automate task what is flask oh now it has a problem with flask this is interesting why is that what is flask okay this was interesting what is flask okay for some reason I get uh programming coding or software development if I type it like this interesting but this is a problem with the model the cool thing now is if I want to add some functionality all I have to do is I have to repeat the process I have to go to the intense Json file I have to add a tag so let's go
and copy paste this add a new or actually let's do it just like this say noral 9 now replace the patterns by uh something like what is neural 9 tell me what is going on with my space key tell me something about neural 9 let's just keep it at that and then we can have a static response neural 9 is a YouTube channel and educational brand focusing on machine learning and python in general or programming mainly python in general uh so now we have this new intent so all I have to do is I have
to rerun the model training I can run it I can run again the 200 EPO there you go it's done then I copy all of this again so I copy this I replace all of this paste it here also copy paste intents Json file and then that's it I now have a new intent in my chatbot I can run this again I can go into the browser and I can ask immediately if he can tell me something about neural 9 what is neural 9 and I get a problem here okay let me just see oh
I think the problem is that the lowercase upper case stuff so let's see what is neural 9 there you go okay so it seems to be case sensitive but the point is you do get um you can easily add new intents you just have to probably diversify uh certain keywords so maybe you should also include some intents with uppercase lowercase differences and so on or you can in general add some code that handles this but this is how you can develop an intelligent web chat bot from scratch and python so that's it for today's video
I hope you enjoyed it and hope you learn something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget subscribe to to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye