├── requirements.txt
├── .gitattributes
├── pics
└── medical_bot.jpg
├── README.md
├── aiml
├── cn-startup.xml
├── cn-medical.aiml
└── cn-test.aiml
├── main.py
├── .gitignore
└── templates
├── .ipynb_checkpoints
└── chat-checkpoint.html
└── chat.html
/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==0.12
2 | aiml==0.8.6
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.html linguist-language=Python
--------------------------------------------------------------------------------
/pics/medical_bot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crownpku/aiml_chatbot/HEAD/pics/medical_bot.jpg
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chatbot
2 | AIML Based Chatbot
3 |
4 | This repository can help you build a simple rule-based chatbot with web front-end.
5 |
6 | 
7 |
8 |
9 | *需要安装支持中文的pyaiml包:
10 | https://github.com/andelf/PyAIML
11 |
12 |
13 |
--------------------------------------------------------------------------------
/aiml/cn-startup.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LOAD AIML CNASK
5 |
6 |
7 |
8 |
9 | aiml/cn-medical.aiml
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/aiml/cn-medical.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | *
16 |
17 | 请核对您的个人信息: 姓名:张三,年龄:31,性别:男,身份证号码:666666666666666666。您早上量血压了吗?
18 |
19 |
20 |
21 |
22 | 量了
23 |
24 | 请问收缩压多少?
25 |
26 |
27 |
28 |
29 | 收缩压*
30 |
31 | 请问舒张压多少?
32 |
33 |
34 |
35 |
36 | 舒张压*
37 |
38 | 我们已记录您的数据。您的血压依然偏高,请您继续坚持服药,若三日内血压没有恢复正常,请及时来我院就医!
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | #coding=utf-8
2 | from flask import Flask, render_template, request, jsonify
3 | import aiml
4 | import os
5 |
6 | app = Flask(__name__)
7 |
8 | @app.route("/")
9 | def hello():
10 | return render_template('chat.html')
11 |
12 | @app.route("/ask", methods=['POST'])
13 | def ask():
14 | message = str(request.form['messageText'].encode('utf-8'))
15 |
16 | kernel = aiml.Kernel()
17 |
18 | if os.path.isfile("bot_brain.brn"):
19 | kernel.bootstrap(brainFile = "bot_brain.brn")
20 | else:
21 | #kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
22 | kernel.learn("./aiml/cn-startup.xml")
23 | kernel.respond("load aiml cnask")
24 | kernel.saveBrain("bot_brain.brn")
25 |
26 | # kernel now ready for use
27 | while True:
28 | if message == "quit":
29 | exit()
30 | elif message == "save":
31 | kernel.saveBrain("bot_brain.brn")
32 | else:
33 | bot_response = kernel.respond(message.decode('utf8'))
34 | # print bot_response
35 | return jsonify({'status':'OK','answer':bot_response})
36 |
37 | if __name__ == "__main__":
38 | app.run(debug=True, host='10.127.1.178', port=15555)
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | env/
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 |
49 | # Translations
50 | *.mo
51 | *.pot
52 |
53 | # Django stuff:
54 | *.log
55 | local_settings.py
56 |
57 | # Flask stuff:
58 | instance/
59 | .webassets-cache
60 |
61 | # Scrapy stuff:
62 | .scrapy
63 |
64 | # Sphinx documentation
65 | docs/_build/
66 |
67 | # PyBuilder
68 | target/
69 |
70 | # Jupyter Notebook
71 | .ipynb_checkpoints
72 |
73 | # pyenv
74 | .python-version
75 |
76 | # celery beat schedule file
77 | celerybeat-schedule
78 |
79 | # SageMath parsed files
80 | *.sage.py
81 |
82 | # dotenv
83 | .env
84 |
85 | # virtualenv
86 | .venv
87 | venv/
88 | ENV/
89 |
90 | # Spyder project settings
91 | .spyderproject
92 | .spyproject
93 |
94 | # Rope project settings
95 | .ropeproject
96 |
97 | # mkdocs documentation
98 | /site
99 |
100 | # mypy
101 | .mypy_cache/
102 |
103 |
104 | #Models
105 | */model/
106 | */data/
107 |
--------------------------------------------------------------------------------
/aiml/cn-test.aiml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 现在几点了
15 |
16 | TIME
17 |
18 |
19 |
20 |
21 | 几点了
22 |
23 | TIME
24 |
25 |
26 |
27 |
28 | TIME
29 |
30 | date
31 |
32 |
33 |
34 |
35 | *
36 |
37 |
38 | 你现在在什么地方?
39 | 我暂时不会说别的了.
40 |
41 |
42 |
43 |
44 |
45 | *
46 | 你现在在什么地方
47 |
48 |
49 |
50 | 是个好地方.
51 | 真希望我也在, 陪你.
52 | 我刚刚看了下的天气哦.
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 外面热么
61 |
62 | 你现在在,
63 | python getweather.py realtime
64 |
65 |
66 |
67 |
68 | 我到*了
69 |
70 |
71 |
72 | 嗯我知道了.
73 | 骗淫, 你明明在.
74 |
75 |
76 |
77 |
78 |
79 | * 天气
80 |
81 | python getweather.py realtime
82 |
83 |
84 |
85 |
86 | 告诉我 * 天气
87 |
88 | python getweather.py realtime
89 |
90 |
91 |
92 |
93 | * 天气实况
94 |
95 | python getweather.py realtime
96 |
97 |
98 |
99 |
100 | * 当前天气
101 |
102 | python getweather.py realtime
103 |
104 |
105 |
106 |
107 | * 现在天气
108 |
109 | python getweather.py realtime
110 |
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/templates/.ipynb_checkpoints/chat-checkpoint.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Chatbot
7 |
8 |
9 |
10 |
64 |
65 |
66 |
67 |
68 |
69 |
智能医疗问诊系统
70 |
71 |
72 |
73 |
74 |
75 |
76 | 南京医院欢迎您!
77 |
78 |
79 |
83 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/templates/chat.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Chatbot
7 |
8 |
9 |
10 |
64 |
65 |
66 |
67 |
68 |
69 |
智能医疗问诊系统
70 |
71 |
72 |
73 |
74 |
75 |
76 | 上海人民医院欢迎您!
77 |
78 |
79 |
83 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
133 |
134 |
135 |
--------------------------------------------------------------------------------