Git Product home page Git Product logo

flask-chatterbot's Introduction

flask-chatterbot

A web implementation of ChatterBot using Flask.

Local Setup:

  1. Ensure that Python, Flask, SQLAlchemy, and ChatterBot are installed (either manually, or run pip install -r requirements.txt).
  2. Run app.py with python app.py.
  3. The demo will be live at http://localhost:5000/

How do I deploy this to a web server?

If you do not have a dedicated server, I highly recommend using PythonAnywhere, AWS or Heroku to host your application.

Deploying on Heroku

If you are deploying on Heroku, you will have to change the database adapter from chatterbot.storage.SQLStorageAdapter to chatterbot.storage.MongoDatabaseAdapter since SQLite3 isn't supported. To do this simply change the following line:

english_bot = ChatBot("English Bot", storage_adapter="chatterbot.storage.SQLStorageAdapter")

... to use the MongoDB adapter:

english_bot = ChatBot("English Bot", 
                     storage_adapter = "chatterbot.storage.MongoDatabaseAdapter",
                     database = mongodb_name,
                     database_uri = mongodb_uri)

... where mongodb_name is the name of the database you wish to connect to and mongodb_uri is the URI of a remote instance of MongoDB.

License

This source is free to use, but ChatterBot does have a license which still applies and can be found on the LICENSE page.

flask-chatterbot's People

Contributors

binitshah avatar chamkank avatar clashkid155 avatar deparkes avatar elicherla01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-chatterbot's Issues

I can't deploy it into PythonAnywhere

I tried to implement the chatbot in pythonanywhere, but I'm not getting it. I have already installed Flask, Chatterbot and SQLAlchemy and nothing. I have already edited the WSGI file, removing the app.run and nothing. I do not know how to fix this. Please help me.

Thank you.

Can Chatterbot speak Turkish?

In this days my friends are trying to create a robot that could look the person that in front of him than listen him. My job began in here. I have to create a chat bot that listen the person with mic than recognize what he/she says after that answer him.
Now my program can listen people and recognize the words. But my program can answer in English. Because i am Turkish i have make it in Turkish.
Is there anybody in there to help me?
This is all i got for now.

from gtts import gTTS
import os
import speech_recognition as sr
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Ron Obvious")

"""
conversation = [
"merhaba",
"sana da merhaba",
"ne haber",
"iyidir senden",
"kac yasindasin",
"18 yasindayim",
"ismin ne ",
"benim adim aytek",
"hava nasil",
"iyi bea nasil olsun"
]
"""

conversation = open('chats.txt','r').readlines()
chatbot.set_trainer(ListTrainer)
chatbot.train(conversation)

def konusma(metin):
tts= gTTS(text=metin ,lang='tr')
tts.save("aaa.mp3")
os.system("mpg321 aaa.mp3")

r= sr.Recognizer()

with sr.Microphone() as kaynak:
print("Please wait. Calibrating microphone...")
# listen for 5 seconds and calculate the ambient noise energy level
r.adjust_for_ambient_noise(kaynak, duration=5)
konusma('kalibre tamamlandi')

while True:
with sr.Microphone() as kaynak:
ses = r.listen(kaynak,timeout = None)
try:
print(r.recognize_google(ses,language="tr-TR"))
soru=r.recognize_google(ses,language="tr-TR")
response = chatbot.get_response(soru)
print(response)
konusma(str(response))
except sr.UnknownValueError:
print("Anlamadim.")
except sr.RequestError:
print("Bad Request")

error = english_bot.set_trainer(ChatterBotCorpusTrainer) AttributeError: 'ChatBot' object has no attribute 'set_trainer'

I'm seeing this problem as below.
no changes from the git repo, git clone, then pip install -r requirements.txt

it looks like a problem within the chatterbot git repo, which is weird.

reported similar problem on the chatterbot git repo yesterday, hoping someone might spot what is going on or replicate my problem.

my current platform: windows 10, have also seen this problem on ubuntu 16.04

checking the package versions
pip freeze | grep atter
ChatterBot==1.0.2
chatterbot-corpus==1.2.0

python app.py
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] C:\Users\Matthew\AppData\Roaming\nltk_data...
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\Matthew\AppData\Roaming\nltk_data...
[nltk_data] Package punkt is already up-to-date!
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\Matthew\AppData\Roaming\nltk_data...
[nltk_data] Package stopwords is already up-to-date!
Traceback (most recent call last):
File "app.py", line 9, in
english_bot.set_trainer(ChatterBotCorpusTrainer)
AttributeError: 'ChatBot' object has no attribute 'set_trainer'

Slow?

Hi,

Im seeing around 10-15 sec responsetime when using this as-is. Even with "simple" single-words, e.g. "Hi". Any idea why that is? Due to chatterbot simply being this slow or is it because its not trained...something else?

Thanks.

Add reactions to bot messages

Hello, I am working on a simple chatbot based on this code and I was wondering if anybody knows how to add reactions to the messages that the chatbot returns.
It could be as simple as a thumbs up and thumbs down.

Thanks!

ModuleNotFoundError: No module named 'spacy'

I copied app.py and all the other code.
I copied requirements.txt

I ran this: pip install -r requirements.txt

When I run app.py I get: ModuleNotFoundError: No module named 'spacy'

I tried:

pip install spacy
python -m spacy download en_core_web_sm

That made no difference. It seems odd I should have this issue and no-one else has reported it.

Application error on heroku

When I deployed flask chatterbot app to heroku it was working fine then after some time an application error came.

/get 404

This is probably something to do with flask but

Your build works great for me on my local machine, but after moving it to my apache server, the "/get" route is 404'ing.

I'm not sure if it's flask not serving /get or chatterbot not having an answer! Do you have any advice? Thanks!

Available for customization?

Hi!

Is this something that would interest you (Flask, chatterbot, aws, etc)? If so, I would love to discuss further.

[email removed]

Very slow response time in PythonAnywhere

Hi Guys,

I am a beginner flask enthusiast.

This flask sample of chatterbot implementation is great! Thanks @chamkank for the great work!

On the other hand, I am just curious if anyone of you has experienced some issue around slow response time when deploying to PythonAnywhere. Locally, a simple 'Hi' will get a response of ~140 ms while the same 'Hi' will get a response of up to 20 seconds in PythonAnywhere. Using the same code and the same default corpus(ie. greetings).

BTW, I promoted it as lowest paid account http://www.chatbotfactory.com.au/ and the code is in here https://github.com/codesydney/chatr. =)

Regards,
Engramar

Widget to the chatbot

Can't we give a widget to this chatbot instead of a full-screen chatbot, something like a small bot on the bottom right and when we open that and pops up to chat in it? If yes how do we do it?

I'm getting an error on deployment

I'm trying to deploy my bot in pythonanywhere following this video by @chamkank
followed every step shown in the video.
On installing requirements i get the following error logs

