Download src/main.py from Fred808/NSL: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/Fred808/NSL/resolve/main/src/main.py
- Command line
-
hf download hf://spaces/Fred808/NSL/src/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Fred808/NSL/resolve/main/src/main.py
1.6 kB
| import os | |
| import sys | |
| # DON'T CHANGE THIS !!! | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | |
| from flask import Flask, send_from_directory | |
| from flask_cors import CORS | |
| from src.models.user import db | |
| from src.routes.user import user_bp | |
| from src.routes.scanner import scanner_bp | |
| app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), 'static')) | |
| app.config['SECRET_KEY'] = 'asdf#FGSgvasgf$5$WGT' | |
| # Enable CORS for all routes | |
| CORS(app) | |
| app.register_blueprint(user_bp, url_prefix='/api') | |
| app.register_blueprint(scanner_bp, url_prefix='/api') | |
| # uncomment if you need to use database | |
| app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{os.path.join(os.path.dirname(__file__), 'database', 'app.db')}" | |
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
| db.init_app(app) | |
| with app.app_context(): | |
| db.create_all() | |
| def serve(path): | |
| static_folder_path = app.static_folder | |
| if static_folder_path is None: | |
| return "Static folder not configured", 404 | |
| if path != "" and os.path.exists(os.path.join(static_folder_path, path)): | |
| return send_from_directory(static_folder_path, path) | |
| else: | |
| index_path = os.path.join(static_folder_path, 'index.html') | |
| if os.path.exists(index_path): | |
| return send_from_directory(static_folder_path, 'index.html') | |
| else: | |
| return "index.html not found", 404 | |
| if __name__ == '__main__': | |
| import os | |
| port = int(os.environ.get('PORT', 7860)) | |
| app.run(host='0.0.0.0', port=port, debug=False) | |