devopsrobo commited on
Commit
8d198a3
·
verified ·
1 Parent(s): 73365d3

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +32 -12
  2. main-raw.py +21 -0
  3. main.py +35 -0
  4. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,32 @@
1
- ---
2
- title: Gptbot
3
- emoji: 🏃
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 4.38.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Chatbot
2
+ AI Based Chatbot
3
+
4
+ ### Requirements
5
+ Python = 2.x.x
6
+ Flask
7
+ Aiml
8
+ pip
9
+
10
+ ## Installation
11
+
12
+ 1. Clone and navigate to chatbot directory.
13
+
14
+ 2. Install the required packages.
15
+ ```bash
16
+ pip install -r requirements.txt
17
+ ```
18
+
19
+ 3. Run the python server.
20
+ ```bash
21
+ python main.py
22
+ ```
23
+ 4. Open **http://127.0.0.1:5000** in your browser.
24
+
25
+ 5. You're done and let's chat with your Robot via browser.
26
+
27
+ ## Screenshot
28
+ ![chatbot](https://user-images.githubusercontent.com/1708683/27002771-68618802-4e0b-11e7-870a-3c05e3f68146.png)
29
+
30
+ ## Author
31
+
32
+ [Sohel Amin](http://www.sohelamin.com)
main-raw.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import aiml
2
+ import os
3
+
4
+ kernel = aiml.Kernel()
5
+
6
+ if os.path.isfile("bot_brain.brn"):
7
+ kernel.bootstrap(brainFile = "bot_brain.brn")
8
+ else:
9
+ kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
10
+ kernel.saveBrain("bot_brain.brn")
11
+
12
+ # kernel now ready for use
13
+ while True:
14
+ message = raw_input("Enter your message to the bot: ")
15
+ if message == "quit":
16
+ exit()
17
+ elif message == "save":
18
+ kernel.saveBrain("bot_brain.brn")
19
+ else:
20
+ bot_response = kernel.respond(message)
21
+ print bot_response
main.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import aiml
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route("/")
8
+ def hello():
9
+ return render_template('chat.html')
10
+
11
+ @app.route("/ask", methods=['POST'])
12
+ def ask():
13
+ message = request.form['messageText'].encode('utf-8').strip()
14
+
15
+ kernel = aiml.Kernel()
16
+
17
+ if os.path.isfile("bot_brain.brn"):
18
+ kernel.bootstrap(brainFile = "bot_brain.brn")
19
+ else:
20
+ kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
21
+ kernel.saveBrain("bot_brain.brn")
22
+
23
+ # kernel now ready for use
24
+ while True:
25
+ if message == "quit":
26
+ exit()
27
+ elif message == "save":
28
+ kernel.saveBrain("bot_brain.brn")
29
+ else:
30
+ bot_response = kernel.respond(message)
31
+ # print bot_response
32
+ return jsonify({'status':'OK','answer':bot_response})
33
+
34
+ if __name__ == "__main__":
35
+ app.run(host='0.0.0.0', debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask>=0.12.3
2
+ aiml==0.8.6