|
a |
|
b/HealthCare_ChatBot/bot.py |
|
|
1 |
import pickle as pk |
|
|
2 |
import numpy as np |
|
|
3 |
import spacy |
|
|
4 |
import torch |
|
|
5 |
import random |
|
|
6 |
from sklearn.tree import _tree |
|
|
7 |
import Searching_des as des |
|
|
8 |
from reply import all_response_msg |
|
|
9 |
from nn_model import NeuralNet |
|
|
10 |
|
|
|
11 |
#******************************************* for Device *********************************************** |
|
|
12 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') |
|
|
13 |
|
|
|
14 |
# remove warning |
|
|
15 |
import warnings |
|
|
16 |
def warn(*args, **kwargs): |
|
|
17 |
pass |
|
|
18 |
warnings.warn = warn |
|
|
19 |
|
|
|
20 |
# ===================================================== LOAD MODELS ================================================== |
|
|
21 |
dtc , le = pk.load(open('./chatbot_modelsave','rb')) |
|
|
22 |
model,second_le = pk.load(open('./chatbot_model','rb')) |
|
|
23 |
ners = pk.load(open('./newsave_model','rb')) |
|
|
24 |
|
|
|
25 |
# Load NN Model |
|
|
26 |
FILE = "./data.pth" |
|
|
27 |
data = torch.load(FILE) |
|
|
28 |
|
|
|
29 |
# -------------------------------------- initlising Global varible ---------------------- |
|
|
30 |
return_input_disease = [] |
|
|
31 |
if len(return_input_disease) > 1: |
|
|
32 |
return_input_disease.clear() |
|
|
33 |
disease_first = [] |
|
|
34 |
symptoms_get = [] |
|
|
35 |
feature_names = ['itching', 'skin_rash', 'nodal_skin_eruptions', 'continuous_sneezing', 'shivering', 'chills', 'joint_pain', 'stomach_pain', 'acidity', 'ulcers_on_tongue', 'muscle_wasting', 'vomiting', 'burning_micturition', 'spotting_ urination', 'fatigue', 'weight_gain', 'anxiety', 'cold_hands_and_feets', 'mood_swings', 'weight_loss', 'restlessness', 'lethargy', 'patches_in_throat', 'irregular_sugar_level', 'cough', 'high_fever', 'sunken_eyes', 'breathlessness', 'sweating', 'dehydration', 'indigestion', 'headache', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'pain_behind_the_eyes', 'back_pain', 'constipation', 'abdominal_pain', 'diarrhoea', 'mild_fever', 'yellow_urine', 'yellowing_of_eyes', 'acute_liver_failure', 'fluid_overload', 'swelling_of_stomach', 'swelled_lymph_nodes', 'malaise', 'blurred_and_distorted_vision', 'phlegm', 'throat_irritation', 'redness_of_eyes', 'sinus_pressure', 'runny_nose', 'congestion', 'chest_pain', 'weakness_in_limbs', 'fast_heart_rate', 'pain_during_bowel_movements', 'pain_in_anal_region', 'bloody_stool', 'irritation_in_anus', 'neck_pain', 'dizziness', 'cramps', 'bruising', 'obesity', 'swollen_legs', 'swollen_blood_vessels', 'puffy_face_and_eyes', 'enlarged_thyroid', 'brittle_nails', 'swollen_extremeties', 'excessive_hunger', 'extra_marital_contacts', 'drying_and_tingling_lips', 'slurred_speech', 'knee_pain', 'hip_joint_pain', 'muscle_weakness', 'stiff_neck', 'swelling_joints', 'movement_stiffness', 'spinning_movements', 'loss_of_balance', 'unsteadiness', 'weakness_of_one_body_side', 'loss_of_smell', 'bladder_discomfort', 'foul_smell_of urine', 'continuous_feel_of_urine', 'passage_of_gases', 'internal_itching', 'toxic_look_(typhos)', 'depression', 'irritability', 'muscle_pain', 'altered_sensorium', 'red_spots_over_body', 'belly_pain', 'abnormal_menstruation', 'dischromic _patches', 'watering_from_eyes', 'increased_appetite', 'polyuria', 'family_history', 'mucoid_sputum', 'rusty_sputum', 'lack_of_concentration', 'visual_disturbances', 'receiving_blood_transfusion', 'receiving_unsterile_injections', 'coma', 'stomach_bleeding', 'distention_of_abdomen', 'history_of_alcohol_consumption', 'fluid_overload.1', 'blood_in_sputum', 'prominent_veins_on_calf', 'palpitations', 'painful_walking', 'pus_filled_pimples', 'blackheads', 'scurring', 'skin_peeling', 'silver_like_dusting', 'small_dents_in_nails', 'inflammatory_nails', 'blister', 'red_sore_around_nose', 'yellow_crust_ooze'] |
|
|
36 |
nlp = spacy.load("en_core_web_sm") |
|
|
37 |
|
|
|
38 |
#============================================== STEP 2 =================================================== |
|
|
39 |
# pridected desiese Step 2 |
|
|
40 |
def input_output(present_disease): |
|
|
41 |
value_dicts = { |
|
|
42 |
'(vertigo) Paroymsal Positional Vertigo': ['vomiting', 'headache', 'nausea', 'spinning_movements', 'loss_of_balance', 'unsteadiness'], 'AIDS': ['muscle_wasting', 'patches_in_throat', 'high_fever', 'extra_marital_contacts'], 'Acne': ['skin_rash', 'pus_filled_pimples', 'blackheads', 'scurring'], 'Alcoholic hepatitis': ['vomiting', 'yellowish_skin', 'abdominal_pain', 'swelling_of_stomach', 'distention_of_abdomen', 'history_of_alcohol_consumption', 'fluid_overload.1'], 'Allergy': ['continuous_sneezing', 'shivering', 'chills', 'watering_from_eyes'], 'Arthritis': ['muscle_weakness', 'stiff_neck', 'swelling_joints', 'movement_stiffness', 'painful_walking'], 'Bronchial Asthma': ['fatigue', 'cough', 'high_fever', 'breathlessness', 'family_history', 'mucoid_sputum'], 'Cervical spondylosis': ['back_pain', 'weakness_in_limbs', 'neck_pain', 'dizziness', 'loss_of_balance'], 'Chicken pox': ['itching', 'skin_rash', 'fatigue', 'lethargy', 'high_fever', 'headache', 'loss_of_appetite', 'mild_fever', 'swelled_lymph_nodes', 'malaise', 'red_spots_over_body'], 'Chronic cholestasis': ['itching', 'vomiting', 'yellowish_skin', 'nausea', 'loss_of_appetite', 'abdominal_pain', 'yellowing_of_eyes'], 'Common Cold': ['continuous_sneezing', 'chills', 'fatigue', 'cough', 'high_fever', 'headache', 'swelled_lymph_nodes', 'malaise', 'phlegm', 'throat_irritation', 'redness_of_eyes', 'sinus_pressure', 'runny_nose', 'congestion', 'chest_pain', 'loss_of_smell', 'muscle_pain'], 'Dengue': ['skin_rash', 'chills', 'joint_pain', 'vomiting', 'fatigue', 'high_fever', 'headache', 'nausea', 'loss_of_appetite', 'pain_behind_the_eyes', 'back_pain', 'malaise', 'muscle_pain', 'red_spots_over_body'], 'Diabetes ': ['fatigue', 'weight_loss', 'restlessness', 'lethargy', 'irregular_sugar_level', 'blurred_and_distorted_vision', 'obesity', 'excessive_hunger', 'increased_appetite', 'polyuria'], 'Dimorphic hemmorhoids(piles)': ['constipation', 'pain_during_bowel_movements', 'pain_in_anal_region', 'bloody_stool', 'irritation_in_anus'], 'Drug Reaction': ['itching', 'skin_rash', 'stomach_pain', 'burning_micturition', 'spotting_ urination'], 'Fungal infection': ['itching', 'skin_rash', 'nodal_skin_eruptions', 'dischromic _patches'], 'GERD': ['stomach_pain', 'acidity', 'ulcers_on_tongue', 'vomiting', 'cough', 'chest_pain'], 'Gastroenteritis': ['vomiting', 'sunken_eyes', 'dehydration', 'diarrhoea'], 'Heart attack': ['vomiting', 'breathlessness', 'sweating', 'chest_pain'], 'Hepatitis B': ['itching', 'fatigue', 'lethargy', 'yellowish_skin', 'dark_urine', 'loss_of_appetite', 'abdominal_pain', 'yellow_urine', 'yellowing_of_eyes', 'malaise', 'receiving_blood_transfusion', 'receiving_unsterile_injections'], 'Hepatitis C': ['fatigue', 'yellowish_skin', 'nausea', 'loss_of_appetite', 'yellowing_of_eyes', 'family_history'], 'Hepatitis D': ['joint_pain', 'vomiting', 'fatigue', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'abdominal_pain', 'yellowing_of_eyes'], 'Hepatitis E': ['joint_pain', 'vomiting', 'fatigue', 'high_fever', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'abdominal_pain', 'yellowing_of_eyes', 'acute_liver_failure', 'coma', 'stomach_bleeding'], 'Hypertension ': ['headache', 'chest_pain', 'dizziness', 'loss_of_balance', 'lack_of_concentration'], 'Hyperthyroidism': ['fatigue', 'mood_swings', 'weight_loss', 'restlessness', 'sweating', 'diarrhoea', 'fast_heart_rate', 'excessive_hunger', 'muscle_weakness', 'irritability', 'abnormal_menstruation'], 'Hypoglycemia': ['vomiting', 'fatigue', 'anxiety', 'sweating', 'headache', 'nausea', 'blurred_and_distorted_vision', 'excessive_hunger', 'drying_and_tingling_lips', 'slurred_speech', 'irritability', 'palpitations'], 'Hypothyroidism': ['fatigue', 'weight_gain', 'cold_hands_and_feets', 'mood_swings', 'lethargy', 'dizziness', 'puffy_face_and_eyes', 'enlarged_thyroid', 'brittle_nails', 'swollen_extremeties', 'depression', 'irritability', 'abnormal_menstruation'], 'Impetigo': ['skin_rash', 'high_fever', 'blister', 'red_sore_around_nose', 'yellow_crust_ooze'], 'Jaundice': ['itching', 'vomiting', 'fatigue', 'weight_loss', 'high_fever', 'yellowish_skin', 'dark_urine', 'abdominal_pain'], 'Malaria': ['chills', 'vomiting', 'high_fever', 'sweating', 'headache', 'nausea', 'diarrhoea', 'muscle_pain'], 'Migraine': ['acidity', 'indigestion', 'headache', 'blurred_and_distorted_vision', 'excessive_hunger', 'stiff_neck', 'depression', 'irritability', 'visual_disturbances'], 'Osteoarthristis': ['joint_pain', 'neck_pain', 'knee_pain', 'hip_joint_pain', 'swelling_joints', 'painful_walking'], 'Paralysis (brain hemorrhage)': ['vomiting', 'headache', 'weakness_of_one_body_side', 'altered_sensorium'], 'Peptic ulcer diseae': ['vomiting', 'indigestion', 'loss_of_appetite', 'abdominal_pain', 'passage_of_gases', 'internal_itching'], 'Pneumonia': ['chills', 'fatigue', 'cough', 'high_fever', 'breathlessness', 'sweating', 'malaise', 'phlegm', 'chest_pain', 'fast_heart_rate', 'rusty_sputum'], 'Psoriasis': ['skin_rash', 'joint_pain', 'skin_peeling', 'silver_like_dusting', 'small_dents_in_nails', 'inflammatory_nails'], 'Tuberculosis': ['chills', 'vomiting', 'fatigue', 'weight_loss', 'cough', 'high_fever', 'breathlessness', 'sweating', 'loss_of_appetite', 'mild_fever', 'yellowing_of_eyes', 'swelled_lymph_nodes', 'malaise', 'phlegm', 'chest_pain', 'blood_in_sputum'], 'Typhoid': ['chills', 'vomiting', 'fatigue', 'high_fever', 'headache', 'nausea', 'constipation', 'abdominal_pain', 'diarrhoea', 'toxic_look_(typhos)', 'belly_pain'], 'Urinary tract infection': ['burning_micturition', 'bladder_discomfort', 'foul_smell_of urine', 'continuous_feel_of_urine'], 'Varicose veins': ['fatigue', 'cramps', 'bruising', 'obesity', 'swollen_legs', 'swollen_blood_vessels', 'prominent_veins_on_calf'], 'hepatitis A': ['joint_pain', 'vomiting', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'abdominal_pain', 'diarrhoea', 'mild_fever', 'yellowing_of_eyes', 'muscle_pain'] |
|
|
43 |
} |
|
|
44 |
symptoms_given = value_dicts[present_disease[0]] |
|
|
45 |
symptoms_get.clear() |
|
|
46 |
symptoms_get.append(symptoms_given) |
|
|
47 |
|
|
|
48 |
|
|
|
49 |
# ================================================== NLTK, SPACY ============================================== |
|
|
50 |
# step 0-A |
|
|
51 |
# Create Bag of words |
|
|
52 |
def bag_of_words(tokenize_sentence , all_words): |
|
|
53 |
bag = np.zeros(len(all_words),dtype=np.float32) |
|
|
54 |
for idx , w in enumerate(all_words): |
|
|
55 |
if w in tokenize_sentence: |
|
|
56 |
bag[idx] = 1.0 |
|
|
57 |
return bag |
|
|
58 |
|
|
|
59 |
# ------------------------------------- Nural Network Model load ------------------------------------ |
|
|
60 |
# nltk model data |
|
|
61 |
input_size = data["input_size"] |
|
|
62 |
hidden_size = data["hidden_size"] |
|
|
63 |
output_size = data["output_size"] |
|
|
64 |
all_words = data['all_words'] |
|
|
65 |
tags = data['tags'] |
|
|
66 |
model_state = data["model_state"] |
|
|
67 |
|
|
|
68 |
nn_model = NeuralNet(input_size, hidden_size, output_size).to(device) |
|
|
69 |
nn_model.load_state_dict(model_state) |
|
|
70 |
nn_model.eval() |
|
|
71 |
|
|
|
72 |
# Create Nltk model |
|
|
73 |
def nltk_output(msg): |
|
|
74 |
sentence = [token.lemma_ for token in nlp(msg)] |
|
|
75 |
X = bag_of_words(sentence, all_words) |
|
|
76 |
X = X.reshape(1, X.shape[0]) |
|
|
77 |
X = torch.from_numpy(X).to(device) |
|
|
78 |
output = nn_model(X) |
|
|
79 |
_, predicted = torch.max(output, dim=1) |
|
|
80 |
tag = tags[predicted.item()] |
|
|
81 |
probs = torch.softmax(output, dim=1) |
|
|
82 |
prob = probs[0][predicted.item()] |
|
|
83 |
if prob.item() > 0.75: |
|
|
84 |
return random.choice(all_response_msg[tag]) |
|
|
85 |
return None |
|
|
86 |
|
|
|
87 |
|
|
|
88 |
#************************************************ START TREE AND RECURESION TO FIND DIES **************************************** |
|
|
89 |
# step 1-C |
|
|
90 |
# get and add predicted dieases |
|
|
91 |
def print_disease(node): |
|
|
92 |
node = node[0] |
|
|
93 |
val = node.nonzero() |
|
|
94 |
disease = le.inverse_transform(val[0]) |
|
|
95 |
disease_first.clear() |
|
|
96 |
disease_first.append(disease) |
|
|
97 |
input_output(disease) |
|
|
98 |
|
|
|
99 |
# step 1-B |
|
|
100 |
# recursion to get dieaseas input |
|
|
101 |
def recurse(node, depth): |
|
|
102 |
tree = dtc |
|
|
103 |
feature_names = ['itching', 'skin_rash', 'nodal_skin_eruptions', 'continuous_sneezing', 'shivering', 'chills', 'joint_pain', 'stomach_pain', 'acidity', 'ulcers_on_tongue', 'muscle_wasting', 'vomiting', 'burning_micturition', 'spotting_ urination', 'fatigue', 'weight_gain', 'anxiety', 'cold_hands_and_feets', 'mood_swings', 'weight_loss', 'restlessness', 'lethargy', 'patches_in_throat', 'irregular_sugar_level', 'cough', 'high_fever', 'sunken_eyes', 'breathlessness', 'sweating', 'dehydration', 'indigestion', 'headache', 'yellowish_skin', 'dark_urine', 'nausea', 'loss_of_appetite', 'pain_behind_the_eyes', 'back_pain', 'constipation', 'abdominal_pain', 'diarrhoea', 'mild_fever', 'yellow_urine', 'yellowing_of_eyes', 'acute_liver_failure', 'fluid_overload', 'swelling_of_stomach', 'swelled_lymph_nodes', 'malaise', 'blurred_and_distorted_vision', 'phlegm', 'throat_irritation', 'redness_of_eyes', 'sinus_pressure', 'runny_nose', 'congestion', 'chest_pain', 'weakness_in_limbs', 'fast_heart_rate', 'pain_during_bowel_movements', 'pain_in_anal_region', 'bloody_stool', 'irritation_in_anus', 'neck_pain', 'dizziness', 'cramps', 'bruising', 'obesity', 'swollen_legs', 'swollen_blood_vessels', 'puffy_face_and_eyes', 'enlarged_thyroid', 'brittle_nails', 'swollen_extremeties', 'excessive_hunger', 'extra_marital_contacts', 'drying_and_tingling_lips', 'slurred_speech', 'knee_pain', 'hip_joint_pain', 'muscle_weakness', 'stiff_neck', 'swelling_joints', 'movement_stiffness', 'spinning_movements', 'loss_of_balance', 'unsteadiness', 'weakness_of_one_body_side', 'loss_of_smell', 'bladder_discomfort', 'foul_smell_of urine', 'continuous_feel_of_urine', 'passage_of_gases', 'internal_itching', 'toxic_look_(typhos)', 'depression', 'irritability', 'muscle_pain', 'altered_sensorium', 'red_spots_over_body', 'belly_pain', 'abnormal_menstruation', 'dischromic _patches', 'watering_from_eyes', 'increased_appetite', 'polyuria', 'family_history', 'mucoid_sputum', 'rusty_sputum', 'lack_of_concentration', 'visual_disturbances', 'receiving_blood_transfusion', 'receiving_unsterile_injections', 'coma', 'stomach_bleeding', 'distention_of_abdomen', 'history_of_alcohol_consumption', 'fluid_overload.1', 'blood_in_sputum', 'prominent_veins_on_calf', 'palpitations', 'painful_walking', 'pus_filled_pimples', 'blackheads', 'scurring', 'skin_peeling', 'silver_like_dusting', 'small_dents_in_nails', 'inflammatory_nails', 'blister', 'red_sore_around_nose', 'yellow_crust_ooze'] |
|
|
104 |
disease_input = return_input_disease[0] |
|
|
105 |
tree_ = tree.tree_ |
|
|
106 |
feature_name = [ |
|
|
107 |
feature_names[i] if i != _tree.TREE_UNDEFINED else "undefined!" |
|
|
108 |
for i in tree_.feature |
|
|
109 |
] |
|
|
110 |
if tree_.feature[node] != _tree.TREE_UNDEFINED: |
|
|
111 |
name = feature_name[node] |
|
|
112 |
threshold = tree_.threshold[node] |
|
|
113 |
if name == disease_input: |
|
|
114 |
val = 1 |
|
|
115 |
else: |
|
|
116 |
val = 0 |
|
|
117 |
if val <= threshold: |
|
|
118 |
recurse(tree_.children_left[node], depth + 1) |
|
|
119 |
else: |
|
|
120 |
recurse(tree_.children_right[node], depth + 1) |
|
|
121 |
else: |
|
|
122 |
present_disease = print_disease(tree_.value[node]) |
|
|
123 |
|
|
|
124 |
# step 1-A |
|
|
125 |
# Check pattern of input data and extract usefull information |
|
|
126 |
def check_pattern(dis_list,inp): |
|
|
127 |
import re |
|
|
128 |
pred_list=[] |
|
|
129 |
ptr=0 |
|
|
130 |
|
|
|
131 |
#input hugging face word |
|
|
132 |
try: |
|
|
133 |
des_word = [] |
|
|
134 |
if len(des_word) > 1: |
|
|
135 |
des_word.clear() |
|
|
136 |
new_models = ners(f"i am suffering from {inp}" , aggregation_strategy="first") |
|
|
137 |
for result in new_models: |
|
|
138 |
if result['entity_group'] == "Disease" and int(float(result['score'])*100) >= 65 : |
|
|
139 |
des_word.append(result['word'].replace(" ", "")) |
|
|
140 |
regexp = re.compile(des_word[0]) |
|
|
141 |
except: |
|
|
142 |
des_word = [] |
|
|
143 |
if len(des_word) > 1: |
|
|
144 |
des_word.clear() |
|
|
145 |
des_word.append(inp) |
|
|
146 |
try: |
|
|
147 |
regexp = re.compile(des_word[0]) |
|
|
148 |
except: |
|
|
149 |
des_word.append("joint pain") |
|
|
150 |
regexp = re.compile(des_word[0]) |
|
|
151 |
for item in dis_list: |
|
|
152 |
if regexp.search(item): |
|
|
153 |
pred_list.append(item) |
|
|
154 |
if(len(pred_list)>0): |
|
|
155 |
# if match found then |
|
|
156 |
return 1,pred_list,des_word[0] |
|
|
157 |
else: |
|
|
158 |
# if match not found or only one same type of item present |
|
|
159 |
return ptr,item,des_word[0] |
|
|
160 |
|
|
|
161 |
# step 1 |
|
|
162 |
# using model check the passible diesiase can predict by tree and recursions after calling method |
|
|
163 |
def tree_to_code(disease_input): |
|
|
164 |
conf,cnf_dis,desies=check_pattern(feature_names,disease_input) |
|
|
165 |
if conf==1: |
|
|
166 |
if len(cnf_dis) > 1: |
|
|
167 |
output = f"Are you suffering from which type of ' {desies} ' ? Please confirm that: \n" |
|
|
168 |
for num,it in enumerate(cnf_dis): |
|
|
169 |
output += f"\t --> {it} \n" |
|
|
170 |
output += f"\t Note: Please use underscore ( _ ) in place of spacing in the name of disease.\n" |
|
|
171 |
return [output] |
|
|
172 |
else : |
|
|
173 |
output = f"You are suffering from {desies} \n" |
|
|
174 |
return_input_disease.clear() |
|
|
175 |
return_input_disease.append(disease_input) |
|
|
176 |
recurse(0,1) |
|
|
177 |
return [output ,"get_des",symptoms_get] |
|
|
178 |
else: |
|
|
179 |
return ["Ohh!! There were no similar diseases discovered. Please enter a valid symptom."] |
|
|
180 |
|
|
|
181 |
# ******************************************** Model Pridection Values *************************************** |
|
|
182 |
#step 3 |
|
|
183 |
# Model Predictions send response |
|
|
184 |
def get_pridected_value(symptoms_experiance): |
|
|
185 |
symptoms_dict = {'itching': 0, 'skin_rash': 1, 'nodal_skin_eruptions': 2, 'continuous_sneezing': 3, 'shivering': 4, 'chills': 5, 'joint_pain': 6, 'stomach_pain': 7, 'acidity': 8, 'ulcers_on_tongue': 9, 'muscle_wasting': 10, 'vomiting': 11, 'burning_micturition': 12, 'spotting_ urination': 13, 'fatigue': 14, 'weight_gain': 15, 'anxiety': 16, 'cold_hands_and_feets': 17, 'mood_swings': 18, 'weight_loss': 19, 'restlessness': 20, 'lethargy': 21, 'patches_in_throat': 22, 'irregular_sugar_level': 23, 'cough': 24, 'high_fever': 25, 'sunken_eyes': 26, 'breathlessness': 27, 'sweating': 28, 'dehydration': 29, 'indigestion': 30, 'headache': 31, 'yellowish_skin': 32, 'dark_urine': 33, 'nausea': 34, 'loss_of_appetite': 35, 'pain_behind_the_eyes': 36, 'back_pain': 37, 'constipation': 38, 'abdominal_pain': 39, 'diarrhoea': 40, 'mild_fever': 41, 'yellow_urine': 42, 'yellowing_of_eyes': 43, 'acute_liver_failure': 44, 'fluid_overload': 45, 'swelling_of_stomach': 46, 'swelled_lymph_nodes': 47, 'malaise': 48, 'blurred_and_distorted_vision': 49, 'phlegm': 50, 'throat_irritation': 51, 'redness_of_eyes': 52, 'sinus_pressure': 53, 'runny_nose': 54, 'congestion': 55, 'chest_pain': 56, 'weakness_in_limbs': 57, 'fast_heart_rate': 58, 'pain_during_bowel_movements': 59, 'pain_in_anal_region': 60, 'bloody_stool': 61, 'irritation_in_anus': 62, 'neck_pain': 63, 'dizziness': 64, 'cramps': 65, 'bruising': 66, 'obesity': 67, 'swollen_legs': 68, 'swollen_blood_vessels': 69, 'puffy_face_and_eyes': 70, 'enlarged_thyroid': 71, 'brittle_nails': 72, 'swollen_extremeties': 73, 'excessive_hunger': 74, 'extra_marital_contacts': 75, 'drying_and_tingling_lips': 76, 'slurred_speech': 77, 'knee_pain': 78, 'hip_joint_pain': 79, 'muscle_weakness': 80, 'stiff_neck': 81, 'swelling_joints': 82, 'movement_stiffness': 83, 'spinning_movements': 84, 'loss_of_balance': 85, 'unsteadiness': 86, 'weakness_of_one_body_side': 87, 'loss_of_smell': 88, 'bladder_discomfort': 89, 'foul_smell_of urine': 90, 'continuous_feel_of_urine': 91, 'passage_of_gases': 92, 'internal_itching': 93, 'toxic_look_(typhos)': 94, 'depression': 95, 'irritability': 96, 'muscle_pain': 97, 'altered_sensorium': 98, 'red_spots_over_body': 99, 'belly_pain': 100, 'abnormal_menstruation': 101, 'dischromic _patches': 102, 'watering_from_eyes': 103, 'increased_appetite': 104, 'polyuria': 105, 'family_history': 106, 'mucoid_sputum': 107, 'rusty_sputum': 108, 'lack_of_concentration': 109, 'visual_disturbances': 110, 'receiving_blood_transfusion': 111, 'receiving_unsterile_injections': 112, 'coma': 113, 'stomach_bleeding': 114, 'distention_of_abdomen': 115, 'history_of_alcohol_consumption': 116, 'fluid_overload.1': 117, 'blood_in_sputum': 118, 'prominent_veins_on_calf': 119, 'palpitations': 120, 'painful_walking': 121, 'pus_filled_pimples': 122, 'blackheads': 123, 'scurring': 124, 'skin_peeling': 125, 'silver_like_dusting': 126, 'small_dents_in_nails': 127, 'inflammatory_nails': 128, 'blister': 129, 'red_sore_around_nose': 130, 'yellow_crust_ooze': 131} |
|
|
186 |
pred_des_list = {15: 'Fungal infection', 4: 'Allergy', 16: 'GERD', 9: 'Chronic cholestasis', 14: 'Drug Reaction', 33: 'Peptic ulcer diseae', 1: 'AIDS', 12: 'Diabetes ', 17: 'Gastroenteritis', 6: 'Bronchial Asthma', 23: 'Hypertension ', 30: 'Migraine', 7: 'Cervical spondylosis', 32: 'Paralysis (brain hemorrhage)', 28: 'Jaundice', 29: 'Malaria', 8: 'Chicken pox', 11: 'Dengue', 37: 'Typhoid', 40: 'hepatitis A', 19: 'Hepatitis B', 20: 'Hepatitis C', 21: 'Hepatitis D', 22: 'Hepatitis E', 3: 'Alcoholic hepatitis', 36: 'Tuberculosis', 10: 'Common Cold', 34: 'Pneumonia', 13: 'Dimorphic hemmorhoids(piles)', 18: 'Heart attack', 39: 'Varicose veins', 26: 'Hypothyroidism', 24: 'Hyperthyroidism', 25: 'Hypoglycemia', 31: 'Osteoarthristis', 5: 'Arthritis', 0: '(vertigo) Paroymsal Positional Vertigo', 2: 'Acne', 38: 'Urinary tract infection', 35: 'Psoriasis', 27: 'Impetigo'} |
|
|
187 |
input_vector = np.zeros(len(symptoms_dict)) |
|
|
188 |
for item in symptoms_experiance: |
|
|
189 |
input_vector[[symptoms_dict[item]]] = 1 |
|
|
190 |
return pred_des_list[model.predict([input_vector])[0]] |
|
|
191 |
|
|
|
192 |
# get diesease Description after model preductions |
|
|
193 |
def get_diesese_practions(dieses): |
|
|
194 |
getprecaution = des.model.getPrecaution(dieses.capitalize()) |
|
|
195 |
if disease_first[0][0] == dieses : |
|
|
196 |
getdescription = des.model.getDescription(dieses.capitalize()) |
|
|
197 |
dieses = dieses |
|
|
198 |
else: |
|
|
199 |
des_first = des.model.getDescription(disease_first[0][0].capitalize()) |
|
|
200 |
des_sencond = des.model.getDescription(dieses.capitalize()) |
|
|
201 |
getdescription = f"{des_sencond} \n\n {des_first}" |
|
|
202 |
dieses = f"{dieses} or {disease_first[0][0]}" |
|
|
203 |
|
|
|
204 |
output = f"You may have {dieses} \n\n {getdescription} \n {getprecaution}\n" |
|
|
205 |
return output |
|
|
206 |
|
|
|
207 |
|
|
|
208 |
# =============================================== RESPNSE SEND TO USER ======================================== |
|
|
209 |
# step 0 |
|
|
210 |
# send response to the user |
|
|
211 |
def getresponse(response_msg): |
|
|
212 |
response_msg = response_msg.lower() |
|
|
213 |
try: |
|
|
214 |
response_nn = nltk_output(response_msg) |
|
|
215 |
except: |
|
|
216 |
response_nn = None |
|
|
217 |
if response_nn is not None: |
|
|
218 |
return [response_nn] |
|
|
219 |
else: |
|
|
220 |
output_function = tree_to_code(response_msg) |
|
|
221 |
if len(output_function) > 1 : |
|
|
222 |
return output_function[0] ,output_function[2][0] |
|
|
223 |
elif len(output_function) == 1 : |
|
|
224 |
return output_function |