No more visits to hospitals
Mobile-based health care decision support system
The hospital is a global convention where any patient may have medical examinations, diagnose diseases, and get treatment recommendations. This custom is followed by the majority of people all around the world. This has been regarded as the most appropriate and genuine method of keeping track of one’s physical body status. However, during COVID, this is not the best course of action. The suggested method seeks to discover an alternative to going to the hospital and making an appointment with a doctor for a check-up or diagnostic. The creation of a chatbot application using natural language processing and machine learning technologies helps people easily interact with the chatbot through a series of questions and doubts, similar to how people interact with each other. Meanwhile, the chatbot will find and identify the person’s symptoms, allowing it to predict which disease the person is suffering from and suggest appropriate remedies and treatments. It can also help people understand their health and urge more people to take necessary health-maintenance practices. According to the findings, such a system is not widely used, and most individuals are unaware of it. Putting this framework into action will greatly assist individuals in avoiding long-distance travels to the hospital simply by utilizing this application no matter where they are.
For that, we can create a Machine Learning-integrated conversation bot using Google Dialog Flow in 4 steps.
- Model of Machine Learning (for each disease like diabetes, heart disease, etc.)
- The Dialog Flow Chatbot collects user input.
- A Flask app that is deployed on any public host and presents the request and response.
- A webhook call is made by the chatbot to the Flask API to send data and retrieve the response.
and finally integration with mobile applications
How does it work?
In this system, We can add any number of diseases but I will talk about how I tried to predict and provide details about Heart diseases. This is a flutter-based mobile application. By logging into the system a user can start a conversation with the chatbot which prompts the questions to take input data.
- Building ML model
For this purpose, I have used this Kaggle dataset to create a model to predict whether a person has heart disease or not. We just import the data and apply the Random Forest classifier to it. If you like to have a look at the model I built you can look at this. Then just pickle the model, and this model, ‘model. pkl’ will be imported into our flask application later.
2. The DialogFlow chatbot
Now, let’s get right into DialogFlow to build our chatbot. Other APIs and frameworks may be used to develop a chatbot, but Google’s DialogFlow is an obvious choice because it is simple, free, and extremely fast to build! Sign in to DialogFlow using your Google account. Then, to construct your chatbot, click ‘Create new Agent.’Here I have already created the agent ‘Doctor’ to predict and query about heart diseases.
Next, we must develop an intent that will request data from the user and perform a webhook call. Before that, you have to create some intents to welcome users and some others to answer user queries. You can follow this documentation to get to know more about that.
The entities that will contain the data received from the user must be added. In my case, for example, I have 13 inputs. As indicated in the image below, create 13 distinct parameters for the 13 data points required from the user. Make sure to include prompts to ask for input from the user individually.
To create entities, there are custom entities and system entities. I have mostly used custom entities for matching data specific to my agent.
You may now test the chatbot on the right panel to see if it is working properly. After that, you must allow fulfillment by selecting ‘Enable webhook call for this intent’. As shown below
By doing so, this intent will send a webhook request to our app, which is hosted on Heroku’s public cloud. We must now construct the flask app, deploy it to Heroku, and then enter the URL in the ‘Fulfillment’ tab on the left side.
3. Flask application on Heroku
We must now create our flask app, which receives the webhook request from our chatbot, obtains the data, fits it to the ML model (model.pkl), and sends the fulfillment text to DialogFlow with the prediction. The code I used
After that, we must process the fulfillment request from DialogFlow, which is in JSON format. Once we’ve collected the data, we’ll put it into an array, feed it into our model, and obtain the prediction. You can have a look How I have done it at this link.
After that, we just need to deploy the code to the public host. I selected Heroku because, once again, it is simple, free, and really fast! Simply add the following files to your new Github repository: the flask app, the model pickle file, a Procfile (this is very important and helps Heroku locate the flask app), and a requirements text file that tells Heroku which libraries and versions to pre-install in order for the app to run correctly.
Simply create a repository on Github and upload it to Heroku. Make a ‘New App,’ then ‘Connect’ your Github repository to it. Once linked, simply press the deploy button and you’re done!
4. The Webhook call
Now comes the final phase. We must now link our deployed app to our chatbot. Simply input the URL of your app’s deployment and append ‘/webhook’ to it. Remember that the app is directed to ‘/webhook’ in the flask code. Simply navigate to DialogFlow’s ‘Fulfillment’ tab on the left panel, enable ‘Webhook,’ and enter <your app’s URL>/webhook.
And now we’re done!. You may check if the webhook request/response is operating properly by starting a conversation in the right panel. With the forecast, you should receive a fulfillment response.
We’ve arrived at the final stage. There isn’t much to do here because connecting mobile apps with DialogFlow is simple. The sample I have done here, How I have integrated to flutter mobile application and you can use it by making changes.
I hope this will be useful. Thank you for reading …