AI Chatbot in Revit using Python
Following my previous article on the C# Chatbot using the Revit API, I’ve decided to elaborate more on the fixed Chatbot in this article by creating an AI Chatbot using Python and Flask. This article informs the reader on the creation of a Chatbot using python and how its then added into Revit as a Web browser dockable plugin.
Firstly, AI chatbots develop their answers to complicated questions using natural language processes and machine learning. These Chatbots operate more efficiently the more they are trained which means the more they are taught the more efficient the response to the user will be.
In comparison to a fixed Chatbot, an AI Chatbot system learns in accordance with its experiences rather than a data feeding process. AI Chatbots use algorithms whenever an input is received, they then analyze the input, form the context and thereafter provides the user with accurate results
My inspiration for this AI Chatbot stemmed from one of the frequent problems we face when working with clients, which is support cases. A support case is when a client has a query regarding the Revit software and needs our prompt assistance. The current process to handle a support case is, the client calls in with their problem and any available technical staff assists. This process however has several problems mainly the turnaround time that the staff takes to resolve the problem queried.
The motive of the AI Chatbot is to provide solutions more promptly to users and to mitigate the issue of delayed solutions due to turn around times. This AI Chatbot will provide split-second reactions to the users and mitigate longer turnaround times . This AI chatbot would provide round the clock assistance which the technical resource could not.
To add the chatbot to Revit and collect all the user data, a dockable web browser plugin was used that points to the hosted chatbot on Heroku.
The WPF plugin implements the IDockablePaneProvider Interface as shown In the figure below
The chromium web browser was used as seen in the figure below
Flask, Keras and Tensor Flow are used to build the chatbot to create the machine learning model.
The figure below indicates the app directory structure.
The libraries used to train the network and saving the model to be consumed by the flask app is shown below
Below is a snippet of the code used to prepare the training data to be fed to the neural network. A data.json file was used as a data source with a dictionary being used to represent the data. The data was sourced from the Autodesk Knowledge network and the accepted solutions provided to the clients.
Figure below shows the final step in preparing the data for training. I create a test and a train list.
For the deep learning model, a three-layer model is created with the first layer containing 128 neurons, the second layer having 64 neurons and the third output layer having neurons equal to the number of intents to predict. ReLu activation function is used for the first two layers whilst the SoftMax activation function is used in the third layer.
In summary we have 3 dense layers and 2 dropout layers. The total number of parameters in the model is 46,328 as seen below. Once this is done the next step will be to compile and train the model.
The model was configured to use the SGD (stochastic gradient descent) optimizer which is a Gradient descent (with momentum) optimizer. After compiling the model, the model is trained and saved to be used in our flask app.
The figure below shows the libraries to be used and the flask app routes.
Below is a figure showing two functions, one that gets the user text and returns the tokens and the other that returns our words array for the chatbot to predict.
The following functions are for predicting the response. The functions use the chatbot_model.h5 file that was generated after the training to provide a response to the user.
Lastly, I’ve used some basic html and JavaScript that receives users input and displays bot responses as seen in the figures below.
Figure below shows the JavaScript code that gets user input and returns the bots response
In conclusion the AI Chatbot is meant to mitigate delayed turn around times and provide prompt feedback to users queries, my project is currently under Research and Development so your feedback would be appreciated towards the development of an efficient and user friendly Chatbot.
Please like, share and leave your comments and suggestions below.
Great job and we are looking to produce the similar kind of idea.
I am fascinated and over the moon by great Idea. thank you. I would love to hear more on this topic
Any development on this post?