Salif SAWADOGO commited on
Commit
030fb97
·
1 Parent(s): abb63f7
Files changed (6) hide show
  1. Dockerfile +2 -1
  2. hello_world.yml.bak → hello_world.yml +0 -0
  3. main.py +60 -44
  4. requirements.txt +1 -3
  5. test.py +14 -0
  6. test.txt +14 -0
Dockerfile CHANGED
@@ -2,5 +2,6 @@ FROM python:3.9
2
  COPY . /usr/app/
3
  WORKDIR /usr/app/
4
  RUN pip install --no-cache-dir -r requirements.txt
5
- CMD ["gunicorn", "--bind", "0.0.0.0:7860", "main:app"]
 
6
 
 
2
  COPY . /usr/app/
3
  WORKDIR /usr/app/
4
  RUN pip install --no-cache-dir -r requirements.txt
5
+ ENTRYPOINT ["gunicorn", "main:application", "-b", "0.0.0.0:7860", "--workers=1"]
6
+
7
 
hello_world.yml.bak → hello_world.yml RENAMED
File without changes
main.py CHANGED
@@ -1,50 +1,61 @@
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,17 +79,19 @@ def predict_note_authentication():
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,15 +101,18 @@ def predict_note_file():
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(host='0.0.0.0', port=7860)
 
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
  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
  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
+
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  Flask==1.1.1
2
- uvicorn[standard]==0.17.*
3
  gunicorn==19.9.0
4
  itsdangerous==1.1.0
5
  Jinja2==2.10.1
@@ -11,7 +10,6 @@ scikit-learn
11
  matplotlib>=1.4.3
12
  pandas>=0.19
13
  flasgger==0.9.4
14
- streamlit
15
- uvicorn[standard]==0.17
16
 
17
 
 
1
  Flask==1.1.1
 
2
  gunicorn==19.9.0
3
  itsdangerous==1.1.0
4
  Jinja2==2.10.1
 
10
  matplotlib>=1.4.3
11
  pandas>=0.19
12
  flasgger==0.9.4
13
+ #uvicorn[standard]==0.17
 
14
 
15
 
test.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask
2
+
3
+ app = Flask(__name__)
4
+
5
+ @app.route('/')
6
+ def home():
7
+ return 'Hello, this is the homepage!'
8
+
9
+ @app.route('/hello')
10
+ def hello():
11
+ return 'Hello from the custom route "/hello"!'
12
+
13
+ if __name__ == '__main__':
14
+ app.run(host='0.0.0.0', port=5000)
test.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask
2
+
3
+ app = Flask(__name__)
4
+
5
+ @app.route('/')
6
+ def home():
7
+ return 'Hello, this is the homepage!'
8
+
9
+ @app.route('/hello')
10
+ def hello():
11
+ return 'Hello from the custom route "/hello"!'
12
+
13
+ if __name__ == '__main__':
14
+ app.run(host='0.0.0.0', port=5000)