WaiYanLynn commited on
Commit
7562203
1 Parent(s): 507e4de

Upload 10 files

Browse files
src/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask
2
+ from flask_cors import CORS
3
+ from src.router.routes import api
4
+
5
+ app = Flask(__name__, template_folder="./templates")
6
+ app.secret_key = "oOUP0oHOQKHnmZHbXT8IxQ99Ml4Q2ZMv"
7
+ cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
8
+
9
+ app.register_blueprint(api, url_prefix="/api")
10
+
11
+ def create_app():
12
+ return app
src/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (832 Bytes). View file
 
src/controllers/__init__.py ADDED
File without changes
src/controllers/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (170 Bytes). View file
 
src/controllers/__pycache__/predict_controller.cpython-311.pyc ADDED
Binary file (2.41 kB). View file
 
src/controllers/predict_controller.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import request, jsonify, Blueprint
2
+ import numpy as np
3
+ from deepface import DeepFace
4
+ from PIL import Image
5
+ import pprint
6
+
7
+ DeepFace.analyze(
8
+ detector_backend='fastmtcnn',
9
+ img_path='./download.jpeg', actions=["emotion"])
10
+
11
+
12
+ predicts = Blueprint("predicts", __name__)
13
+
14
+ ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg"}
15
+
16
+
17
+ def allowed_file(filename):
18
+ return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
19
+
20
+
21
+ @predicts.route("/", methods=["POST"], strict_slashes=False)
22
+ def upload_file():
23
+ print('predicting')
24
+ try:
25
+ if "file" not in request.files:
26
+ raise ValueError("File not found in the request.")
27
+
28
+ file = request.files["file"]
29
+
30
+ if file.filename == "":
31
+ raise ValueError("Empty filename in the request.")
32
+
33
+ if file and allowed_file(file.filename):
34
+ objs = DeepFace.analyze(
35
+ detector_backend='fastmtcnn',
36
+ img_path=np.array(Image.open(file)), actions=["emotion"]
37
+ )
38
+
39
+ # pprint.pp(objs)
40
+ return jsonify(objs), 200
41
+ else:
42
+ raise ValueError("Invalid file type.")
43
+
44
+ except Exception as e:
45
+ print(e)
46
+ return f"Error processing file: {str(e)}", 500
src/router/__init__.py ADDED
File without changes
src/router/__pycache__/__init__.cpython-311.pyc ADDED
Binary file (165 Bytes). View file
 
src/router/__pycache__/routes.cpython-311.pyc ADDED
Binary file (476 Bytes). View file
 
src/router/routes.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ from flask import Blueprint
2
+ from src.controllers.predict_controller import predicts
3
+
4
+ api = Blueprint("api", __name__)
5
+ api.register_blueprint(predicts, url_prefix="/predicts")