Spaces:
Runtime error
Runtime error
Factor Studios
commited on
Update src/main.py
Browse files- src/main.py +24 -5
src/main.py
CHANGED
|
@@ -10,7 +10,7 @@ from src.routes.user import user_bp
|
|
| 10 |
from src.routes.ai_chat import ai_chat_bp
|
| 11 |
|
| 12 |
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), 'static'))
|
| 13 |
-
app.config['SECRET_KEY'] = 'asdf#FGSgvasgf$5$WGT'
|
| 14 |
|
| 15 |
# Enable CORS for all routes
|
| 16 |
CORS(app)
|
|
@@ -18,19 +18,34 @@ CORS(app)
|
|
| 18 |
app.register_blueprint(user_bp, url_prefix='/api')
|
| 19 |
app.register_blueprint(ai_chat_bp, url_prefix='/api')
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
|
|
|
| 23 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
db.init_app(app)
|
| 25 |
with app.app_context():
|
| 26 |
db.create_all()
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@app.route('/', defaults={'path': ''})
|
| 29 |
@app.route('/<path:path>')
|
| 30 |
def serve(path):
|
| 31 |
static_folder_path = app.static_folder
|
| 32 |
if static_folder_path is None:
|
| 33 |
-
|
| 34 |
|
| 35 |
if path != "" and os.path.exists(os.path.join(static_folder_path, path)):
|
| 36 |
return send_from_directory(static_folder_path, path)
|
|
@@ -43,4 +58,8 @@ def serve(path):
|
|
| 43 |
|
| 44 |
|
| 45 |
if __name__ == '__main__':
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from src.routes.ai_chat import ai_chat_bp
|
| 11 |
|
| 12 |
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), 'static'))
|
| 13 |
+
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'asdf#FGSgvasgf$5$WGT')
|
| 14 |
|
| 15 |
# Enable CORS for all routes
|
| 16 |
CORS(app)
|
|
|
|
| 18 |
app.register_blueprint(user_bp, url_prefix='/api')
|
| 19 |
app.register_blueprint(ai_chat_bp, url_prefix='/api')
|
| 20 |
|
| 21 |
+
# Database configuration
|
| 22 |
+
database_path = os.path.join(os.path.dirname(__file__), 'database', 'app.db')
|
| 23 |
+
app.config['SQLALCHEMY_DATABASE_URI'] = f"sqlite:///{database_path}"
|
| 24 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 25 |
+
|
| 26 |
+
# Ensure database directory exists
|
| 27 |
+
os.makedirs(os.path.dirname(database_path), exist_ok=True)
|
| 28 |
+
|
| 29 |
db.init_app(app)
|
| 30 |
with app.app_context():
|
| 31 |
db.create_all()
|
| 32 |
|
| 33 |
+
# Health check endpoint
|
| 34 |
+
@app.route('/health')
|
| 35 |
+
def health_check():
|
| 36 |
+
return {'status': 'healthy', 'message': 'Server is running'}, 200
|
| 37 |
+
|
| 38 |
+
# GPU status endpoint (if needed for health check)
|
| 39 |
+
@app.route('/api/gpu-status')
|
| 40 |
+
def gpu_status():
|
| 41 |
+
return {'status': 'ok', 'message': 'GPU status endpoint'}, 200
|
| 42 |
+
|
| 43 |
@app.route('/', defaults={'path': ''})
|
| 44 |
@app.route('/<path:path>')
|
| 45 |
def serve(path):
|
| 46 |
static_folder_path = app.static_folder
|
| 47 |
if static_folder_path is None:
|
| 48 |
+
return "Static folder not configured", 404
|
| 49 |
|
| 50 |
if path != "" and os.path.exists(os.path.join(static_folder_path, path)):
|
| 51 |
return send_from_directory(static_folder_path, path)
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
if __name__ == '__main__':
|
| 61 |
+
# Get port from environment variable, default to 5000
|
| 62 |
+
port = int(os.environ.get('PORT', 5000))
|
| 63 |
+
debug = os.environ.get('FLASK_ENV') == 'development'
|
| 64 |
+
|
| 65 |
+
app.run(host='0.0.0.0', port=port, debug=debug)
|