-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_with_flasgger.py
executable file
·106 lines (85 loc) · 2.42 KB
/
api_with_flasgger.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
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 12 15:27:57 2021
@author: sharad
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 12 12:53:29 2021
@author: sharad
File for testing Docker and Falsk
Creating a frontend using Flasgger
"""
from flask import Flask,request
import pandas as pd
import numpy as np
import pickle
import flasgger
from flasgger import Swagger
app=Flask(__name__)
Swagger(app)
pickle_in=open('classifier.pkl','rb')
classifier=pickle.load(pickle_in)
#Entry page
@app.route('/')
def welcome():
return "Welcome to Flask API"
#To predict by getting input from user
# http://127.0.0.1:5000/predict?variance=0&skewness=-2&curtosis=-1&entropy=4
@app.route('/predict',methods=['GET'])
def predict():
"""Let's Authencita the Bank notes.
This is using docstring for specification.
We are using Flask for creating API, Flsagger for Frontend & Docker for contanerization
---
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: The Output value
"""
variance=request.args.get('variance')
skewness=request.args.get('skewness')
curtosis=request.args.get('curtosis')
entropy=request.args.get('entropy')
prediction=classifier.predict([[variance,skewness,curtosis,entropy]])
return "The predicted value is "+str(prediction)
#To predict by passing a file
#use postman
@app.route('/predict_file',methods=['POST'])
def predict_file():
"""Let's Authencita the Bank notes.
This is using docstring for specification.
We are using Flask for creating API, Flsagger for Frontend & Docker for contanerization
---
parameters:
- name: file
in: formData
type: file
required: true
responses:
200:
description: The Output values
"""
df_test=pd.read_csv(request.files.get("file"))
prediction=classifier.predict(df_test)
return "The Predicted values for the csv are "+str(list(prediction))
if __name__== '__main__':
app.run(host='0.0.0.0',port=8000)