diff --git a/chat_bot.py b/chat_bot.py index 923364a..def9762 100644 --- a/chat_bot.py +++ b/chat_bot.py @@ -1,6 +1,5 @@ import re import pandas as pd -import pyttsx3 from sklearn import preprocessing from sklearn.tree import DecisionTreeClassifier,_tree import numpy as np @@ -37,10 +36,7 @@ clf1 = DecisionTreeClassifier() clf = clf1.fit(x_train,y_train) -# print(clf.score(x_train,y_train)) -# print ("cross result========") scores = cross_val_score(clf, x_test, y_test, cv=3) -# print (scores) print (scores.mean()) @@ -53,17 +49,6 @@ indices = np.argsort(importances)[::-1] features = cols -def readn(nstr): - engine = pyttsx3.init() - - engine.setProperty('voice', "english+f5") - engine.setProperty('rate', 130) - - engine.say(nstr) - engine.runAndWait() - engine.stop() - - severityDictionary=dict() description_list = dict() precautionDictionary=dict() @@ -72,14 +57,18 @@ def readn(nstr): for index, symptom in enumerate(x): symptoms_dict[symptom] = index -def calc_condition(exp,days): - sum=0 +def calc_condition(exp, days): + total_severity = 0 for item in exp: - sum=sum+severityDictionary[item] - if((sum*days)/(len(exp)+1)>13): - print("You should take the consultation from doctor. ") + if item in severityDictionary: + total_severity += severityDictionary[item] + else: + print(f"System Warning: Symptom '{item}' not found in severityDictionary.") + + if (total_severity * days) / (len(exp) + 1) > 13: + print("Carey: I would suggest consultating a doctor! ") else: - print("It might not be that bad but you should take precautions.") + print("Carey: It seems like the situation is not that bad, but I think you should still take certain precautions.") def getDescription(): @@ -91,9 +80,6 @@ def getDescription(): _description={row[0]:row[1]} description_list.update(_description) - - - def getSeverityDict(): global severityDictionary with open('MasterData/symptom_severity.csv') as csv_file: @@ -107,7 +93,6 @@ def getSeverityDict(): except: pass - def getprecautionDict(): global precautionDictionary with open('MasterData/symptom_precaution.csv') as csv_file: @@ -118,12 +103,11 @@ def getprecautionDict(): _prec={row[0]:[row[1],row[2],row[3],row[4]]} precautionDictionary.update(_prec) - def getInfo(): - print("-----------------------------------HealthCare ChatBot-----------------------------------") - print("\nYour Name? \t\t\t\t",end="->") - name=input("") - print("Hello, ",name) + #print("-----------------------------------HealthCare ChatBot-----------------------------------") + print("\nCarey: Hello! I am Carey: The Get Well Bot and I am here to ensure you that All is Well!! What is your name? \n") + name=input("You: ") + print("Carey: Hello, ",name, "! How may I help you today~?") def check_pattern(dis_list,inp): pred_list=[] @@ -169,34 +153,31 @@ def tree_to_code(tree, feature_names): while True: - print("\nEnter the symptom you are experiencing \t\t",end="->") - disease_input = input("") + print("\nCarey: Don't worry! We'll figure this out together. Firstly, can you tell me the symptom that you are experiencing ? \n") + disease_input = input("You: ") conf,cnf_dis=check_pattern(chk_dis,disease_input) if conf==1: - print("searches related to input: ") + print("Carey: I found the following searches related to your symptom: ") for num,it in enumerate(cnf_dis): print(num,")",it) if num!=0: - print(f"Select the one you meant (0 - {num}): ", end="") - conf_inp = int(input("")) + print(f"Carey: Can you select the one you exactly meant? You can select by sending the corresponding number from (0 - {num})! \n") + conf_inp = int(input("You: ")) else: conf_inp=0 disease_input=cnf_dis[conf_inp] break - # print("Did you mean: ",cnf_dis,"?(yes/no) :",end="") - # conf_inp = input("") - # if(conf_inp=="yes"): - # break else: - print("Enter valid symptom.") + print("Carey: I am so sorry, I'm not sure about that symptom. Can you try re-phrasing or perhaps mentioning a different symptom instead?") while True: try: - num_days=int(input("Okay. From how many days ? : ")) + print("Carey: Oh, I see... For how many days have you been experiencing this? :\n ") + num_days=int(input("You: ")) break except: - print("Enter valid input.") + print("Carey: I don't think that's a number ;--;") def recurse(node, depth): indent = " " * depth if tree_.feature[node] != _tree.TREE_UNDEFINED: @@ -221,7 +202,7 @@ def recurse(node, depth): # if len(dis_list)!=0: # print("symptoms present " + str(list(symptoms_present))) # print("symptoms given " + str(list(symptoms_given)) ) - print("Are you experiencing any ") + print("Carey: By any chance, are you experiencing any") symptoms_exp=[] for syms in list(symptoms_given): inp="" @@ -231,7 +212,7 @@ def recurse(node, depth): if(inp=="yes" or inp=="no"): break else: - print("provide proper answers i.e. (yes/no) : ",end="") + print("Carey: You can let me know by either saying yes or no :) : \n") if(inp=="yes"): symptoms_exp.append(syms) @@ -239,25 +220,24 @@ def recurse(node, depth): # print(second_prediction) calc_condition(symptoms_exp,num_days) if(present_disease[0]==second_prediction[0]): - print("You may have ", present_disease[0]) + print("Carey: It seems to me that you may have ", present_disease[0]) print(description_list[present_disease[0]]) # readn(f"You may have {present_disease[0]}") # readn(f"{description_list[present_disease[0]]}") else: - print("You may have ", present_disease[0], "or ", second_prediction[0]) + print("Carey: It seems to me that you may have", present_disease[0], "or", second_prediction[0]) print(description_list[present_disease[0]]) print(description_list[second_prediction[0]]) # print(description_list[present_disease[0]]) precution_list=precautionDictionary[present_disease[0]] - print("Take following measures : ") + print("Carey: You don't have to panic! This is merely an assumption. Regardless, I suggest taking following measures! : \n") for i,j in enumerate(precution_list): print(i+1,")",j) - # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given) - # print("confidence level is " + str(confidence_level)) + print("\nCarey: Having flucating health is not uncommon. It can be stressful, but I want you to remember that things will improve and I am always here for you. Get Well Soon!") recurse(0, 1) getSeverityDict()