-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_UI.py
94 lines (79 loc) · 2.3 KB
/
app_UI.py
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
## App with frontend UI using flasgger API
from flask import Flask,request
import pandas as pd
#import numpy as np
import pickle
import flasgger
from flasgger import Swagger
## creating app
app =Flask(__name__)
Swagger(app)
## classifier file
pickle_file = open("RF_Classifier.pkl",'rb')
classifier = pickle.load(pickle_file)
## creating routes
@app.route("/")
def hello():
return "Hello ady"
## fucntion for predcition --> we need four features according to our model
@app.route('/predict' , methods = ['GET'])
def predict_note():
#below lines are for swagger API's UI
"""Authenticate the Banks Note .
Enter the parameters below
---
parameters:
- name: Variance
in: query
type: number
required: true
- name: Skewness
in: query
type: number
required: true
- name: Curtosis
in: query
type: number
required: true
- name: Entropy
in: query
type: number
required: true
responses:
200:
description: Output value
"""
var = request.args.get('Variance')
skew = request.args.get('Skewness')
curt = request.args.get('Curtosis')
ent = request.args.get('Entropy')
pred = classifier.predict([[var , skew , curt , ent]])
output = "The predciton value for given bank note details : " + str(pred) + "."
return output
## sample GET data :
# ?Variance=5.1321&Skewness=-0.031048&Curtosis=0.32616&Entropy=1.11510 -> Test data : ans = 0
# ?Variance=-1.2943&Skewness=2.6735&Curtosis=-0.84085&Entropy=-2.03230 -> train data : ans = 1
#
@app.route('/predict_file' , methods = ['POST'])
def predict_note_file():
#below lines are for swagger API's UI
"""Authenticate the Banks Note .
Upload the CSV file here
---
parameters:
- name: file
in: formData
type: file
required: true
responses:
200:
description: Output values
"""
file_name = request.files.get("file") ## file variable will get csv file
df_test = pd.read_csv(file_name)
pred = classifier.predict(df_test)
output = "The predciton value for given bank note in a csv file : " + str(list(pred)) + "."
return output
## running app
if __name__== "__main__":
app.run()