Spaces:
Build error
Build error
Update app.py
#2
by
chemistrymath - opened
app.py
CHANGED
|
@@ -1,8 +1,16 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
import urllib.request
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Now import libraries
|
| 7 |
import mediapipe as mp
|
| 8 |
import matplotlib.pyplot as plt
|
|
@@ -11,22 +19,24 @@ from flask import Flask, request, jsonify
|
|
| 11 |
from flask_cors import CORS
|
| 12 |
import torch.nn.functional as F
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
os.environ["MP_MODELS_PATH"]
|
| 17 |
|
| 18 |
-
# ✅ Ensure the directories exist
|
| 19 |
-
os.makedirs("/tmp/matplotlib", exist_ok=True)
|
| 20 |
-
os.makedirs("/tmp/mediapipe_models", exist_ok=True)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
MODEL_URL = "https://storage.googleapis.com/mediapipe-assets/pose_landmark_heavy.tflite"
|
| 25 |
|
|
|
|
| 26 |
if not os.path.exists(MODEL_PATH):
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
app = Flask(__name__)
|
| 31 |
CORS(app)
|
| 32 |
|
|
|
|
| 1 |
|
| 2 |
+
|
|
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
+
import os
|
| 6 |
+
import urllib.request
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# Set writable directories
|
| 10 |
+
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 11 |
+
os.environ["MP_MODELS_PATH"] = "/tmp/mediapipe_models"
|
| 12 |
+
|
| 13 |
+
|
| 14 |
# Now import libraries
|
| 15 |
import mediapipe as mp
|
| 16 |
import matplotlib.pyplot as plt
|
|
|
|
| 19 |
from flask_cors import CORS
|
| 20 |
import torch.nn.functional as F
|
| 21 |
|
| 22 |
+
# MediaPipe Model Download
|
| 23 |
+
MEDIAPIPE_POSE_MODEL_URL = "https://storage.googleapis.com/mediapipe-models/pose_landmark/pose_landmark_heavy/float16/1/pose_landmark_heavy.tflite"
|
| 24 |
+
MODEL_PATH = os.path.join(os.environ["MP_MODELS_PATH"], "pose_landmark_heavy.tflite")
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Ensure model directory exists and is writable
|
| 28 |
+
os.makedirs(os.environ["MP_MODELS_PATH"], exist_ok=True)
|
|
|
|
| 29 |
|
| 30 |
+
# Download MediaPipe model if not exists
|
| 31 |
if not os.path.exists(MODEL_PATH):
|
| 32 |
+
try:
|
| 33 |
+
print("Downloading MediaPipe model...")
|
| 34 |
+
urllib.request.urlretrieve(MEDIAPIPE_POSE_MODEL_URL, MODEL_PATH)
|
| 35 |
+
print(f"Model downloaded successfully to {MODEL_PATH}")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"Error downloading model: {e}")
|
| 38 |
+
|
| 39 |
+
# Rest of the existing app.py code remains the same
|
| 40 |
app = Flask(__name__)
|
| 41 |
CORS(app)
|
| 42 |
|