Error logs
Collecting ruamel.yaml<=0.15 Downloading ruamel.yaml-0.15.0.tar.gz (247 kB) |████████████████████████████████| 247 kB 266 kB/s ERROR: Command errored out with exit status 1: command: /usr/local/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-tqok7 5ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/setup.py'"'"'; __file__='"'"'/tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202a e74479b5eaca6954a11404/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io .StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exe c(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-h6oggpb_ cwd: /tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/ Complete output (11 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/setup.py", line 171, in <module> pkg_data = _package_data(__file__.replace('setup.py', '__init__.py')) File "/tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/setup.py", line 150, in _package_data data = literal_eval(u''.join(lines)) File "/tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/setup.py", line 122, in literal_eval return _convert(node_or_string) File "/tmp/pip-install-tqok75ch/ruamel-yaml_c767c7202ae74479b5eaca6954a11404/setup.py", line 69, in _convert if isinstance(node, (Str, Bytes)): NameError: name 'Str' is not defined

Chatterbot not answer...

Hi... the chatterbot not answer...

I uses this...

Chatterbot 1.0.8
Flask 1.1.2

The app

`from flask import Flask, render_template, request
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

app = Flask(name, template_folder="templates")

chatbot = ChatBot('Toni')

Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)

Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.english")

Train the chatbot based on the spanish corpus
trainer.train("chatterbot.corpus.spanish")

@app.route('/')
def home():
return render_template('home.html')

@app.route("/get")
def get_bot_response():
userText = request.args.get('msg')
return str(bot.get_response(userText))

if name == "main":
from waitress import serve
serve(app, host="0.0.0.0", port=8080)
(I don't know if waitress is ok... I am músican no programer)

The html is there
``

``

<title>ChatBot</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
  body {
    font-family: monospace;
    color: #fff;
  }
  h1 {
    display: inline-block;
    font-size: 3em;
    margin: 0;
    padding: 14px;
  }
  h3 {
    color: black;
    font-size: 20px;
    margin-top: 3px;
    text-align: center;
  }
  #chatbox {
    margin-left: auto;
    margin-right: auto;
    width: 40%;
    margin-top: 60px;
  }
  #userInput {
    margin-left: auto;
    margin-right: auto;
    width: 40%;
    margin-top: 70px;
  }
  #textInput {
    width:40%;
    border: none;
    border-bottom: 5px solid #00cc99;
    font-family: monospace;
    font-size: 17px;
  }
  .userText {
    color: white;
    font-family: monospace;
    font-size: 17px;
    text-align: right;
    line-height: 30px;
  }
  .userText span {
    background-color: #4169e1;
    padding: 10px;
    border-radius: 2px;
  }
  .botText {
    color: white;
    font-family: monospace;
    font-size: 17px;
    text-align: left;
    line-height: 30px;
  }
  .botText span {
    background-color: #a4c639;
    padding: 10px;
    border-radius: 2px;
  }
  #tidbit {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 300px;
  }
  .boxed {
    margin-left: auto;
    margin-right: auto;
    width: 78%;
    margin-top: 60px;
    border: 1px solid #00cc99;
  }
  .box {
    border: 2px solid #00cc99;
  }
</style>

Welcome to my ChatBot

Hello! My name is Bob. Your personal chatbot!

bob

Hi! Nice to meet you!

  <script>
  function getBotResponse() {
    var rawText = $("#textInput").val();
    var userHtml = '<p class="userText"><span>' + rawText + "</span></p>";
    $("#textInput").val("");
    $("#chatbox").append(userHtml);
    document
        .getElementById("userInput")
        .scrollIntoView({ block: "start", behavior: "smooth" });
    $.get("/get", { msg: rawText }).done(function (data) {
        var botHtml = '<p class="botText"><span>' + data + "</span></p>";
        $("#chatbox").append(botHtml);
        document
            .getElementById("userInput")
            .scrollIntoView({ block: "start", behavior: "smooth" });
    });
}
$("#textInput").keypress(function (e) {
    if (e.which == 13) {
        getBotResponse();
    }
});
    </script>

</div>
``

Thanks for help me.

PythonAnywhere issue

I have deployed this in pythonAnywhere following the youtube video and it worked. But, when I tried to deploy after adding my own training dataset, it did not work. I have uploaded my dataset in a text file in the mybot folder and also uploaded the db.sqlite3 file in the same folder.It works fine on local host. Would you please help how I can deploy the app with my own dataset?

column text is not unique

I deployed to heroku with Procfile:

web:gunicorn app:chamkank

And just change this example from app.py to chamkank.py

After build success, start to launch gunicorn got following issues.

sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) column text is not unique [SQL: 'INSERT INTO "StatementTable" (text, extra_data) VALUES (?, ?)'] [parameters: ('Artificial Intelligence is the branch of engineering and science devoted to constructing machines that think.', <memory at 0x7f30d0599048>)]

Heroku

Hi!
I deployed the app on Heroku.
I succeed in running it from terminal and heroku's console, but I cannot open it in the web browser using the app URL.
In the Procfile I wrote
web: python app.py runserver 0.0.0.0:5000

Thank you for you time and best wishes for your future projects

ModuleNotFoundError: No module named 'chatterbot'

Not able to execute the app.py. Installed all the packages as per the requirement.txt. Throwing this error. This

Traceback (most recent call last): File "app.py", line 2, in <module> from chatterbot import ChatBot ModuleNotFoundError: No module named 'chatterbot'

What is the correct version of ChatBot should we use for this app?

deploying with python anywhere

@chamkank when I try to execute app.py with python anywhere I get the below error

dbapi_connection.execute('PRAGMA journal_mode=WAL')
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) cannot change into wal mode from within a transaction (Background on this error at: ht
tp://sqlalche.me/e/e3q8)

How can I make it run in web browser of another system

I am new to chatterbot with flask
and running flask applications
I executed the app.py on my system , it works fine
the app is running on a given URL
but I want to make it execute on other systems web browser too
How can I do it?
Please help
Thank you
@chamkank

Not able to edit the css or html file

The changes made in the css or html file is not reflected on the website after deployment.
It is showing as debugger mode:off. Please, help me with some solution.

UnsupportedOperation: not writable

May I know why the error occurred? Data have been trained but it failed as last with this error.

File "C:\Users\Daniel\Anaconda3\envs\tensorflow\lib\site-packages\click\utils.py", line 259, in echo
file.write(message)

UnsupportedOperation: not writable

Thank you.

I can't deploy it into heroku

Hello;
I took your script, and I replace by the MangoDB as described.
of course I have created a mongo DB Data base in (mLab).
But when I deploy the app into heroku, it dosen't work
the error I got is:
english_bot.train("chatterbot.corpus.english")
AttributeError: 'NoneType' object has no attribute 'add extra file'

how could I deploy it pliz?

Thaks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.