a b/run.ipynb
1
{
2
 "cells": [
3
  {
4
   "cell_type": "code",
5
   "execution_count": null,
6
   "metadata": {},
7
   "outputs": [
8
    {
9
     "name": "stdout",
10
     "output_type": "stream",
11
     "text": [
12
      "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n",
13
      "\n",
14
      "You said: i have a headache\n",
15
      "\n",
16
      "- what kind of headache do you have : 1. Migrane headache - intense throbbing pain on just one side of the head. 2. Cluster headaches - severe and recurrent headaches 3. Tension Headache - Ocassional;\n",
17
      "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n",
18
      "\n",
19
      "Your last instruction was unclear to me\n",
20
      "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n",
21
      "\n",
22
      "Your last instruction was unclear to me\n",
23
      "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n",
24
      "\n"
25
     ]
26
    }
27
   ],
28
   "source": [
29
    "from flask import Flask, render_template, request\n",
30
    "from chatterbot import ChatBot\n",
31
    "from chatterbot.trainers import ChatterBotCorpusTrainer\n",
32
    "import os\n",
33
    "from gtts import gTTS\n",
34
    "import speech_recognition as sr\n",
35
    "import os\n",
36
    "import re\n",
37
    "import webbrowser\n",
38
    "import smtplib\n",
39
    "import requests\n",
40
    "\n",
41
    "\n",
42
    "from chatterbot import ChatBot\n",
43
    "from chatterbot.trainers import ListTrainer\n",
44
    "\n",
45
    "filenumber=int(os.listdir('saved_conversations')[-1])\n",
46
    "filenumber=filenumber+1\n",
47
    "file= open('saved_conversations/'+str(filenumber),\"w+\")\n",
48
    "file.write('bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\\n')\n",
49
    "file.close()\n",
50
    "\n",
51
    "\n",
52
    "english_bot = ChatBot('Bot',\n",
53
    "             storage_adapter='chatterbot.storage.SQLStorageAdapter',\n",
54
    "             logic_adapters=[\n",
55
    "   {\n",
56
    "       'import_path': 'chatterbot.logic.BestMatch'\n",
57
    "   },\n",
58
    "   \n",
59
    "],\n",
60
    "trainer='chatterbot.trainers.ListTrainer')\n",
61
    "english_bot.set_trainer(ListTrainer)\n",
62
    "\n",
63
    "\n",
64
    "def myCommand():\n",
65
    "    r = sr.Recognizer()\n",
66
    "\n",
67
    "    with sr.Microphone() as source:\n",
68
    "         print('bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\\n')\n",
69
    "         r.pause_treshold = 1\n",
70
    "         r.adjust_for_ambient_noise(source, duration = 1)\n",
71
    "         audio = r.listen(source)\t\n",
72
    "\n",
73
    "    try:\n",
74
    "        command = r.recognize_google(audio).lower()\n",
75
    "        print('You said: '+ command + '\\n')\n",
76
    "\n",
77
    "    except sr.UnknownValueError:\n",
78
    "           print('Your last instruction was unclear to me')\n",
79
    "           command = myCommand();\n",
80
    "\n",
81
    "    return command \n",
82
    "\n",
83
    "\n",
84
    "def get_bot_response(command):\n",
85
    "    #userText = request.args.get('msg')\n",
86
    "    response = str(english_bot.get_response(command))\n",
87
    "\n",
88
    "    appendfile=os.listdir('saved_conversations')[-1]\n",
89
    "    appendfile= open('saved_conversations/'+str(filenumber),\"a\")\n",
90
    "    appendfile.write('user : '+command+'\\n')\n",
91
    "    appendfile.write('bot : '+response+'\\n')\n",
92
    "    appendfile.close()\n",
93
    "    return response\n",
94
    "\n",
95
    "\n",
96
    "while True:\n",
97
    "    value=get_bot_response(myCommand())\n",
98
    "    print(value)"
99
   ]
100
  },
101
  {
102
   "cell_type": "code",
103
   "execution_count": null,
104
   "metadata": {
105
    "collapsed": true
106
   },
107
   "outputs": [],
108
   "source": []
109
  }
110
 ],
111
 "metadata": {
112
  "kernelspec": {
113
   "display_name": "Python 3",
114
   "language": "python",
115
   "name": "python3"
116
  },
117
  "language_info": {
118
   "codemirror_mode": {
119
    "name": "ipython",
120
    "version": 3
121
   },
122
   "file_extension": ".py",
123
   "mimetype": "text/x-python",
124
   "name": "python",
125
   "nbconvert_exporter": "python",
126
   "pygments_lexer": "ipython3",
127
   "version": "3.7.6"
128
  }
129
 },
130
 "nbformat": 4,
131
 "nbformat_minor": 2
132
}