Download app.py from Anm5/ytry: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/Anm5/ytry/resolve/main/app.py
- Command line
-
hf download hf://Anm5/ytry/app.py
-
curl -L -o app.py https://huggingface.co/Anm5/ytry/resolve/main/app.py
1.05 kB
| from flask import Flask, request, jsonify | |
| import cv2 | |
| import numpy as np | |
| import base64 | |
| app = Flask(__name__) | |
| def decode_image(data_url): | |
| header, encoded = data_url.split(",", 1) | |
| image_data = base64.b64decode(encoded) | |
| image_np = np.fromstring(image_data, dtype=np.uint8) | |
| image = cv2.imdecode(image_np, cv2.IMREAD_COLOR) | |
| return image | |
| def process_frame(): | |
| data = request.json | |
| frame_data = data['frame'] | |
| frame = decode_image(frame_data) | |
| # Process the frame (use your existing run function) | |
| result_image = run(frame, model_complexity=1, enable_segmentation=True, | |
| min_detection_confidence=0.5, background_color='white') | |
| # Encode the image back to base64 | |
| _, buffer = cv2.imencode('.jpg', result_image) | |
| encoded_image = base64.b64encode(buffer).decode('utf-8') | |
| response = { | |
| 'processed_frame': f"data:image/jpeg;base64,{encoded_image}" | |
| } | |
| return jsonify(response) | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |