-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
118 lines (102 loc) · 3.79 KB
/
chatbot.py
File metadata and controls
118 lines (102 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import pandas as pd
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/message', methods=['POST'])
def Message():
intent = request.get_json()
intent = intent['intent']['name']
content = request.get_json()
if intent == '키워드 검색':
content = content['action']['detailParams']['news_keyword']['value']
keyword = pd.read_csv("entity_keyword.csv")
keyword = keyword[keyword['entity'] == content]
keyword.reset_index(drop=True, inplace=True)
item = []
for i in range(len(keyword)):
item += [{
"title": keyword['title'][i],
"description": keyword['description'][i],
"thumbnail": {
"imageUrl": keyword['image'][i],
"link": {"web": keyword['link'][i]}
}
}]
dataSend = {
"version": "2.0",
"template": {
"outputs": [
{
"carousel": {
"type": "basicCard",
"items": item
}
}
]
}
}
elif intent == '브랜드 검색':
content = content['action']['detailParams']['news_brand']['value']
brand = pd.read_csv("entity_brand.csv")
brand = brand[brand['entity'] == content]
brand.reset_index(drop=True, inplace=True)
item = []
for i in range(len(brand)):
item += [{
"title": brand['title'][i],
"description": brand['description'][i],
"thumbnail": {
"imageUrl": brand['image'][i],
"link": {"web": brand['link'][i]}
}
}]
dataSend = {
"version": "2.0",
"template": {
"outputs": [
{
"carousel": {
"type": "basicCard",
"items": item
}
}
]
}
}
elif intent == '피드백 안내':
user = content['userRequest']['user']['id']
utter = content['action']['detailParams']['feedback']['value']
fdback = pd.DataFrame({'user': [user], 'utterance': [utter]})
fdback['user'][len(fdback)] = user
fdback['utterance'][len(fdback)] = utter
fdback.to_csv('feedback.csv', index=False, mode='a', encoding='utf-8', header=False)
dataSend = {
"version": "2.0",
"template": {
"outputs": [
{
"simpleText": '소중한 의견 감사해요!\n앞으로도 발전하는 왓츠뉴가 되겠습니다!'
}
]}
}
elif intent == '최신 뉴스':
brand = pd.read_csv("entity_brand.csv")
brand.reset_index(drop=True, inplace=True)
dataSend = {
"version": "2.0",
"template": {
"outputs": [
{
"basicCard": {
"title": brand['description'][0],
"thumbnail": {
"imageUrl": brand['image'][0],
"link": {"web": brand['link'][0]}
}
}
}
]
}
}
return jsonify(dataSend)
if __name__ == "__main__":
app.run(host='0.0.0.0')