diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..fc43fb6 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..c571730 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# flask-chatterbot + +#### A web implementation of [ChatterBot](https://github.com/gunthercox/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* + 3. Demo will be live at [http://localhost:5000/](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](https://www.pythonanywhere.com/), [AWS](https://aws.amazon.com/getting-started/projects/deploy-python-application/) or [Heroku](https://devcenter.heroku.com/articles/getting-started-with-python#introduction) to host your application. + +### Deploying on PythonAnywhere +Here is a quick 5 minute video on how to get setup: https://youtu.be/VP0HvbunaRo + +### 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](https://github.com/gunthercox/ChatterBot/blob/master/LICENSE) page. diff --git a/app.py b/app.py new file mode 100644 index 0000000..7c9a374 --- /dev/null +++ b/app.py @@ -0,0 +1,26 @@ +from flask import Flask, render_template, request +from chatterbot import ChatBot +from chatterbot.trainers import ChatterBotCorpusTrainer + +app = Flask(__name__) + +english_bot = ChatBot("Chatterbot", storage_adapter="chatterbot.storage.SQLStorageAdapter") + +# english_bot.set_trainer(ChatterBotCorpusTrainer) +# english_bot.train("chatterbot.corpus.english") + + +@app.route("/") +def home(): + return render_template("chat.html") + +@app.route("/get") +def get_bot_response(): + userText = request.args.get('messageText') + print(request.args) + print(userText) + return str(english_bot.get_response(userText)) + + +if __name__ == "__main__": + app.run() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..b5bdbb5 Binary files /dev/null and b/db.sqlite3 differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..be67bb1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +# Used by pip to install required python packages +# Usage: pip install -r requirements.txt + +Flask>=0.11 +chatterbot>=0.7.1 +SQLAlchemy>=1.1.11 \ No newline at end of file diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..20c1658 --- /dev/null +++ b/static/style.css @@ -0,0 +1,81 @@ +body { + font-family: Garamond; +} + +h1 { + color: black; + margin-bottom: 0; + margin-top: 0; + text-align: center; + font-size: 40px; +} + +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: 60px; +} + +#textInput { + width: 87%; + border: none; + border-bottom: 3px solid #009688; + font-family: monospace; + font-size: 17px; +} + +#buttonInput { + padding: 3px; + 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: #009688; + padding: 10px; + border-radius: 2px; +} + +.botText { + color: white; + font-family: monospace; + font-size: 17px; + text-align: left; + line-height: 30px; +} + +.botText span { + background-color: #EF5350; + padding: 10px; + border-radius: 2px; +} + +#tidbit { + position:absolute; + bottom:0; + right:0; + width: 300px; +} \ No newline at end of file diff --git a/templates/chat.html b/templates/chat.html new file mode 100755 index 0000000..4a22157 --- /dev/null +++ b/templates/chat.html @@ -0,0 +1,135 @@ + + + + + + Chatbot + + + + + + +
+ +
+

紫鵑 岂曰无衣? 与子 同袍..

+ +
+ +
+
+ + 同我讲话吧。 + +
+
+
    +
+
+ +
+
+ +
+
+ + + + + + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f35e945 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,42 @@ + + + + + + + +

Shopping Assistant

+

Intelligent guidance to your desired shopping item through conversion

+
+
+

吖!

+
+
+ + +
+ +
+ + \ No newline at end of file