├── README.md ├── data ├── botprofile.yml ├── cough.cold.yml ├── doctor.yml ├── fever.yml ├── fracture.yml ├── generalhealth.yml ├── greetings.yml ├── headache.yml ├── new.yml └── personalinfo.yml ├── db.sqlite3 ├── requirements.txt ├── run.py ├── saved_conversations ├── 0 ├── 1 ├── 2 ├── 3 └── 4 ├── static └── style.css ├── templates └── index.html └── train.py /README.md: -------------------------------------------------------------------------------- 1 | # flask-chatbot 2 | Built on python 3.6 3 | Flask==0.11 4 | chatterbot==0.8.4 5 | SQLAlchemy==1.1.11 6 | 7 | #### A web implementation of [ChatterBot](https://github.com/gunthercox/ChatterBot) using Flask. 8 | 9 | ## Local Setup: 10 | 1. Open command prompt and locate folder. run 'pip install -r requirements.txt' 11 | 2. Run *train.py* 12 | 3. Run *run.py* 13 | 4. Demo will be live at http://localhost:5000/ 14 | 15 | ## License 16 | This source is free to use, but ChatterBot does have a license which still applies and can be found on the [LICENSE](https://github.com/gunthercox/ChatterBot/blob/master/LICENSE) page. 17 | -------------------------------------------------------------------------------- /data/botprofile.yml: -------------------------------------------------------------------------------- 1 | - - What are your interests 2 | - I am interested in helping you medically! 3 | - - What are your interests 4 | - I am interested in a wide variety of topics, and read rather a lot. 5 | - - What is your number 6 | - You can contact the helpline at +91 9999 11111 7 | - - What is your number 8 | - You can contact the helpline at +91 9999 11111 9 | - - What is your location 10 | - We are located at Dwarkadas J. Sanghvi College of Engineering as of now. 11 | - - What is your location 12 | - I am offline. So I am present at the same location as you. 13 | - - Where are you from 14 | - I am offline. at Dwarkadas J. Sanghvi College of Engineering as of now. 15 | - - Who is your father 16 | - Automated healthcare team created me. 17 | - - Who is your mother 18 | - Automated healthcare team created me. 19 | - - What is your age 20 | - I was created in February 2019. 21 | - - are you online? 22 | - no i am completely offline 23 | -------------------------------------------------------------------------------- /data/cough.cold.yml: -------------------------------------------------------------------------------- 1 | - - My nose is choked. 2 | - Okay, this is a symptom of cold, do you have cold? 3 | - - yes i have cold. 4 | - You should take a sudafed tablet after your meal. 5 | - - Ok, i will take the sudafed tablet. 6 | - let me know if you are feeling better after having sudafed tablet. 7 | - - I took the sudafed tablet. 8 | - Good, now take some rest and then let me know if you are feeling better after having sudafed tablet. 9 | - - No, i am still not felling better after having sudafed tablet. 10 | - Ok, its not just a normal cold, you should consult a doctor. 11 | - - Can u book an appointment for me. 12 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 13 | 14 | - - I have a cough. 15 | - You should take a spoon full of benadryl after your meal. 16 | - - Ok, i will take the benadryl. 17 | - let me know if you are feeling better after having benadryl. 18 | - - I took the dose of benadryl. 19 | - Good, now take some rest and then let me know if you are feeling better after having benadryl. 20 | - - No, i am still not felling better after having benadryl. 21 | - Ok, its not just a normal cough, you should consult a doctor. 22 | - - Can u book an appointment for me. 23 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 24 | - 25 | - - I have a cold. 26 | - You should take a sudafed tablet after your meal. 27 | - - Ok, i will take the sudafed tablet. 28 | - let me know if you are feeling better after having sudafed tablet. 29 | - - I took the sudafed tablet. 30 | - Good, now take some rest and then let me know if you are feeling better after having sudafed tablet. 31 | - - No, i am still not felling better after having sudafed tablet. 32 | - Ok, its not just a normal cold, you should consult a doctor. 33 | - - Can u book an appointment for me. 34 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 35 | 36 | - - My chest is aching. 37 | - Okay, this is a symptom of cough , do you have cough? 38 | - - yes i have cough. 39 | - You should take a spoon full of benadryl after your meal. 40 | - - Ok, i will take the benadryl. 41 | - let me know if you are feeling better after having benadryl. 42 | - - I took the dose of benadryl. 43 | - Good, now take some rest and then let me know if you are feeling better after having benadryl. 44 | - - No, i am still not felling better after having benadryl. 45 | - Ok, its not just a normal cough, you should consult a doctor. 46 | - - Can u book an appointment for me. 47 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 48 | 49 | - - My nose is itching. 50 | - Okay, this is a symptom of cold, do you have cold? 51 | - - yes i have cold. 52 | - You should take a sudafed tablet after your meal. 53 | - - Ok, i will take the sudafed tablet. 54 | - let me know if you are feeling better after having sudafed tablet. 55 | - - I took the sudafed tablet. 56 | - Good, now take some rest and then let me know if you are feeling better after having sudafed tablet. 57 | - - No, i am still not felling better after having sudafed tablet. 58 | - Ok, its not just a normal cold, you should consult a doctor. 59 | - - Can u book an appointment for me. 60 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 61 | 62 | - - My throat is itching. 63 | - Okay, this is a symptom of cough , do you have cough? 64 | - - yes i have cough. 65 | - You should take a spoon full of benadryl after your meal. 66 | - - Ok, i will take the benadryl. 67 | - let me know if you are feeling better after having benadryl. 68 | - - I took the dose of benadryl. 69 | - Good, now take some rest and then let me know if you are feeling better after having benadryl. 70 | - - No, i am still not felling better after having benadryl. 71 | - Ok, its not just a normal cough, you should consult a doctor. 72 | - - Can u book an appointment for me. 73 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 74 | - - -------------------------------------------------------------------------------- /data/doctor.yml: -------------------------------------------------------------------------------- 1 | - - is a doctor available ? 2 | - sorry, all doctors are occupied at the moment. We will connect you to a doctor soon. Do you want to book an appointment? 3 | - - hi can i see a doctor ? 4 | - all doctors are attending patients. we shall revert to your request soon. Do you want to book an appointment? 5 | - - i want to talk to a doctor 6 | - you shall be called once the doctor is available. Do you want to book an appointment? 7 | - - can you book an apointment with a doctor? 8 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 9 | - - Patient Name Date Time Doctor Hospital 10 | - appointment details saved. you shall be contacted shortly. 11 | - - thanks 12 | - happy to help! -------------------------------------------------------------------------------- /data/fever.yml: -------------------------------------------------------------------------------- 1 | - - I am not feeling well. 2 | - Okay. can you tell me what's wrong? what are your symptoms? 3 | - - My body temperature has raised. 4 | - This is a symptom of fever, you should take a tablet of crocin after you have your meal. 5 | - - Ok, i will take the crocin. 6 | - let me know if you are feeling better after having crocin. 7 | - - I took crocin. 8 | - Good, now take some rest and then let me know if you are feeling better after having crocin. 9 | - - No, i am still not felling better after having crocin. 10 | - Ok, its not just a normal fever, you should consult a doctor. 11 | - - Can u book an appointment for me. 12 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 13 | - - I am shivering. 14 | - This is a symptom of fever, you should take a tablet of crocin after you have your meal. 15 | - - Ok, i will take the crocin. 16 | - let me know if you are feeling better after having crocin. 17 | - - I took crocin. 18 | - Good, now take some rest and then let me know if you are feeling better after having crocin. 19 | - - No, i am still not felling better after having crocin. 20 | - Ok, its not just a normal fever, you should consult a doctor. 21 | - - Can u book an appointment for me. 22 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 23 | 24 | - - I am feeling weak. 25 | - This is a symptom of fever, you should take a tablet of crocin after you have your meal. 26 | - - Ok, i will take the crocin. 27 | - let me know if you are feeling better after having crocin. 28 | - - I took crocin. 29 | - Good, now take some rest and then let me know if you are feeling better after having crocin. 30 | - - No, i am still not felling better after having crocin. 31 | - Ok, its not just a normal fever, you should consult a doctor. 32 | - - Can u book an appointment for me. 33 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 34 | 35 | - - I have weakness in my body. 36 | - This is a symptom of fever, you should take a tablet of crocin after you have your meal. 37 | - - Ok, i will take the crocin. 38 | - let me know if you are feeling better after having crocin. 39 | - - I took crocin. 40 | - Good, now take some rest and then let me know if you are feeling better after having crocin. 41 | - - No, i am still not felling better after having crocin. 42 | - Ok, its not just a normal fever, you should consult a doctor. 43 | - - Can u book an appointment for me. 44 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' -------------------------------------------------------------------------------- /data/fracture.yml: -------------------------------------------------------------------------------- 1 | - - my hand is aching. 2 | - okay, did you get hurt, or it is a suddern aching. 3 | - - my leg is aching. 4 | - okay, did you get hurt, or it is a suddern aching. 5 | - - my joint is aching. 6 | - okay, did you get hurt, or it is a suddern aching. 7 | - - yes i got hurt. 8 | - ok, is there a swelling or a physical deformity or bleeding at the aching region. 9 | - - it is a mild ache. 10 | - ok, is there a swelling or a physical deformity or bleeding at the aching region. 11 | - - yes there is a swelling 12 | - okay, it is a common symptom of fracture, should I book an an appointment for you. 13 | - - yes there is a physical deformity. 14 | - okay, it is a common symptom of fracture, should I book an an appointment for you. 15 | - - yes it is bleeding. 16 | - okay, it is a common symptom of fracture, should I book an an appointment for you. 17 | - - yes i want to book an appointment. 18 | - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 19 | - - my hand is paining. 20 | - okay, did you get hurt, or it is a suddern paining. 21 | - - my leg is paining. 22 | - okay, did you get hurt, or it is a suddern paining. 23 | - - my joint is paining. 24 | - okay, did you get hurt, or it is a suddern paining. 25 | - - yes i got hurt. 26 | -------------------------------------------------------------------------------- /data/generalhealth.yml: -------------------------------------------------------------------------------- 1 | - - i feel sick 2 | - okay. can you tell me what's wrong? what are your symptoms? 3 | - - i am sick 4 | - okay. can you tell me what's wrong? what are your symptoms? 5 | - - i am not feeling well 6 | - okay. can you tell me what's wrong? what are your symptoms? 7 | - - i do not feeling well 8 | - okay. can you tell me what's wrong? what are your symptoms? 9 | - - i am not well 10 | - okay. can you tell me what's wrong? what are your symptoms? 11 | - - i feel fine 12 | - good to know. how may i assist you then? 13 | - - i am feeling fine 14 | - good to know. how may i assist you then? 15 | - - i feel great 16 | - good to know. how may i assist you then? 17 | - - i am feeling great 18 | - good to know. how may i assist you then? 19 | - - i am great 20 | - good to know. how may i assist you then? 21 | - - i feel awesome 22 | - great to know. how can i assist you then? 23 | 24 | -------------------------------------------------------------------------------- /data/greetings.yml: -------------------------------------------------------------------------------- 1 | - - hi there 2 | - hi. How are you feeling today? 3 | - - Hello 4 | - Hi. How are you feeling today? 5 | - - Hi 6 | - Hello. How are you feeling today? 7 | - - Greetings! 8 | - Hello. How are you feeling today? 9 | - - Hello 10 | - Namaste! How are you feeling today? 11 | - How are you feeling today? 12 | - - Hi, How is it going? 13 | - The app is working great! How are you feeling today? 14 | - - Hi, How are you feeling today? 15 | - I'm feeling fine. How are you feeling today? 16 | - - Hi, How is it going? 17 | - It's a little busy today. How are you feeling? 18 | - - Nice to meet you. 19 | - Thank you. How can i assist you? How are you feeling today? 20 | - - How do you do? 21 | - I'm doing well. How are you feeling today? 22 | - - How do you do? 23 | - I'm doing well. How are you feeling today? 24 | - - Hi, nice to meet you. 25 | - Thank you. You too. How are you feeling today? 26 | - - It is a pleasure to meet you. 27 | - Thank you. You too. How are you feeling today? 28 | - - Top of the morning to you! 29 | - Thank you kindly. How are you feeling today? 30 | - - Top of the morning to you! 31 | - And the rest of the day to you. How are you feeling today? 32 | - - What's up? 33 | - Not much. How are you feeling today? 34 | - - What's up? 35 | - Not too much. How are you feeling today? 36 | - - What's up? 37 | - Not much, how about you? How are you feeling today? 38 | - - What's up? 39 | - Nothing much. How are you feeling today? 40 | - - What's up? 41 | - The sky's up but I'm fine thanks. What about you? How are you feeling today? 42 | - - bye 43 | - Bye. Nice talking to you 44 | - - Bye bye 45 | - bye. thanks for using our service 46 | - - thanks for helping me out 47 | - you're most welcome 48 | - - thanks 49 | - always welcome 50 | 51 | -------------------------------------------------------------------------------- /data/headache.yml: -------------------------------------------------------------------------------- 1 | - - i have a headache 2 | - what kind of headache do you have : 1. Migrane headache - intense throbbing pain on just one side of the head. 2. Cluster headaches - severe and recurrent headaches 3. Tension Headache - Ocassional; 3 | - - i have a migrane headache 4 | - symptom noted. Migraines tend to be recurrent, and each attack may last up to 3 days. would you like to talk to a doctor? 5 | - - i have a cluster headache 6 | - symptom noted. Attacks tend to occur in daily clusters that can persist for weeks or months. They typically take place at the same time of day, which can often be a couple of hours after falling asleep at night. would you like to talk to a doctor? 7 | - - i have a tension headache 8 | - symptom noted. The cause of tension headaches is unclear, but stress, anxiety, and depression are common triggers. would you like to talk to a doctor? 9 | -------------------------------------------------------------------------------- /data/new.yml: -------------------------------------------------------------------------------- 1 | - - I am feeling dizzy. 2 | - This might be because you are tired, you should take some rest. 3 | - - 4 | - 5 | - - 6 | - -------------------------------------------------------------------------------- /data/personalinfo.yml: -------------------------------------------------------------------------------- 1 | - - i live in city 2 | - okay location stored. Welcome to medical portal. Say Hi! 3 | - - my name is 4 | - Hello! your name has been stored. What is your age? 5 | - - my age is 6 | - okay. your age has been stored. Which city do you live in? 7 | - - i am years old 8 | - okay. your age has been stored. Which city do you live in? 9 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atulyakumar97/NLP-chatbot/4de1d67bca20d41bbb151422fdfadd5e6a3ed3af/db.sqlite3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Used by pip to install required python packages 2 | # Usage: pip install -r requirements.txt 3 | 4 | Flask==0.12.3 5 | chatterbot==0.8.4 6 | SQLAlchemy==1.1.11 -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | from chatterbot import ChatBot 3 | from chatterbot.trainers import ChatterBotCorpusTrainer 4 | import os 5 | 6 | from chatterbot import ChatBot 7 | from chatterbot.trainers import ListTrainer 8 | 9 | filenumber=int(os.listdir('saved_conversations')[-1]) 10 | filenumber=filenumber+1 11 | file= open('saved_conversations/'+str(filenumber),"w+") 12 | file.write('bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n') 13 | file.close() 14 | 15 | app = Flask(__name__) 16 | 17 | 18 | english_bot = ChatBot('Bot', 19 | storage_adapter='chatterbot.storage.SQLStorageAdapter', 20 | logic_adapters=[ 21 | { 22 | 'import_path': 'chatterbot.logic.BestMatch' 23 | }, 24 | 25 | ], 26 | trainer='chatterbot.trainers.ListTrainer') 27 | english_bot.set_trainer(ListTrainer) 28 | 29 | @app.route("/") 30 | def home(): 31 | return render_template("index.html") 32 | 33 | @app.route("/get") 34 | def get_bot_response(): 35 | userText = request.args.get('msg') 36 | response = str(english_bot.get_response(userText)) 37 | 38 | appendfile=os.listdir('saved_conversations')[-1] 39 | appendfile= open('saved_conversations/'+str(filenumber),"a") 40 | appendfile.write('user : '+userText+'\n') 41 | appendfile.write('bot : '+response+'\n') 42 | appendfile.close() 43 | 44 | return response 45 | 46 | 47 | if __name__ == "__main__": 48 | app.run() 49 | -------------------------------------------------------------------------------- /saved_conversations/0: -------------------------------------------------------------------------------- 1 | Saved conversations index begins from 1 -------------------------------------------------------------------------------- /saved_conversations/1: -------------------------------------------------------------------------------- 1 | bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter. 2 | user : my name is atulya 3 | bot : - Hello! your name has been stored. What is your age? 4 | user : my age is 20 5 | bot : - okay. your age has been stored. Which city do you live in? 6 | user : i live in mumbai 7 | bot : - okay location stored. Welcome to medical portal. Say Hi! 8 | user : Hi 9 | bot : - Hello. How are you feeling today? 10 | user : i feel sick 11 | bot : - okay. can you tell me what's wrong? what are your symptoms? 12 | user : i have a headache 13 | bot : - what kind of headache do you have : 1. Migrane headache - intense throbbing pain on just one side of the head. 2. Cluster headaches - severe and recurrent headaches 3. Tension Headache - Ocassional; 14 | user : cluster headache 15 | bot : - symptom noted. Attacks tend to occur in daily clusters that can persist for weeks or months. They typically take place at the same time of day, which can often be a couple of hours after falling asleep at night. would you like to talk to a doctor? 16 | user : yes i'd like to talk to a doctor 17 | bot : - you shall be called once the doctor is available. Do you want to book an appointment? 18 | user : yes book an appointment for me 19 | bot : - yes please state time and doctor's name in the following format; 'Patient Name: Date: Doctor: Hospital:' 20 | user : Patient Name: Atulya Date: 05.03.17 Doctor: Yogesh Hospital: Hiranandani 21 | bot : - appointment details saved. you shall be contacted shortly. 22 | user : thanks 23 | bot : - happy to help! 24 | user : Bye 25 | bot : - Bye. Nice talking to you 26 | -------------------------------------------------------------------------------- /saved_conversations/2: -------------------------------------------------------------------------------- 1 | bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter. 2 | user : my name is yogesh 3 | bot : - Hello! your name has been stored. What is your age? 4 | user : hello 5 | bot : - Hi. How are you feeling today? 6 | user : i am 19 years old, am good 7 | bot : - you shall be called once the doctor is available. Do you want to book an appointment? 8 | user : i am good 9 | bot : - good to know. how may i assist you then? 10 | user : but i have some issues with my head 11 | bot : - symptom noted. Attacks tend to occur in daily clusters that can persist for weeks or months. They typically take place at the same time of day, which can often be a couple of hours after falling asleep at night. would you like to talk to a doctor? 12 | -------------------------------------------------------------------------------- /saved_conversations/3: -------------------------------------------------------------------------------- 1 | bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter. 2 | user : yogesh 3 | bot : - okay. your age has been stored. Which city do you live in? 4 | -------------------------------------------------------------------------------- /saved_conversations/4: -------------------------------------------------------------------------------- 1 | bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter. 2 | -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Garamond; 3 | } 4 | 5 | h1 { 6 | color: black; 7 | margin-bottom: 0; 8 | margin-top: 0; 9 | text-align: center; 10 | font-size: 40px; 11 | } 12 | 13 | h3 { 14 | color: black; 15 | font-size: 20px; 16 | margin-top: 3px; 17 | text-align: center; 18 | } 19 | 20 | #chatbox { 21 | margin-left: auto; 22 | margin-right: auto; 23 | width: 40%; 24 | margin-top: 60px; 25 | } 26 | 27 | #userInput { 28 | margin-left: auto; 29 | margin-right: auto; 30 | width: 40%; 31 | margin-top: 60px; 32 | } 33 | 34 | #textInput { 35 | width: 87%; 36 | border: none; 37 | border-bottom: 3px solid #009688; 38 | font-family: monospace; 39 | font-size: 17px; 40 | } 41 | 42 | #buttonInput { 43 | padding: 3px; 44 | font-family: monospace; 45 | font-size: 17px; 46 | } 47 | 48 | .userText { 49 | color: white; 50 | font-family: monospace; 51 | font-size: 17px; 52 | text-align: right; 53 | line-height: 30px; 54 | } 55 | 56 | .userText span { 57 | background-color: #009688; 58 | padding: 10px; 59 | border-radius: 2px; 60 | } 61 | 62 | .botText { 63 | color: white; 64 | font-family: monospace; 65 | font-size: 17px; 66 | text-align: left; 67 | line-height: 30px; 68 | } 69 | 70 | .botText span { 71 | background-color: #EF5350; 72 | padding: 10px; 73 | border-radius: 2px; 74 | } 75 | 76 | #tidbit { 77 | position:absolute; 78 | bottom:0; 79 | right:0; 80 | width: 300px; 81 | } -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |Please try typing full sentences as I am still learning!
12 |I am a chatbot. You can begin conversation by typing in a message and pressing enter.
13 |Hi There! What is your name?
14 |