{"cells":[{"cell_type":"code","execution_count":3,"metadata":{"id":"0V8EjOkXGTFb","colab":{"base_uri":"https://localhost:8080/"},"outputId":"5524a27d-8f30-4905-dc82-b49d25e19bda","executionInfo":{"status":"ok","timestamp":1660462996396,"user_tz":-330,"elapsed":173470,"user":{"displayName":"Sachindu Gimhana","userId":"13341145685503871291"}}},"outputs":[{"output_type":"stream","name":"stdout","text":["Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: tflearn in /usr/local/lib/python3.7/dist-packages (0.5.0)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from tflearn) (1.21.6)\n","Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from tflearn) (1.15.0)\n","Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from tflearn) (7.1.2)\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: textblob in /usr/local/lib/python3.7/dist-packages (0.15.3)\n","Requirement already satisfied: nltk>=3.1 in /usr/local/lib/python3.7/dist-packages (from textblob) (3.7)\n","Requirement already satisfied: click in /usr/local/lib/python3.7/dist-packages (from nltk>=3.1->textblob) (7.1.2)\n","Requirement already satisfied: joblib in /usr/local/lib/python3.7/dist-packages (from nltk>=3.1->textblob) (1.1.0)\n","Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from nltk>=3.1->textblob) (4.64.0)\n","Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.7/dist-packages (from nltk>=3.1->textblob) (2022.6.2)\n"]},{"output_type":"stream","name":"stderr","text":["[nltk_data] Downloading package punkt to /root/nltk_data...\n","[nltk_data] Package punkt is already up-to-date!\n"]},{"name":"stdout","output_type":"stream","text":["Welcome to Canis Care VetBot (type quit to stop)!\n","You: hi\n","Sentiment Value is : 0.0\n","Hi there, what can I do for you?\n","You: what are the dog skin diseases\n","Sentiment Value is : 0.0\n","Ringworm, Acral Lick Dermatitis, Mange\n","You: what are the dog skin diseases\n","Sentiment Value is : 0.0\n","Folliculitis, Impetigo, Yeast Infections, Ticks and Fleas\n","You: dog skin diseases\n","Sentiment Value is : 0.0\n","Folliculitis, Impetigo, Yeast Infections, Ticks and Fleas\n","You: precations for Mange\n","Sentiment Value is : 0.0\n","Sores and lesions, Scabby, crusty or scaly skin\n","You: symptoms for mange\n","Sentiment Value is : 0.0\n","Sores and lesions, Scabby, crusty or scaly skin\n","You: thanks\n","Sentiment Value is : 0.2\n","The pleasure is all mine!\n","You: good be\n","Sentiment Value is : 0.7\n","Hello, thanks for visiting\n","You: goood bye\n","Sentiment Value is : 0.0\n","Have a nice day\n","You: eit\n","Sentiment Value is : 0.0\n","I didn't get that, try again.\n","You: exit\n","Sentiment Value is : 0.0\n","I didn't get that, try again.\n","You: quit\n"]}],"source":["!pip install tflearn\n","!pip install textblob\n","\n","import nltk\n","nltk.download('punkt')\n","from nltk.stem.lancaster import LancasterStemmer\n","stemmer = LancasterStemmer()\n","from textblob import TextBlob\n","import numpy\n","import tflearn\n","import tensorflow\n","import random\n","import json\n","import pickle\n","\n","with open(\"intents.json\") as file:\n"," data = json.load(file)\n","\n","try:\n"," with open(\"data.pickle\", \"rb\") as f:\n"," words, labels, training, output = pickle.load(f)\n","except:\n"," words = []\n"," labels = []\n"," docs_x = []\n"," docs_y = []\n","\n"," for intent in data[\"intents\"]:\n"," for pattern in intent[\"patterns\"]:\n"," wrds = nltk.word_tokenize(pattern)\n"," words.extend(wrds)\n"," docs_x.append(wrds)\n"," docs_y.append(intent[\"tag\"])\n","\n"," if intent[\"tag\"] not in labels:\n"," labels.append(intent[\"tag\"])\n","\n"," words = [stemmer.stem(w.lower()) for w in words if w != \"?\"]\n"," words = sorted(list(set(words)))\n","\n"," labels = sorted(labels)\n","\n"," training = []\n"," output = []\n","\n"," out_empty = [0 for _ in range(len(labels))]\n","\n"," for x, doc in enumerate(docs_x):\n"," bag = []\n","\n"," wrds = [stemmer.stem(w.lower()) for w in doc]\n","\n"," for w in words:\n"," if w in wrds:\n"," bag.append(1)\n"," else:\n"," bag.append(0)\n","\n"," output_row = out_empty[:]\n"," output_row[labels.index(docs_y[x])] = 1\n","\n"," training.append(bag)\n"," output.append(output_row)\n","\n","\n"," training = numpy.array(training)\n"," output = numpy.array(output)\n","\n"," with open(\"data.pickle\", \"wb\") as f:\n"," pickle.dump((words, labels, training, output), f)\n","\n","from tensorflow.python.framework import ops\n","ops.reset_default_graph()\n","\n","net = tflearn.input_data(shape=[None, len(training[0])])\n","net = tflearn.fully_connected(net, 8)\n","net = tflearn.fully_connected(net, 8)\n","net = tflearn.fully_connected(net, len(output[0]), activation=\"softmax\")\n","net = tflearn.regression(net)\n","\n","model = tflearn.DNN(net)\n","\n","try:\n"," model.load(\"model.tflearn\")\n","except:\n"," train = model.fit(training, output, n_epoch=2000, batch_size=8, show_metric=True)\n"," model.save(\"model.tflearn\")\n","\n","def bag_of_words(s, words):\n"," bag = [0 for _ in range(len(words))]\n","\n"," s_words = nltk.word_tokenize(s)\n"," s_words = [stemmer.stem(word.lower()) for word in s_words]\n","\n"," for se in s_words:\n"," for i, w in enumerate(words):\n"," if w == se:\n"," bag[i] = 1\n"," \n"," return numpy.array(bag)\n"," \n","def chat():\n"," print(\"Welcome to Canis Care VetBot (type quit to stop)!\")\n"," while True:\n"," inp = input(\"You: \")\n"," if inp.lower() == \"quit\":\n"," break\n"," \n"," #getting sentiment analysis value\n"," edu=TextBlob(inp)\n"," sa=edu.sentiment.polarity\n"," print(\"Sentiment Value is : \",sa) \n","\n"," results = model.predict([bag_of_words(inp, words)])[0]\n"," results_index = numpy.argmax(results)\n"," tag = labels[results_index]\n","\n"," if results[results_index] > 0.7:\n"," for tg in data[\"intents\"]:\n"," if tg['tag'] == tag:\n"," responses = tg['bot_response']\n","\n"," print(random.choice(responses))\n","\n"," else:\n"," print(\"I didn't get that, try again.\")\n","\n","chat()"]},{"cell_type":"code","source":[""],"metadata":{"id":"o5kZkho2SH1n"},"execution_count":null,"outputs":[]}],"metadata":{"colab":{"collapsed_sections":[],"name":"Vet_Bot.ipynb","provenance":[],"authorship_tag":"ABX9TyMO0aMAMOJF7Y+oufnfsl+s"},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
"What are the most prevalent skin illnesses in dogs?",
"What are the most prevalent skin illnesses in dogs?",
"What are some of the most common skin problems in dogs?"
"What are some of the most common skin problems in dogs?",
"What are the most common skin problems in dogs?"
],
],
"bot_response":[
"bot_response":[
"Ringworm, Acral Lick Dermatitis, Mange",
"Ringworm, Acral Lick Dermatitis, Mange",
...
@@ -51,7 +52,8 @@
...
@@ -51,7 +52,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Ringworm?",
"What are the symptoms of Ringworm?",
"Ringworm symptoms include ?",
"Ringworm symptoms include ?",
"How do I know if my dog has Ringworm?"
"How do I know if my dog has Ringworm?",
"Symptoms for Ringworm?"
],
],
"bot_response":[
"bot_response":[
"Circular areas of hair loss, often with a red and crusty edge",
"Circular areas of hair loss, often with a red and crusty edge",
...
@@ -68,7 +70,8 @@
...
@@ -68,7 +70,8 @@
"What are the Ringworm precautions?",
"What are the Ringworm precautions?",
"What are some Ringworm preventative measures?",
"What are some Ringworm preventative measures?",
"How can I prevent my dog from Ringworm?",
"How can I prevent my dog from Ringworm?",
"How can I keep my dog from getting Ringworm?"
"How can I keep my dog from getting Ringworm?",
"Precautions for Ringworm?"
],
],
"bot_response":[
"bot_response":[
"Fully cleanse the environment of the home and any tools and bedding that the animals regularly, Follow the instructions of your veterinarian"
"Fully cleanse the environment of the home and any tools and bedding that the animals regularly, Follow the instructions of your veterinarian"
...
@@ -82,7 +85,8 @@
...
@@ -82,7 +85,8 @@
"Why does my dog get Ringworm?",
"Why does my dog get Ringworm?",
"In my dog, what causes Ringworm?",
"In my dog, what causes Ringworm?",
"How is my dog affected by Ringworm?",
"How is my dog affected by Ringworm?",
"How does Ringworm affect my dog?"
"How does Ringworm affect my dog?",
"Causes for Ringworm?"
],
],
"bot_response":[
"bot_response":[
"Direct contact with an infected animal, Through contaminated objects such as brushes, dog beds, and toys, as well as surfaces that are difficult to clean, like rugs, wool, and wood, Some types of ringworm fungi live in the soil, weaker immune systems"
"Direct contact with an infected animal, Through contaminated objects such as brushes, dog beds, and toys, as well as surfaces that are difficult to clean, like rugs, wool, and wood, Some types of ringworm fungi live in the soil, weaker immune systems"
...
@@ -93,7 +97,8 @@
...
@@ -93,7 +97,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Dandruff?",
"What are the symptoms of Dandruff?",
"Dandruff symptoms include ?",
"Dandruff symptoms include ?",
"How do I know if my dog has Dandruff?"
"How do I know if my dog has Dandruff?",
"Symptoms for Dandruff?"
],
],
"bot_response":[
"bot_response":[
"Itchiness, An odor to the skin, Excessive amounts of dandruff",
"Itchiness, An odor to the skin, Excessive amounts of dandruff",
"Clean environment free of any fleas, urine, or fecal material",
"Clean environment free of any fleas, urine, or fecal material",
...
@@ -163,7 +172,8 @@
...
@@ -163,7 +172,8 @@
"Why does my dog get Impetigo?",
"Why does my dog get Impetigo?",
"In my dog, what causes Impetigo?",
"In my dog, what causes Impetigo?",
"How is my dog affected by Impetigo?",
"How is my dog affected by Impetigo?",
"How does Impetigo affect my dog?"
"How does Impetigo affect my dog?",
"Causes for Impetigo?"
],
],
"bot_response":[
"bot_response":[
"An overgrowth of Staphylococcus bacteria, Unhygienic areas, Fleas, Urine scalding"
"An overgrowth of Staphylococcus bacteria, Unhygienic areas, Fleas, Urine scalding"
...
@@ -174,7 +184,8 @@
...
@@ -174,7 +184,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Yeast Infections?",
"What are the symptoms of Yeast Infections?",
"Yeast Infections symptoms include ?",
"Yeast Infections symptoms include ?",
"How do I know if my dog has Yeast Infections?"
"How do I know if my dog has Yeast Infections?",
"Symptoms for Yeast Infections?"
],
],
"bot_response":[
"bot_response":[
"Changes in skin color and texture, Greasy skin, Scaly skin",
"Changes in skin color and texture, Greasy skin, Scaly skin",
...
@@ -189,7 +200,8 @@
...
@@ -189,7 +200,8 @@
"What are the Yeast Infections precautions?",
"What are the Yeast Infections precautions?",
"What are some Yeast Infections preventative measures?",
"What are some Yeast Infections preventative measures?",
"How can I prevent my dog from Yeast Infections?",
"How can I prevent my dog from Yeast Infections?",
"How can I keep my dog from getting Yeast Infections?"
"How can I keep my dog from getting Yeast Infections?",
"Precautions for Yeast Infections?"
],
],
"bot_response":[
"bot_response":[
"Keep the dog indoors during extreme heat and humidity",
"Keep the dog indoors during extreme heat and humidity",
...
@@ -208,7 +220,8 @@
...
@@ -208,7 +220,8 @@
"Why does my dog get Yeast Infections?",
"Why does my dog get Yeast Infections?",
"In my dog, what causes Yeast Infections?",
"In my dog, what causes Yeast Infections?",
"How is my dog affected by Yeast Infections?",
"How is my dog affected by Yeast Infections?",
"How does Yeast Infections affect my dog?"
"How does Yeast Infections affect my dog?",
"Causes for Yeast Infections?"
],
],
"bot_response":[
"bot_response":[
"Overactive immune system, Underactive immune system, They’re high in sugar and carbs",
"Overactive immune system, Underactive immune system, They’re high in sugar and carbs",
...
@@ -221,7 +234,8 @@
...
@@ -221,7 +234,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Ticks and Fleas?",
"What are the symptoms of Ticks and Fleas?",
"Ticks and Fleas symptoms include ?",
"Ticks and Fleas symptoms include ?",
"How do I know if my dog has Ticks and Fleas?"
"How do I know if my dog has Ticks and Fleas?",
"Symptoms for Ticks and Fleas?"
],
],
"bot_response":[
"bot_response":[
"Scratching, biting, or chewing skin,Losing hair, especially around the neck and tail",
"Scratching, biting, or chewing skin,Losing hair, especially around the neck and tail",
...
@@ -235,7 +249,8 @@
...
@@ -235,7 +249,8 @@
"What are the Ticks and Fleas precautions?",
"What are the Ticks and Fleas precautions?",
"What are some Ticks and Fleas preventative measures?",
"What are some Ticks and Fleas preventative measures?",
"How can I prevent my dog from Ticks and Fleas?",
"How can I prevent my dog from Ticks and Fleas?",
"How can I keep my dog from getting Ticks and Fleas?"
"How can I keep my dog from getting Ticks and Fleas?",
"Precautions for Ticks and Fleas?"
],
],
"bot_response":[
"bot_response":[
"Keep the lawn manicured, Check the dog regularly for signs of parasite activity",
"Keep the lawn manicured, Check the dog regularly for signs of parasite activity",
...
@@ -250,7 +265,8 @@
...
@@ -250,7 +265,8 @@
"Why does my dog get Ticks and Fleas?",
"Why does my dog get Ticks and Fleas?",
"In my dog, what causes Ticks and Fleas?",
"In my dog, what causes Ticks and Fleas?",
"How is my dog affected by Ticks and Fleas?",
"How is my dog affected by Ticks and Fleas?",
"How does Ticks and Fleas affect my dog?"
"How does Ticks and Fleas affect my dog?",
"Causes for Ticks and Fleas?"
],
],
"bot_response":[
"bot_response":[
"They’re out in that environment, walking through the woods or high grass, They crawl up on these low shrubs or grass"
"They’re out in that environment, walking through the woods or high grass, They crawl up on these low shrubs or grass"
...
@@ -261,7 +277,8 @@
...
@@ -261,7 +277,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Mange?",
"What are the symptoms of Mange?",
"Mange symptoms include ?",
"Mange symptoms include ?",
"How do I know if my dog has Mange?"
"How do I know if my dog has Mange?",
"Symptoms for Mange?"
],
],
"bot_response":[
"bot_response":[
"Redness, rash, and itching, Hair loss",
"Redness, rash, and itching, Hair loss",
...
@@ -275,7 +292,8 @@
...
@@ -275,7 +292,8 @@
"What are the Mange precautions?",
"What are the Mange precautions?",
"What are some Mange preventative measures?",
"What are some Mange preventative measures?",
"How can I prevent my dog from Mange?",
"How can I prevent my dog from Mange?",
"How can I keep my dog from getting Mange?"
"How can I keep my dog from getting Mange?",
"Precautions for Mange?"
],
],
"bot_response":[
"bot_response":[
"Keep pets away from any other animals suspected to have mange, including avoiding public dog parks or similar areas that may foster contagious outbreaks",
"Keep pets away from any other animals suspected to have mange, including avoiding public dog parks or similar areas that may foster contagious outbreaks",
...
@@ -291,7 +309,8 @@
...
@@ -291,7 +309,8 @@
"Why does my dog get Mange?",
"Why does my dog get Mange?",
"In my dog, what causes Mange?",
"In my dog, what causes Mange?",
"How is my dog affected by Mange?",
"How is my dog affected by Mange?",
"How does Mange affect my dog?"
"How does Mange affect my dog?",
"Causes for Mange?"
],
],
"bot_response":[
"bot_response":[
"Sarcoptic mite, Sarcoptes scabiei, or a closely related mite species like Notoedres",
"Sarcoptic mite, Sarcoptes scabiei, or a closely related mite species like Notoedres",
...
@@ -303,7 +322,8 @@
...
@@ -303,7 +322,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Lupus?",
"What are the symptoms of Lupus?",
"Lupus symptoms include ?",
"Lupus symptoms include ?",
"How do I know if my dog has Lupus?"
"How do I know if my dog has Lupus?",
"Symptoms for Lupus?"
],
],
"bot_response":[
"bot_response":[
"Pale skin on the bridge of the nose",
"Pale skin on the bridge of the nose",
...
@@ -318,7 +338,8 @@
...
@@ -318,7 +338,8 @@
"What are the Lupus precautions?",
"What are the Lupus precautions?",
"What are some Lupus preventative measures?",
"What are some Lupus preventative measures?",
"How can I prevent my dog from Lupus?",
"How can I prevent my dog from Lupus?",
"How can I keep my dog from getting Lupus?"
"How can I keep my dog from getting Lupus?",
"Precautions for Lupus?"
],
],
"bot_response":["Regular veterinary visits and Healthy lifestyle"]
"bot_response":["Regular veterinary visits and Healthy lifestyle"]
},
},
...
@@ -330,7 +351,8 @@
...
@@ -330,7 +351,8 @@
"Why does my dog get Lupus?",
"Why does my dog get Lupus?",
"In my dog, what causes Lupus?",
"In my dog, what causes Lupus?",
"How is my dog affected by Lupus?",
"How is my dog affected by Lupus?",
"How does Lupus affect my dog?"
"How does Lupus affect my dog?",
"Causes for Lupus?"
],
],
"bot_response":[
"bot_response":[
"Genetic factors, Immunologic disorders",
"Genetic factors, Immunologic disorders",
...
@@ -342,7 +364,8 @@
...
@@ -342,7 +364,8 @@
"patterns":[
"patterns":[
"What are the symptoms of Folliculitis?",
"What are the symptoms of Folliculitis?",
"Folliculitis symptoms include ?",
"Folliculitis symptoms include ?",
"How do I know if my dog has Folliculitis?"
"How do I know if my dog has Folliculitis?",
"Symptoms for Folliculitis?"
],
],
"bot_response":[
"bot_response":[
"Swelling, redness, itching, pustules (pimples) and Hair loss",
"Swelling, redness, itching, pustules (pimples) and Hair loss",
...
@@ -357,7 +380,8 @@
...
@@ -357,7 +380,8 @@
"What are the Folliculitis precautions?",
"What are the Folliculitis precautions?",
"What are some Folliculitis preventative measures?",
"What are some Folliculitis preventative measures?",
"How can I prevent my dog from Folliculitis?",
"How can I prevent my dog from Folliculitis?",
"How can I keep my dog from getting Folliculitis?"
"How can I keep my dog from getting Folliculitis?",
"Precautions for Folliculitis?"
],
],
"bot_response":[
"bot_response":[
"Keep the dog on year-round quality flea-prevention medication",
"Keep the dog on year-round quality flea-prevention medication",