Spaces:
Sleeping
Sleeping
Salif SAWADOGO
commited on
Commit
·
030fb97
1
Parent(s):
abb63f7
'test'
Browse files- Dockerfile +2 -1
- hello_world.yml.bak → hello_world.yml +0 -0
- main.py +60 -44
- requirements.txt +1 -3
- test.py +14 -0
- 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 |
-
|
|
|
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
|
|
|
|
|
2 |
import pickle
|
3 |
import pandas as pd
|
4 |
-
|
|
|
|
|
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 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
swagger_config = {
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
def welcome():
|
43 |
-
return "
|
44 |
|
45 |
|
46 |
-
|
|
|
|
|
|
|
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 =
|
77 |
print(prediction)
|
78 |
-
return "Alors vraissemblablement la réponse est "
|
|
|
|
|
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
|
96 |
print(df_test.head())
|
97 |
-
prediction
|
|
|
98 |
return str(list(prediction))
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
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 |
-
|
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)
|