Spaces:
Sleeping
Sleeping
Arnel Gwen Nuqui
commited on
Commit
Β·
b3db271
1
Parent(s):
6d636a3
replace app
Browse files
app.py
CHANGED
|
@@ -1,24 +1,23 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
# Environment Configuration
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
os.environ["MODEL_DIR"] = "/tmp/model"
|
| 8 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 9 |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # Suppress TensorFlow INFO/WARN
|
| 10 |
os.environ["GLOG_minloglevel"] = "2" # Suppress Mediapipe logs
|
| 11 |
|
| 12 |
-
# Create /tmp directories (Hugging Face allows writes only under /tmp)
|
| 13 |
os.makedirs(os.environ["MODEL_DIR"], exist_ok=True)
|
| 14 |
os.makedirs(os.environ["MPLCONFIGDIR"], exist_ok=True)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# -------------------------------------------------------------
|
| 20 |
-
# Flask Initialization
|
| 21 |
-
# -------------------------------------------------------------
|
| 22 |
app = Flask(__name__)
|
| 23 |
|
| 24 |
# CORS Configuration
|
|
@@ -37,36 +36,47 @@ CORS(
|
|
| 37 |
supports_credentials=True,
|
| 38 |
)
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
# Import Blueprints (with diagnostics)
|
| 42 |
-
#
|
| 43 |
try:
|
| 44 |
print("π Attempting to import blueprints...")
|
| 45 |
|
| 46 |
from routes.classification_routes import classification_bp
|
| 47 |
-
#from routes.webrtc_routes import webrtc_bp
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
|
|
|
| 51 |
app.register_blueprint(classification_bp, url_prefix="/api")
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
except Exception as e:
|
| 57 |
-
|
| 58 |
-
print(
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
# Log Registered Routes
|
| 62 |
-
#
|
| 63 |
-
print("Registered
|
| 64 |
for rule in app.url_map.iter_rules():
|
| 65 |
-
print("
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
# Root & Health Check Route
|
| 69 |
-
#
|
| 70 |
@app.route("/")
|
| 71 |
def home():
|
| 72 |
routes = [str(rule) for rule in app.url_map.iter_rules()]
|
|
@@ -76,10 +86,12 @@ def home():
|
|
| 76 |
"available_routes": routes
|
| 77 |
})
|
| 78 |
|
| 79 |
-
#
|
| 80 |
-
# Main Entrypoint
|
| 81 |
-
#
|
| 82 |
if __name__ == "__main__":
|
| 83 |
-
port = int(os.environ.get("PORT", 7860)) # Hugging Face
|
| 84 |
debug = os.environ.get("DEBUG", "False").lower() == "true"
|
|
|
|
|
|
|
| 85 |
app.run(host="0.0.0.0", port=port, debug=debug)
|
|
|
|
| 1 |
import os
|
| 2 |
+
import traceback
|
| 3 |
+
from flask import Flask, jsonify
|
| 4 |
+
from flask_cors import CORS
|
| 5 |
|
| 6 |
+
# =============================================================
|
| 7 |
+
# β
Environment Configuration
|
| 8 |
+
# =============================================================
|
| 9 |
+
# Hugging Face allows writes only under /tmp, so create safe dirs
|
| 10 |
os.environ["MODEL_DIR"] = "/tmp/model"
|
| 11 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 12 |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # Suppress TensorFlow INFO/WARN
|
| 13 |
os.environ["GLOG_minloglevel"] = "2" # Suppress Mediapipe logs
|
| 14 |
|
|
|
|
| 15 |
os.makedirs(os.environ["MODEL_DIR"], exist_ok=True)
|
| 16 |
os.makedirs(os.environ["MPLCONFIGDIR"], exist_ok=True)
|
| 17 |
|
| 18 |
+
# =============================================================
|
| 19 |
+
# β
Flask Initialization
|
| 20 |
+
# =============================================================
|
|
|
|
|
|
|
|
|
|
| 21 |
app = Flask(__name__)
|
| 22 |
|
| 23 |
# CORS Configuration
|
|
|
|
| 36 |
supports_credentials=True,
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# =============================================================
|
| 40 |
+
# π Import Blueprints (with deep diagnostics)
|
| 41 |
+
# =============================================================
|
| 42 |
try:
|
| 43 |
print("π Attempting to import blueprints...")
|
| 44 |
|
| 45 |
from routes.classification_routes import classification_bp
|
| 46 |
+
# from routes.webrtc_routes import webrtc_bp
|
| 47 |
+
|
| 48 |
+
print("β
Successfully imported classification_bp from routes.classification_routes")
|
| 49 |
|
| 50 |
+
# Inspect blueprint details
|
| 51 |
+
if hasattr(classification_bp, "url_prefix"):
|
| 52 |
+
print(f"π¦ Blueprint prefix: {getattr(classification_bp, 'url_prefix', 'None')}")
|
| 53 |
+
if hasattr(classification_bp, "deferred_functions"):
|
| 54 |
+
print(f"π Blueprint has {len(classification_bp.deferred_functions)} deferred functions")
|
| 55 |
|
| 56 |
+
# Register the blueprints
|
| 57 |
app.register_blueprint(classification_bp, url_prefix="/api")
|
| 58 |
+
print("β
classification_bp registered successfully.")
|
| 59 |
|
| 60 |
+
# app.register_blueprint(webrtc_bp)
|
| 61 |
+
# print("β
webrtc_bp registered successfully.")
|
| 62 |
|
| 63 |
except Exception as e:
|
| 64 |
+
print("β οΈ Failed to import or register blueprints.")
|
| 65 |
+
print("π¨ Exception type:", type(e).__name__)
|
| 66 |
+
print("π Exception message:", str(e))
|
| 67 |
+
print("π Full traceback:")
|
| 68 |
+
traceback.print_exc()
|
| 69 |
|
| 70 |
+
# =============================================================
|
| 71 |
+
# π Debug: Log All Registered Routes
|
| 72 |
+
# =============================================================
|
| 73 |
+
print("\nπ Final Registered Routes:")
|
| 74 |
for rule in app.url_map.iter_rules():
|
| 75 |
+
print(f"β‘ {rule.endpoint} β {rule}")
|
| 76 |
|
| 77 |
+
# =============================================================
|
| 78 |
+
# π Root & Health Check Route
|
| 79 |
+
# =============================================================
|
| 80 |
@app.route("/")
|
| 81 |
def home():
|
| 82 |
routes = [str(rule) for rule in app.url_map.iter_rules()]
|
|
|
|
| 86 |
"available_routes": routes
|
| 87 |
})
|
| 88 |
|
| 89 |
+
# =============================================================
|
| 90 |
+
# π Main Entrypoint
|
| 91 |
+
# =============================================================
|
| 92 |
if __name__ == "__main__":
|
| 93 |
+
port = int(os.environ.get("PORT", 7860)) # Default for Hugging Face
|
| 94 |
debug = os.environ.get("DEBUG", "False").lower() == "true"
|
| 95 |
+
|
| 96 |
+
print(f"\nπ Starting Flask server on port {port} (debug={debug})...")
|
| 97 |
app.run(host="0.0.0.0", port=port, debug=debug)
|