Commit 15ec85bc authored by Shalitha Deshan Jayasekara's avatar Shalitha Deshan Jayasekara 🏘

Merge branch 'IT18116984_WeerasundaraD.A' into 'master'

Implement Chatbot,API Cofiguration

See merge request !18
parents 35fd6065 18b07515
......@@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
# Default ignored files
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/disease_prediction.iml" filepath="$PROJECT_DIR$/.idea/disease_prediction.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
import numpy
import tensorflow as tf
from flask import Flask
from flask import request
from flask_cors import CORS
from tensorflow.keras.models import load_model
import keras
import predict_disease
app = Flask(__name__)
cors = CORS(app)
@app.route("/predict", methods =['POST'])
def predict():
data = numpy.array(request.get_json())
print(data)
prediction = predict_disease.predict(data)
return {"pred": str(numpy.argmax(prediction))}
if __name__ == '__main__':
app.run(debug=True, port=5001, host="0.0.0.0")
import numpy
import pandas as pd
import tensorflow as tf
from keras.models import load_model
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import metrics
from sklearn import preprocessing
def loadModel(model):
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(7, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model = load_model('model.h5')
return model
def trainModel(model, datasetFilePath):
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(7, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model_df = pd.read_csv(datasetFilePath)
leDiseases = preprocessing.LabelEncoder()
leDiseases.fit(model_df['Diseases'])
print(leDiseases.classes_)
model_df['Diseases'] = leDiseases.transform(model_df['Diseases'])
# print(dataDf.describe())q
leBreeds = preprocessing.LabelEncoder()
leBreeds.fit(model_df['Breeds'])
model_df['Breeds'] = leBreeds.transform(model_df['Breeds'])
dataDf = model_df.fillna(0)
print(model_df.shape)
X = model_df.values[:,0:62]
y = model_df.values[:,62]
print(y)
x_train,x_test,y_train,y_test = train_test_split(X,y, stratify=y,test_size=0.2)
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
history = model.fit(x_train, y_train, epochs=15, validation_data=(x_test, y_test))
print("History: ", history)
val_loss, val_acc = model.evaluate(x_test, y_test)
print(val_loss)
print(val_acc)
model.save('model.h5')
print(history.history)
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
y_pred = model.predict_classes(x_test)
print(y_test)
print(y_pred)
cnf_matrix = metrics.confusion_matrix(y_test, y_pred)
print("===================")
print("Confusion matrix")
print("===================")
print(cnf_matrix)
return model
def predict(model, data):
return model.predict(numpy.array(data))
model = tf.keras.models.Sequential()
trainModel(model, "data.csv")
age,symptom1,symptom2,symptom3,symptom4,symptom5,symptom6,symptom7,symptom8,symptom9,symptom10,symptom11,symptom12,symptom13,symptom14,symptom15,symptom16,symptom17,disease
1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,3
1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,3
1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,3
1,1,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0
1,1,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
1,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,1,0
1,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0
1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0
4,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,0,0
4,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0
4,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0
4,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,0,0
4,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1
4,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1
4,1,1,1,1,1,0,1,1,1,0,1,0,0,1,1,1,0,1
4,1,1,1,1,1,1,1,1,1,1,1,0,0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,1,0,1,1,1,0
4,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,0,2
4,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,2
4,0,0,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,2
4,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,2
4,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,2
4,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,2
4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,2
\ No newline at end of file
Age,Breeds,anorexia,high_fever,itching,pus_discharge,fever,dripping_urine,cough,vomiting,unable_to_swallowing,scratching,scratching_the_affected_ear_on_the_floor,blood_in_urine,eye_discharge,lethargy,patchy_hair_loss,rubbing_the_affected_ear_on_the_floor,strain_to_urinate,nasal_discharge,bloody_diarrhea,increased_salivation,crusty_skin_ulcers,frequently_rotating_movement,diarrhea,frequently_urination,mild_fever,drooling,skin_redness,rash,painful,pale_gums,licking_genital_area,abdominal_pain,seizures,inflammation_of_skin,hyperemic_gums,bloating,paralysis,unpleasant_odor,redness_on_the_ear,whining_when_urination,weight_loss,hypersensitivity,stiff_joints,muscle_twitching,weakness,odd_behavior,thickening_of_skin,abnormal_bleeding,dehydration,sores_on_the_abdomen,enlarged_lymph_nodes,sores_on_the_legs,increased_capillary_refill_time,difficulty_breathing,sores_on_the_ears,pain,sores_on_the_chest,sores_on_the_elbows,partial_paralysis,complete_paralysis,Diseases
2,german sheppherd,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,Parvovirus
2,german sheppherd,1,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0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,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,Tick Fever
7,german sheppherd,1,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,Tick Fever
5,german sheppherd,1,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,Tick Fever
4,mongrel,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Urinary tract infections (UTIs)
3,mongrel,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Urinary tract infections (UTIs)
6,german sheppherd,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,Canine Distemper
4,german sheppherd,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,Canine Distemper
7,mongrel,1,0,0,0,1,0,1,0,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,Canine Distemper
10,pomeranian,1,0,0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,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,Canine Distemper
6,pomeranian,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,Canine Distemper
7,german sheppherd,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,Canine Distemper
8,mongrel,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,Canine Distemper
7,pomeranian,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,Canine Distemper
9,german sheppherd,1,0,0,0,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,Canine Distemper
......@@ -3,6 +3,20 @@ import pandas as pd
import tensorflow as tf
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import preprocessing
dataDf = pd.read_csv("data.csv")
leDiseases = preprocessing.LabelEncoder()
leDiseases.fit(dataDf['Diseases'])
print(leDiseases.classes_)
dataDf['Diseases'] = leDiseases.transform(dataDf['Diseases'])
# print(dataDf.describe())
leBreeds = preprocessing.LabelEncoder()
leBreeds.fit(dataDf['Breeds'])
dataDf['Breeds'] = leBreeds.transform(dataDf['Breeds'])
dataDf = dataDf.fillna(0)
model = tf.keras.models.Sequential()
......@@ -10,19 +24,24 @@ def trainModel(model, datasetFilePath):
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(256, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(128, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(11, activation=tf.nn.softmax))
model.add(tf.keras.layers.Dense(7, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model_df = pd.read_csv(datasetFilePath)
print(model_df.shape)
X = model_df.values[:,0:18]
y = model_df.values[:,18]
print(y)
print(dataDf.shape)
X = dataDf[['Age','Breeds','anorexia','high_fever','itching','pus_discharge','fever','dripping_urine','cough','vomiting','unable_to_swallowing','scratching','scratching_the_affected_ear_on_the_floor','blood_in_urine','eye_discharge','lethargy','patchy_hair_loss','rubbing_the_affected_ear_on_the_floor','strain_to_urinate','nasal_discharge','bloody_diarrhea','increased_salivation','crusty_skin_ulcers','frequently_rotating_movement','diarrhea','frequently_urination','mild_fever','drooling','skin_redness','rash','painful','pale_gums','licking_genital_area','abdominal_pain','seizures','inflammation_of_skin','hyperemic_gums','bloating','paralysis','unpleasant_odor','redness_on_the_ear','whining_when_urination','weight_loss','hypersensitivity','stiff_joints','muscle_twitching','weakness','odd_behavior','thickening_of_skin','abnormal_bleeding','dehydration','sores_on_the_abdomen','enlarged_lymph_nodes','sores_on_the_legs','increased_capillary_refill_time','difficulty_breathing','sores_on_the_ears','pain','sores_on_the_chest','sores_on_the_elbows','partial_paralysis','complete_paralysis']]
y = dataDf[['Diseases']]
# print(y)
x_train,x_test,y_train,y_test = train_test_split(X,y, stratify=y,test_size=0.2)
x_train = tf.keras.utils.normalize(x_train, axis=1)
x_test = tf.keras.utils.normalize(x_test, axis=1)
# x_train = tf.keras.utils.normalize(x_train, axis=1)
# x_test = tf.keras.utils.normalize(x_test, axis=1)
print("==================")
print(x_train)
print("==================")
print(y_train)
print("==================")
history = model.fit(x_train, y_train, epochs=50, validation_data=(x_test, y_test))
val_loss, val_acc = model.evaluate(x_test, y_test)
......
import numpy
import tensorflow as tf
from flask import Flask
from flask import request
from flask_cors import CORS
from tensorflow.keras.models import load_model
import keras
app = Flask(__name__)
cors = CORS(app)
@app.route("/predict", methods =['POST'])
def predict():
model = tf.keras.models.Sequential()
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(7, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model = load_model('model.h5')
data = numpy.array(request.get_json())
print(data)
prediction = model.predict(data)
return {"pred": str(numpy.argmax(prediction))}
if __name__ == '__main__':
app.run(debug=True, port=5001)
import tensorflow as tf
import numpy
from tensorflow.keras.models import load_model
model = tf.keras.models.Sequential()
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten())
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(25, activation=tf.nn.relu))
model.add(tf.keras.layers.Dense(7, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model = load_model('model.h5')
prediction = model.predict(numpy.array([[6,1,1,1,1,1,104,1,0,1,1,1,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1,6,1,1,1,1,1,104,1,0,1,1,1,0,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1]]))
print(prediction)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment