├── README.md └── python-chatbot.ipynb /README.md: -------------------------------------------------------------------------------- 1 | ## Python Chat-Bot 2 | This is a simple python chat bot. It will replay Questions based on predefine Questions and Answers. 3 | -------------------------------------------------------------------------------- /python-chatbot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Uttam.ipynb", 7 | "provenance": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "code", 20 | "execution_count": null, 21 | "metadata": { 22 | "colab": { 23 | "base_uri": "https://localhost:8080/" 24 | }, 25 | "id": "f3bmi1uj6hdO", 26 | "outputId": "0bb364b2-bf6b-4e58-efa4-a14af23afe61" 27 | }, 28 | "outputs": [ 29 | { 30 | "output_type": "stream", 31 | "name": "stdout", 32 | "text": [ 33 | "Collecting chatterbot\n", 34 | " Downloading ChatterBot-1.0.8-py2.py3-none-any.whl (63 kB)\n", 35 | "\u001b[?25l\r\u001b[K |█████▏ | 10 kB 25.4 MB/s eta 0:00:01\r\u001b[K |██████████▎ | 20 kB 28.3 MB/s eta 0:00:01\r\u001b[K |███████████████▌ | 30 kB 34.3 MB/s eta 0:00:01\r\u001b[K |████████████████████▋ | 40 kB 39.5 MB/s eta 0:00:01\r\u001b[K |█████████████████████████▊ | 51 kB 41.4 MB/s eta 0:00:01\r\u001b[K |███████████████████████████████ | 61 kB 44.6 MB/s eta 0:00:01\r\u001b[K |████████████████████████████████| 63 kB 2.3 MB/s \n", 36 | "\u001b[?25hRequirement already satisfied: python-dateutil<2.9,>=2.8 in /usr/local/lib/python3.7/dist-packages (from chatterbot) (2.8.2)\n", 37 | "Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from chatterbot) (2018.9)\n", 38 | "Collecting mathparse<0.2,>=0.1\n", 39 | " Downloading mathparse-0.1.2-py3-none-any.whl (7.2 kB)\n", 40 | "Collecting sqlalchemy<1.4,>=1.3\n", 41 | " Downloading SQLAlchemy-1.3.24-cp37-cp37m-manylinux2010_x86_64.whl (1.3 MB)\n", 42 | "\u001b[K |████████████████████████████████| 1.3 MB 43.2 MB/s \n", 43 | "\u001b[?25hRequirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil<2.9,>=2.8->chatterbot) (1.15.0)\n", 44 | "Installing collected packages: sqlalchemy, mathparse, chatterbot\n", 45 | " Attempting uninstall: sqlalchemy\n", 46 | " Found existing installation: SQLAlchemy 1.4.29\n", 47 | " Uninstalling SQLAlchemy-1.4.29:\n", 48 | " Successfully uninstalled SQLAlchemy-1.4.29\n", 49 | "Successfully installed chatterbot-1.0.8 mathparse-0.1.2 sqlalchemy-1.3.24\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "pip install chatterbot" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "source": [ 60 | "from chatterbot import ChatBot\n", 61 | "from chatterbot.trainers import ListTrainer\n", 62 | "bot = ChatBot(\"Uttam\")\n", 63 | "trainer = ListTrainer(bot)\n", 64 | "\n", 65 | "trainer.train(\n", 66 | " [\n", 67 | " 'Hi',\n", 68 | " 'Hello',\n", 69 | " 'How are you?',\n", 70 | " 'I am fine thank you. What about you?',\n", 71 | " 'I am also fine',\n", 72 | " 'Nice to hear that',\n", 73 | " 'What is your name?',\n", 74 | " 'My name is uttam',\n", 75 | " 'Thank you',\n", 76 | " 'You are most welcome',\n", 77 | " 'কেমন আছেন?',\n", 78 | " 'আমি ভালো আছি'\n", 79 | " ]\n", 80 | ")" 81 | ], 82 | "metadata": { 83 | "colab": { 84 | "base_uri": "https://localhost:8080/" 85 | }, 86 | "id": "nCO71wNq8cIq", 87 | "outputId": "124039bd-6526-423f-9bfe-7d4999cc79c6" 88 | }, 89 | "execution_count": null, 90 | "outputs": [ 91 | { 92 | "output_type": "stream", 93 | "name": "stdout", 94 | "text": [ 95 | "List Trainer: [####################] 100%\n" 96 | ] 97 | } 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "source": [ 103 | "name = input(\"Enter your name: \")\n", 104 | "\n", 105 | "while True:\n", 106 | " try:\n", 107 | " print(name,end=\"-->\") \n", 108 | " user_input= input()\n", 109 | " if user_input=='bye':\n", 110 | " break\n", 111 | " bot_response = bot.get_response(user_input)\n", 112 | "\n", 113 | " print(\"BOT-->\",bot_response)\n", 114 | " print(\"\")\n", 115 | "\n", 116 | " except(KeyboardInterrupt, EOFError, SystemExit ):\n", 117 | " break \n" 118 | ], 119 | "metadata": { 120 | "colab": { 121 | "base_uri": "https://localhost:8080/" 122 | }, 123 | "id": "KUEaEB50-fvl", 124 | "outputId": "2d06cbc7-f521-49d7-9cae-0f540062e962" 125 | }, 126 | "execution_count": null, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "Enter your name: Uttam\n", 133 | "Uttam-->Hi\n", 134 | "BOT--> Hello\n", 135 | "\n", 136 | "Uttam-->How are you?\n", 137 | "BOT--> I am fine thank you. What about you?\n", 138 | "\n", 139 | "Uttam-->I am also fine\n", 140 | "BOT--> Nice to hear that\n", 141 | "\n", 142 | "Uttam-->bye\n" 143 | ] 144 | } 145 | ] 146 | } 147 | ] 148 | } --------------------------------------------------------------------------------