-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (42 loc) · 1.3 KB
/
app.py
File metadata and controls
54 lines (42 loc) · 1.3 KB
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
import os
import logging
import secrets
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from flask_login import LoginManager
from flask_wtf.csrf import CSRFProtect
# Configure logging
logging.basicConfig(level=logging.DEBUG)
class Base(DeclarativeBase):
pass
db = SQLAlchemy(model_class=Base)
# create the app
app = Flask(__name__)
# Use environment variable or generate strong random key
app.secret_key = os.environ.get("SESSION_SECRET", secrets.token_hex(16))
# Initialize CSRF protection
csrf = CSRFProtect(app)
# Configure the SQLite database
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///llm_assessment.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {
"pool_recycle": 300,
"pool_pre_ping": True,
}
# initialize the app with the extension
db.init_app(app)
# Setup login manager
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
# Import models here to avoid circular imports
from models import User
@login_manager.user_loader
def load_user(user_id):
return db.session.get(User, int(user_id))
with app.app_context():
# Import all models here
import models # noqa: F401
db.create_all()