Spaces:
Sleeping
Sleeping
| import os | |
| import traceback | |
| from flask import Flask, jsonify | |
| from flask_cors import CORS | |
| # ============================================================= | |
| # β Environment Configuration | |
| # ============================================================= | |
| os.environ["MODEL_DIR"] = "/tmp/model" | |
| os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib" | |
| os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" | |
| os.environ["GLOG_minloglevel"] = "2" | |
| os.makedirs(os.environ["MODEL_DIR"], exist_ok=True) | |
| os.makedirs(os.environ["MPLCONFIGDIR"], exist_ok=True) | |
| # ============================================================= | |
| # β Flask Initialization | |
| # ============================================================= | |
| app = Flask(__name__) | |
| CORS( | |
| app, | |
| resources={r"/api/*": { | |
| "origins": [ | |
| "http://localhost:3000", | |
| "http://127.0.0.1:3000", | |
| "https://proctorvision-client.vercel.app", | |
| "https://proctorvision-server-production.up.railway.app", | |
| ] | |
| }}, | |
| supports_credentials=True, | |
| ) | |
| # ============================================================= | |
| # π Import Blueprint (Classification only) | |
| # ============================================================= | |
| try: | |
| print("π Attempting to import classification routes...") | |
| from routes.classification_routes import classification_bp | |
| app.register_blueprint(classification_bp, url_prefix="/api") | |
| print("β classification_bp registered successfully.") | |
| except Exception as e: | |
| print("β οΈ Failed to import or register blueprints.") | |
| print("π¨ Exception type:", type(e).__name__) | |
| print("π Exception message:", str(e)) | |
| print("π Full traceback:") | |
| traceback.print_exc() | |
| # ============================================================= | |
| # π Debug: List Registered Routes | |
| # ============================================================= | |
| print("\nπ Final Registered Routes:") | |
| for rule in app.url_map.iter_rules(): | |
| print(f"β‘ {rule.endpoint} β {rule}") | |
| # ============================================================= | |
| # π Root Route | |
| # ============================================================= | |
| def home(): | |
| routes = [str(rule) for rule in app.url_map.iter_rules()] | |
| return jsonify({ | |
| "status": "ok", | |
| "message": "β ProctorVision AI Classification Backend Running", | |
| "available_routes": routes | |
| }) | |
| # ============================================================= | |
| # π Main Entrypoint | |
| # ============================================================= | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 7860)) | |
| debug = os.environ.get("DEBUG", "False").lower() == "true" | |
| print(f"\nπ Starting Flask server on port {port} (debug={debug})...") | |
| app.run(host="0.0.0.0", port=port, debug=debug) | |