Download app.py from Anm5/try1: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/Anm5/try1/resolve/main/app.py
- Command line
-
hf download hf://spaces/Anm5/try1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Anm5/try1/resolve/main/app.py
1.39 kB
| from flask import Flask, request, jsonify | |
| from PIL import Image | |
| import io | |
| import base64 | |
| import numpy as np | |
| import logging | |
| app = Flask(__name__) | |
| # Dummy pose recognition function | |
| def recognize_pose(image): | |
| # Replace this with your actual model inference code | |
| pose = "warrior" # Dummy value for testing | |
| return pose | |
| def api_recognize_pose(): | |
| try: | |
| # Decode the image from the request | |
| image_data = request.json['image'].split(",")[1] | |
| image_bytes = base64.b64decode(image_data) | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| # Preprocess and recognize pose | |
| image = preprocess_image(image) | |
| pose = recognize_pose(image) | |
| return jsonify({'pose': pose}) | |
| except KeyError as ke: | |
| logging.error(f"Key Error: {ke}") | |
| return jsonify({'error': 'Invalid input data format'}), 400 | |
| except Exception as e: | |
| logging.error(f"Unexpected error: {e}") | |
| return jsonify({'error': str(e)}), 500 | |
| def preprocess_image(image): | |
| # Example preprocessing; adjust as needed for your model | |
| image = image.resize((224, 224)) # Resize image to expected input size | |
| image = np.array(image) / 255.0 # Normalize image | |
| image = np.expand_dims(image, axis=0) # Add batch dimension | |
| return image | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |