Spaces:
Sleeping
Sleeping
Commit ·
8e5e32f
1
Parent(s): 765c205
Add route to serve haarcascade XML file for Flutter app access
Browse files12341511 unmodified lines151615171518151915201521from flask import Flask, request, jsonifyfrom flask_cors import CORSfrom flask_sock import Sockimport google.generativeai as genai1511 unmodified lines# Initialize models when module is loaded (works with gunicorn)initialize_models()if __name__ == '__main__':print(">> Starting Gemini AI Journaling Backend...")print(f">> API Key configured: {'YES' if GEMINI_API_KEY else 'NO'}")12341511 unmodified lines151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542from flask import Flask, request, jsonify, send_from_directoryfrom flask_cors import CORSfrom flask_sock import Sockimport google.generativeai as genai1511 unmodified lines# Initialize models when module is loaded (works with gunicorn)initialize_models()# ============================================================================# STATIC FILE SERVING (For Flutter App to download models)# ============================================================================@app.route('/models/<path:filename>')def serve_models(filename):"""Serve model files (XML, PKL) to the Flutter app"""# Only allow specific file types for securityallowed_extensions = {'.xml', '.pkl', '.json', '.txt'}file_ext = os.path.splitext(filename)[1].lower()if file_ext not in allowed_extensions:return jsonify({'error': 'File type not allowed'}), 403return send_from_directory(os.path.dirname(os.path.abspath(__file__)), filename)@app.route('/haarcascade_frontalface_default.xml')def serve_cascade():"""Direct shortcut to serve the haarcascade file"""return send_from_directory(os.path.dirname(os.path.abspath(__file__)), 'haarcascade_frontalface_default.xml')if __name__ == '__main__':print(">> Starting Gemini AI Journaling Backend...")print(f">> API Key configured: {'YES' if GEMINI_API_KEY else 'NO'}")
app.py+22-1