Arnel Gwen Nuqui commited on
Commit
b3db271
Β·
1 Parent(s): 6d636a3

replace app

Browse files
Files changed (1) hide show
  1. app.py +44 -32
app.py CHANGED
@@ -1,24 +1,23 @@
1
  import os
 
 
 
2
 
3
- # -------------------------------------------------------------
4
- # Environment Configuration
5
- # -------------------------------------------------------------
6
- # Use writable directories for model/data/temp
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
- from flask import Flask, jsonify
17
- from flask_cors import CORS
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
- print("βœ… Successfully imported blueprints!")
 
 
 
 
50
 
 
51
  app.register_blueprint(classification_bp, url_prefix="/api")
52
- #app.register_blueprint(webrtc_bp)
53
 
54
- print("βœ… Blueprints registered successfully.")
 
55
 
56
  except Exception as e:
57
- # Log permission or import errors clearly
58
- print(f"⚠️ Failed to import or register blueprints: {e}")
 
 
 
59
 
60
- # -------------------------------------------------------------
61
- # Log Registered Routes
62
- # -------------------------------------------------------------
63
- print("Registered routes:")
64
  for rule in app.url_map.iter_rules():
65
- print(" ", rule)
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 default port
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)