Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Analysis of Chatbot and Produce a Predictable reason and feedback code
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-298
Analysis of Chatbot and Produce a Predictable reason and feedback code
Commits
08cd85da
Commit
08cd85da
authored
Oct 08, 2022
by
Karagoda Gamage Pasan Malaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
aa2a87e7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
api.py
api.py
+70
-0
No files found.
api.py
0 → 100644
View file @
08cd85da
from
flask
import
Flask
,
render_template
,
Response
,
request
from
flask_cors
import
CORS
import
requests
as
r
import
pickle
import
numpy
as
np
import
pandas
as
pd
from
sklearn.preprocessing
import
LabelEncoder
app
=
Flask
(
__name__
)
CORS
(
app
)
lr_model
=
pickle
.
load
(
open
(
'trained_models/finalized_model_lr.sav'
,
'rb'
))
final_result_list
=
[
0
,
0
,
0
,
0
,
0
]
@
app
.
route
(
'/'
)
def
home
():
return
render_template
(
'index.html'
)
@
app
.
route
(
'/classification'
,
methods
=
[
'POST'
])
def
classification
():
global
emotion_data
question_no
=
request
.
form
[
'question_no'
]
answer
=
request
.
form
[
'answer'
]
emotion
=
request
.
form
[
'emotion'
]
add_status
=
request
.
form
[
'add_status'
]
features
=
data_preprocessing
([
question_no
,
answer
,
emotion
])
print
(
features
)
prediction
=
lr_model
.
predict
(
features
)
if
prediction
[
0
]
==
1
:
final_result_list
[
0
]
+=
1
elif
prediction
[
0
]
==
2
:
final_result_list
[
1
]
+=
1
elif
prediction
[
0
]
==
3
:
final_result_list
[
2
]
+=
1
elif
prediction
[
0
]
==
4
:
final_result_list
[
3
]
+=
1
else
:
final_result_list
[
4
]
+=
1
if
add_status
==
'add'
:
return
render_template
(
'index.html'
)
else
:
return
render_template
(
'result_2.html'
,
data
=
final_result_list
)
def
data_preprocessing
(
data
):
df
=
pd
.
read_csv
(
'data/reason_data_up.csv'
)
# df.loc[len(df.index)] = data
df
.
append
(
pd
.
Series
(
data
,
index
=
df
.
columns
[:
len
(
data
)]),
ignore_index
=
True
)
df
[
'question no'
]
=
df
[
'question no'
]
.
astype
(
'str'
)
df
[
'answer'
]
=
df
[
'answer'
]
.
astype
(
'str'
)
df
[
'emotion'
]
=
df
[
'emotion'
]
.
astype
(
'str'
)
df
[[
'question no'
,
'answer'
,
'emotion'
]]
=
df
[[
'question no'
,
'answer'
,
'emotion'
]]
.
apply
(
LabelEncoder
()
.
fit_transform
)
X_var
=
np
.
asarray
(
df
[[
'question no'
,
'answer'
,
'emotion'
]])
return
[
X_var
[
-
1
]]
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment