File size: 2,873 Bytes
44ed412
b3db271
 
 
44ed412
b3db271
 
 
9d5b23e
012d331
f06ccae
 
44ed412
9d5b23e
 
 
b3db271
 
 
44ed412
 
 
 
f06ccae
 
 
 
 
 
 
 
44ed412
 
 
b3db271
f06ccae
b3db271
44ed412
f06ccae
9d5b23e
6d636a3
 
9d5b23e
f06ccae
9d5b23e
44ed412
b3db271
 
 
 
 
44ed412
b3db271
f06ccae
b3db271
 
68d7061
b3db271
9d5b23e
b3db271
f06ccae
b3db271
44ed412
 
68d7061
44ed412
 
f06ccae
68d7061
44ed412
 
b3db271
 
 
44ed412
f06ccae
44ed412
b3db271
44ed412
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
# =============================================================
@app.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)