File size: 3,306 Bytes
030fb97
 
 
9535a73
 
030fb97
 
 
9535a73
 
 
030fb97
 
 
 
 
 
 
 
 
 
 
 
 
9535a73
 
030fb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9535a73
030fb97
9535a73
 
030fb97
 
 
 
9535a73
030fb97
9535a73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
030fb97
9535a73
 
 
 
 
030fb97
9535a73
030fb97
 
 
9535a73
 
 
 
 
 
 
 
 
 
 
030fb97
9535a73
 
 
030fb97
9535a73
030fb97
9535a73
030fb97
 
9535a73
 
030fb97
 
 
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
from flask import  Flask
from flask import request
import numpy as np
import pickle
import pandas as pd
import flasgger
from flasgger import Swagger
from flasgger import Swagger, LazyString, LazyJSONEncoder, swag_from



application=Flask(__name__)        # debut de l'app


# pas tres import: habillage det affivhage
application.json_encoder = LazyJSONEncoder

swagger_template = dict(
                      info = {
                          'title': LazyString(lambda: "Modèle d'authentification de billets de banque"),
                          'description': LazyString(lambda: " Les informations statistiques extraites nous permettra de savoir si les billets sont authentiques"),
                             },
                      host = LazyString(lambda: request.host)
                      )

swagger_config = {
                      "headers": [],
                      "specs": [
                          {
                              "endpoint": '',
                              "route": '/',
                              "rule_filter": lambda rule: True,
                              "model_filter": lambda tag: True,
                          }
                      ],
                      "static_url_path": "/flasgger_static",
                      "swagger_ui": True,
                      "specs_route": "/apidocs/"
                      
                  }

swagger= Swagger(application, template=swagger_template, config=swagger_config)
# Swagger(application)

# chargement du modèle
modele=pickle.load(open("model.pkl","rb"))

@application.route('/')
def welcome():
    return "Bienvenu dans le site d'authentification"





@application.route('/predict',methods=["Get"])
def predict_note_authentication():
    
    """Let's Authenticate the Banks Note 
    This is using docstrings for specifications.
    ---
    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 values
        
    """
    variance = request.args.get("variance")
    skewness = request.args.get("skewness")
    curtosis = request.args.get("curtosis")
    entropy = request.args.get("entropy")
    prediction = modele.predict([[variance, skewness, curtosis, entropy]])
    print(prediction)
    return "Alors vraissemblablement la réponse est "+str(prediction)

@application.route('/predict_file',methods=["POST"])


def predict_note_file():
    """Let's Authenticate the Banks Note 
    This is using docstrings for specifications.
    ---
    parameters:
      - name: file
        in: formData
        type: file
        required: true
      
    responses:
        200:
            description: The output values
        
    """
    df_test=pd.read_csv(request.files.get("file"))
    print(df_test.head())
    prediction=modele.predict(df_test)
    
    return str(list(prediction))

if __name__=='__main__':               #  si 1 est exécuté alors l'application (codé en bas) sera mis en exécution
    application.run()