Spaces:
Sleeping
Sleeping
| from flask import Flask, request, jsonify | |
| import torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| # Load Meta Sapiens Pose model | |
| sapiens_model = torch.jit.load('/models/sapiens_pose/model.pt') | |
| sapiens_model.eval() | |
| # Load MotionBERT model | |
| motionbert_model = AutoModelForSequenceClassification.from_pretrained('/models/motionbert') | |
| motionbert_tokenizer = AutoTokenizer.from_pretrained('/models/motionbert') | |
| app = Flask(__name__) | |
| def pose_estimation(): | |
| # Accept an image file as input for pose estimation | |
| image = request.files['image'].read() | |
| # Perform pose estimation | |
| with torch.no_grad(): | |
| pose_result = sapiens_model(torch.tensor(image)) | |
| return jsonify({"pose_result": pose_result.tolist()}) | |
| def sequence_analysis(): | |
| # Accept keypoint data as input for sequence analysis | |
| keypoints = request.json['keypoints'] | |
| inputs = motionbert_tokenizer(keypoints, return_tensors="pt") | |
| with torch.no_grad(): | |
| sequence_output = motionbert_model(**inputs) | |
| return jsonify({"sequence_analysis": sequence_output.logits.tolist()}) | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) | |