--- a +++ b/.ipynb_checkpoints/run-checkpoint.ipynb @@ -0,0 +1,132 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n", + "\n", + "You said: i have a headache\n", + "\n", + "- 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", + "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n", + "\n", + "Your last instruction was unclear to me\n", + "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n", + "\n", + "Your last instruction was unclear to me\n", + "bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\n", + "\n" + ] + } + ], + "source": [ + "from flask import Flask, render_template, request\n", + "from chatterbot import ChatBot\n", + "from chatterbot.trainers import ChatterBotCorpusTrainer\n", + "import os\n", + "from gtts import gTTS\n", + "import speech_recognition as sr\n", + "import os\n", + "import re\n", + "import webbrowser\n", + "import smtplib\n", + "import requests\n", + "\n", + "\n", + "from chatterbot import ChatBot\n", + "from chatterbot.trainers import ListTrainer\n", + "\n", + "filenumber=int(os.listdir('saved_conversations')[-1])\n", + "filenumber=filenumber+1\n", + "file= open('saved_conversations/'+str(filenumber),\"w+\")\n", + "file.write('bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\\n')\n", + "file.close()\n", + "\n", + "\n", + "english_bot = ChatBot('Bot',\n", + " storage_adapter='chatterbot.storage.SQLStorageAdapter',\n", + " logic_adapters=[\n", + " {\n", + " 'import_path': 'chatterbot.logic.BestMatch'\n", + " },\n", + " \n", + "],\n", + "trainer='chatterbot.trainers.ListTrainer')\n", + "english_bot.set_trainer(ListTrainer)\n", + "\n", + "\n", + "def myCommand():\n", + " r = sr.Recognizer()\n", + "\n", + " with sr.Microphone() as source:\n", + " print('bot : Hi There! I am a medical chatbot. You can begin conversation by typing in a message and pressing enter.\\n')\n", + " r.pause_treshold = 1\n", + " r.adjust_for_ambient_noise(source, duration = 1)\n", + " audio = r.listen(source)\t\n", + "\n", + " try:\n", + " command = r.recognize_google(audio).lower()\n", + " print('You said: '+ command + '\\n')\n", + "\n", + " except sr.UnknownValueError:\n", + " print('Your last instruction was unclear to me')\n", + " command = myCommand();\n", + "\n", + " return command \n", + "\n", + "\n", + "def get_bot_response(command):\n", + " #userText = request.args.get('msg')\n", + " response = str(english_bot.get_response(command))\n", + "\n", + " appendfile=os.listdir('saved_conversations')[-1]\n", + " appendfile= open('saved_conversations/'+str(filenumber),\"a\")\n", + " appendfile.write('user : '+command+'\\n')\n", + " appendfile.write('bot : '+response+'\\n')\n", + " appendfile.close()\n", + " return response\n", + "\n", + "\n", + "while True:\n", + " value=get_bot_response(myCommand())\n", + " print(value)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}