Salif SAWADOGO commited on
Commit
d5f9739
·
1 Parent(s): aed1bf0

EXPOOSE APP on 7860

Browse files
Files changed (1) hide show
  1. main.py +44 -61
main.py CHANGED
@@ -1,61 +1,50 @@
1
- from flask import Flask
2
- from flask import request
3
- import numpy as np
4
  import pickle
5
  import pandas as pd
6
- import flasgger
7
- from flasgger import Swagger
8
- from flasgger import Swagger, LazyString, LazyJSONEncoder, swag_from
9
 
 
10
 
 
 
11
 
12
- application=Flask(__name__) # debut de l'app
13
-
14
-
15
- # pas tres import: habillage det affivhage
16
- application.json_encoder = LazyJSONEncoder
17
-
18
- swagger_template = dict(
19
- info = {
20
- 'title': LazyString(lambda: "Modèle d'authentification de billets de banque"),
21
- 'description': LazyString(lambda: " Les informations statistiques extraites nous permettra de savoir si les billets sont authentiques"),
22
- },
23
- host = LazyString(lambda: request.host)
24
- )
25
 
26
  swagger_config = {
27
- "headers": [],
28
- "specs": [
29
- {
30
- "endpoint": '',
31
- "route": '/',
32
- "rule_filter": lambda rule: True,
33
- "model_filter": lambda tag: True,
34
- }
35
- ],
36
- "static_url_path": "/flasgger_static",
37
- "swagger_ui": True,
38
- "specs_route": "/apidocs/"
39
-
40
- }
41
-
42
- swagger= Swagger(application, template=swagger_template, config=swagger_config)
43
- # Swagger(application)
44
-
45
- # chargement du modèle
46
- modele=pickle.load(open("model.pkl","rb"))
47
-
48
- @application.route('/')
49
  def welcome():
50
- return "Bienvenu dans le site d'authentification"
51
 
52
 
53
-
54
-
55
-
56
- @application.route('/predict',methods=["Get"])
57
  def predict_note_authentication():
58
-
59
  """Let's Authenticate the Banks Note
60
  This is using docstrings for specifications.
61
  ---
@@ -79,19 +68,17 @@ def predict_note_authentication():
79
  responses:
80
  200:
81
  description: The output values
82
-
83
  """
84
  variance = request.args.get("variance")
85
  skewness = request.args.get("skewness")
86
  curtosis = request.args.get("curtosis")
87
  entropy = request.args.get("entropy")
88
- prediction = modele.predict([[variance, skewness, curtosis, entropy]])
89
  print(prediction)
90
- return "Alors vraissemblablement la réponse est "+str(prediction)
91
-
92
- @application.route('/predict_file',methods=["POST"])
93
 
94
 
 
95
  def predict_note_file():
96
  """Let's Authenticate the Banks Note
97
  This is using docstrings for specifications.
@@ -101,19 +88,15 @@ def predict_note_file():
101
  in: formData
102
  type: file
103
  required: true
104
-
105
  responses:
106
  200:
107
  description: The output values
108
-
109
  """
110
- df_test=pd.read_csv(request.files.get("file"))
111
  print(df_test.head())
112
- prediction=modele.predict(df_test)
113
-
114
  return str(list(prediction))
115
 
116
- if __name__=='__main__': # si 1 est exécuté alors l'application (codé en bas) sera mis en exécution
117
- application.run()
118
-
119
-
 
1
+ from flask import Flask, request
 
 
2
  import pickle
3
  import pandas as pd
4
+ from flasgger import Swagger, LazyString, LazyJSONEncoder
 
 
5
 
6
+ app = Flask(__name__) # Rename 'application' to 'app' for brevity
7
 
8
+ # Set JSON encoder for the app
9
+ app.json_encoder = LazyJSONEncoder
10
 
11
+ # Swagger configuration
12
+ swagger_template = {
13
+ 'info': {
14
+ 'title': LazyString(lambda: "Modèle d'authentification de billets de banque"),
15
+ 'description': LazyString(lambda: " Les informations statistiques extraites nous permettra de savoir si les billets sont authentiques"),
16
+ },
17
+ 'host': LazyString(lambda: request.host)
18
+ }
 
 
 
 
 
19
 
20
  swagger_config = {
21
+ "headers": [],
22
+ "specs": [
23
+ {
24
+ "endpoint": '',
25
+ "route": '/',
26
+ "rule_filter": lambda rule: True,
27
+ "model_filter": lambda tag: True,
28
+ }
29
+ ],
30
+ "static_url_path": "/flasgger_static",
31
+ "swagger_ui": True,
32
+ "specs_route": "/apidocs/"
33
+ }
34
+
35
+ swagger = Swagger(app, template=swagger_template, config=swagger_config)
36
+
37
+ # Load the model
38
+ model = pickle.load(open("model.pkl", "rb"))
39
+
40
+
41
+ @app.route('/')
 
42
  def welcome():
43
+ return "Bienvenue dans le site d'authentification"
44
 
45
 
46
+ @app.route('/predict', methods=["GET"])
 
 
 
47
  def predict_note_authentication():
 
48
  """Let's Authenticate the Banks Note
49
  This is using docstrings for specifications.
50
  ---
 
68
  responses:
69
  200:
70
  description: The output values
 
71
  """
72
  variance = request.args.get("variance")
73
  skewness = request.args.get("skewness")
74
  curtosis = request.args.get("curtosis")
75
  entropy = request.args.get("entropy")
76
+ prediction = model.predict([[variance, skewness, curtosis, entropy]])
77
  print(prediction)
78
+ return "Alors vraissemblablement la réponse est " + str(prediction)
 
 
79
 
80
 
81
+ @app.route('/predict_file', methods=["POST"])
82
  def predict_note_file():
83
  """Let's Authenticate the Banks Note
84
  This is using docstrings for specifications.
 
88
  in: formData
89
  type: file
90
  required: true
 
91
  responses:
92
  200:
93
  description: The output values
 
94
  """
95
+ df_test = pd.read_csv(request.files.get("file"))
96
  print(df_test.head())
97
+ prediction = model.predict(df_test)
 
98
  return str(list(prediction))
99
 
100
+
101
+ if __name__ == '__main__':
102
+ app.run(port=7860)