Spaces:
Sleeping
Sleeping
Arnel Gwen Nuqui
commited on
Commit
·
9d5b23e
1
Parent(s):
8c91bd9
done creating app
Browse files
app.py
CHANGED
|
@@ -3,10 +3,16 @@ import os
|
|
| 3 |
# -------------------------------------------------------------
|
| 4 |
# Environment Configuration
|
| 5 |
# -------------------------------------------------------------
|
|
|
|
|
|
|
| 6 |
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 7 |
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # Suppress TensorFlow INFO/WARN
|
| 8 |
os.environ["GLOG_minloglevel"] = "2" # Suppress Mediapipe logs
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from flask import Flask, jsonify
|
| 11 |
from flask_cors import CORS
|
| 12 |
|
|
@@ -23,8 +29,8 @@ CORS(
|
|
| 23 |
"origins": [
|
| 24 |
"http://localhost:3000",
|
| 25 |
"http://127.0.0.1:3000",
|
| 26 |
-
"https://proctorvision-client.vercel.app",
|
| 27 |
-
"https://proctorvision-server-production.up.railway.app",
|
| 28 |
]
|
| 29 |
}
|
| 30 |
},
|
|
@@ -32,27 +38,32 @@ CORS(
|
|
| 32 |
)
|
| 33 |
|
| 34 |
# -------------------------------------------------------------
|
| 35 |
-
# Import Blueprints
|
| 36 |
-
# -------------------------------------------------------------
|
| 37 |
-
|
| 38 |
-
# -------------------------------------------------------------
|
| 39 |
-
# Import Blueprints (with error diagnostics)
|
| 40 |
# -------------------------------------------------------------
|
| 41 |
try:
|
| 42 |
print("🔍 Attempting to import blueprints...")
|
|
|
|
| 43 |
from routes.classification_routes import classification_bp
|
| 44 |
from routes.webrtc_routes import webrtc_bp
|
|
|
|
| 45 |
print("✅ Successfully imported blueprints!")
|
| 46 |
|
| 47 |
app.register_blueprint(classification_bp, url_prefix="/api")
|
| 48 |
app.register_blueprint(webrtc_bp, url_prefix="/api")
|
|
|
|
| 49 |
print("✅ Blueprints registered successfully.")
|
|
|
|
| 50 |
except Exception as e:
|
|
|
|
| 51 |
print(f"⚠️ Failed to import or register blueprints: {e}")
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
print("Registered routes:")
|
| 54 |
for rule in app.url_map.iter_rules():
|
| 55 |
-
print(rule)
|
|
|
|
| 56 |
# -------------------------------------------------------------
|
| 57 |
# Root & Health Check Route
|
| 58 |
# -------------------------------------------------------------
|
|
@@ -65,11 +76,10 @@ def home():
|
|
| 65 |
"available_routes": routes
|
| 66 |
})
|
| 67 |
|
| 68 |
-
|
| 69 |
# -------------------------------------------------------------
|
| 70 |
# Main Entrypoint
|
| 71 |
# -------------------------------------------------------------
|
| 72 |
if __name__ == "__main__":
|
| 73 |
-
port = int(os.environ.get("PORT", 7860)) # Hugging Face
|
| 74 |
debug = os.environ.get("DEBUG", "False").lower() == "true"
|
| 75 |
app.run(host="0.0.0.0", port=port, debug=debug)
|
|
|
|
| 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 |
|
|
|
|
| 29 |
"origins": [
|
| 30 |
"http://localhost:3000",
|
| 31 |
"http://127.0.0.1:3000",
|
| 32 |
+
"https://proctorvision-client.vercel.app",
|
| 33 |
+
"https://proctorvision-server-production.up.railway.app",
|
| 34 |
]
|
| 35 |
}
|
| 36 |
},
|
|
|
|
| 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, url_prefix="/api")
|
| 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 |
# -------------------------------------------------------------
|
|
|
|
| 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)
|