Spaces:
Running
Running
| from flask import Flask, render_template, request, jsonify | |
| from flask_cors import CORS | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def create_app(test_config=None): | |
| # create and configure the app | |
| app = Flask(__name__, instance_relative_config=True) | |
| app.config.from_mapping( | |
| SECRET_KEY=os.environ.get('SECRET_KEY', 'change-me-in-production'), | |
| UPLOAD_FOLDER=os.path.join(app.root_path, 'static', 'uploads'), | |
| ALLOWED_EXTENSIONS={'png', 'jpg', 'jpeg'}, | |
| MAX_CONTENT_LENGTH=16 * 1024 * 1024, # 16MB max | |
| ) | |
| if test_config is None: | |
| # load the instance config, if it exists, when not testing | |
| app.config.from_pyfile('config.py', silent=True) | |
| else: | |
| # load the test config if passed in | |
| app.config.from_mapping(test_config) | |
| # ensure the upload folder exists | |
| os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) | |
| CORS(app) | |
| # Register Blueprints | |
| from .routes import main_routes, analysis_routes, recognition_routes | |
| app.register_blueprint(main_routes.bp) | |
| app.register_blueprint(analysis_routes.bp) | |
| app.register_blueprint(recognition_routes.bp) | |
| def page_not_found(e): | |
| return render_template('404.html'), 404 | |
| def internal_server_error(e): | |
| return render_template('500.html'), 500 | |
| return app | |