-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswagger.py
79 lines (68 loc) · 1.83 KB
/
swagger.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
from flask import Flask, request
import pandas as pd
import numpy as np
import pickle
import flasgger
from flasgger import Swagger
# **********************
# Define the starting point for the flask app
app = Flask(__name__)
Swagger(app)
pickle_input = open("random_f.pkl", "rb")
classifier = pickle.load(pickle_input)
# homepage
@app.route("/")
def homePage():
return "Dr.Dre says hell yeah..."
@app.route("/predict")
def predict_forgery():
"""Here, you can predict a single input.
---
parameters:
- name: var
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: Forgery Status
"""
var = request.args.get("var")
skewness = request.args.get("skewness")
curtosis = request.args.get("curtosis")
entropy = request.args.get("entropy")
prediction = classifier.predict([[var, skewness, curtosis, entropy]])
output_map = {0: "Genuine", 1: "Forged"}
return f"The banknote is {output_map[prediction[0]]}"
@app.route("/predict_batches", methods=["POST"])
def predict_forgery_batches():
"""Here, you can predict batches.
---
parameters:
- name: file
in: formData
type: file
required: true
responses:
200:
description: Forgery Status
"""
df_test = pd.read_csv(request.files.get("file"))
output_map = {0: "Genuine", 1: "Forged"}
prediction = classifier.predict(df_test)
return f"The banknotes are {[output_map[i] for i in prediction]}"
# run the app
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)