Update app.py
Browse files
app.py
CHANGED
|
@@ -3,28 +3,25 @@ from PIL import Image
|
|
| 3 |
import io
|
| 4 |
import base64
|
| 5 |
import logging
|
|
|
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
| 8 |
|
| 9 |
# Dummy pose recognition function
|
| 10 |
def recognize_pose(image):
|
| 11 |
-
# Replace
|
| 12 |
-
pose = "warrior" #
|
| 13 |
return pose
|
| 14 |
|
| 15 |
-
# Endpoint to handle pose recognition requests
|
| 16 |
@app.route('/api/recognize_pose', methods=['POST'])
|
| 17 |
def api_recognize_pose():
|
| 18 |
try:
|
| 19 |
-
#
|
| 20 |
image_data = request.json['image'].split(",")[1]
|
| 21 |
image_bytes = base64.b64decode(image_data)
|
| 22 |
image = Image.open(io.BytesIO(image_bytes))
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
image.save('received_image.jpg')
|
| 26 |
-
|
| 27 |
-
# Preprocess the image and perform pose recognition
|
| 28 |
image = preprocess_image(image)
|
| 29 |
pose = recognize_pose(image)
|
| 30 |
return jsonify({'pose': pose})
|
|
@@ -35,11 +32,10 @@ def api_recognize_pose():
|
|
| 35 |
logging.error(f"Unexpected error: {e}")
|
| 36 |
return jsonify({'error': str(e)}), 500
|
| 37 |
|
| 38 |
-
# Function to preprocess the image
|
| 39 |
def preprocess_image(image):
|
| 40 |
-
#
|
| 41 |
-
image = image.resize((224, 224)) #
|
| 42 |
-
image = np.array(image) / 255.0 # Normalize
|
| 43 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 44 |
return image
|
| 45 |
|
|
|
|
| 3 |
import io
|
| 4 |
import base64
|
| 5 |
import logging
|
| 6 |
+
import numpy as np
|
| 7 |
|
| 8 |
app = Flask(__name__)
|
| 9 |
|
| 10 |
# Dummy pose recognition function
|
| 11 |
def recognize_pose(image):
|
| 12 |
+
# Replace with your model inference code
|
| 13 |
+
pose = "warrior" # Example dummy pose
|
| 14 |
return pose
|
| 15 |
|
|
|
|
| 16 |
@app.route('/api/recognize_pose', methods=['POST'])
|
| 17 |
def api_recognize_pose():
|
| 18 |
try:
|
| 19 |
+
# Decode the image from the request
|
| 20 |
image_data = request.json['image'].split(",")[1]
|
| 21 |
image_bytes = base64.b64decode(image_data)
|
| 22 |
image = Image.open(io.BytesIO(image_bytes))
|
| 23 |
+
|
| 24 |
+
# Preprocess and recognize pose
|
|
|
|
|
|
|
|
|
|
| 25 |
image = preprocess_image(image)
|
| 26 |
pose = recognize_pose(image)
|
| 27 |
return jsonify({'pose': pose})
|
|
|
|
| 32 |
logging.error(f"Unexpected error: {e}")
|
| 33 |
return jsonify({'error': str(e)}), 500
|
| 34 |
|
|
|
|
| 35 |
def preprocess_image(image):
|
| 36 |
+
# Example preprocessing; adjust as needed for your model
|
| 37 |
+
image = image.resize((224, 224)) # Resize image to expected input size
|
| 38 |
+
image = np.array(image) / 255.0 # Normalize image
|
| 39 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 40 |
return image
|
| 41 |
|