modified: _pycache__/create_app.cpython-312.pyc
Browse filesmodified: __pycache__/database.cpython-312.pyc
modified: configs.py
modified: create_app.py
modified: database.py
modified: inference/__pycache__/__init__.cpython-312.pyc
modified: inference/__pycache__/infer_single.cpython-312.pyc
modified: models/__pycache__/__init__.cpython-312.pyc
modified: models/__pycache__/model.cpython-312.pyc
modified: utils/__pycache__/__init__.cpython-312.pyc
modified: utils/__pycache__/data_utils.cpython-312.pyc
modified: utils/__pycache__/prompts.cpython-312.pyc
modified: utils/__pycache__/util_func.cpython-312.pyc
modified: views/__pycache__/__init__.cpython-312.pyc
modified: views/__pycache__/about.cpython-312.pyc
modified: views/__pycache__/auth.cpython-312.pyc
modified: views/__pycache__/dashboard.cpython-312.pyc
modified: views/__pycache__/error.cpython-312.pyc
modified: views/__p_ycache__/infer.cpython-312.pyc
modified: views/auth.py
- __pycache__/create_app.cpython-312.pyc +0 -0
- __pycache__/database.cpython-312.pyc +0 -0
- configs.py +1 -0
- create_app.py +20 -43
- database.py +4 -2
- inference/__pycache__/__init__.cpython-312.pyc +0 -0
- inference/__pycache__/infer_single.cpython-312.pyc +0 -0
- models/__pycache__/__init__.cpython-312.pyc +0 -0
- models/__pycache__/model.cpython-312.pyc +0 -0
- utils/__pycache__/__init__.cpython-312.pyc +0 -0
- utils/__pycache__/data_utils.cpython-312.pyc +0 -0
- utils/__pycache__/prompts.cpython-312.pyc +0 -0
- utils/__pycache__/util_func.cpython-312.pyc +0 -0
- views/__pycache__/__init__.cpython-312.pyc +0 -0
- views/__pycache__/about.cpython-312.pyc +0 -0
- views/__pycache__/auth.cpython-312.pyc +0 -0
- views/__pycache__/dashboard.cpython-312.pyc +0 -0
- views/__pycache__/error.cpython-312.pyc +0 -0
- views/__pycache__/infer.cpython-312.pyc +0 -0
- views/auth.py +5 -1
|
Binary files a/__pycache__/create_app.cpython-312.pyc and b/__pycache__/create_app.cpython-312.pyc differ
|
|
|
|
Binary files a/__pycache__/database.cpython-312.pyc and b/__pycache__/database.cpython-312.pyc differ
|
|
|
|
@@ -1,2 +1,3 @@
|
|
| 1 |
SECRET_KEY = 'secret_key_here'
|
|
|
|
| 2 |
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
|
|
| 1 |
SECRET_KEY = 'secret_key_here'
|
| 2 |
+
SQLALCHEMY_DATABASE_URI = 'sqlite:///users.db'
|
| 3 |
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
|
@@ -5,7 +5,7 @@ from flask import render_template
|
|
| 5 |
from transformers import LongformerTokenizer, AutoTokenizer, AutoModelForCausalLM, LongformerConfig
|
| 6 |
from models.model import *
|
| 7 |
from utils.util_func import *
|
| 8 |
-
import
|
| 9 |
|
| 10 |
db = SQLAlchemy()
|
| 11 |
login_manager = LoginManager()
|
|
@@ -20,67 +20,44 @@ MODEL_SESSION = None
|
|
| 20 |
def load_models():
|
| 21 |
global MODELS_LOADED, LONGFORMER_TOKENIZER, LONGFORMER_MODEL, QWEN_TOKENIZER, QWEN_MODEL
|
| 22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
-
print("DEIVCE=", device)
|
| 24 |
if not MODELS_LOADED:
|
| 25 |
-
print("START TO GET QWEN")
|
| 26 |
-
model_name = 'Qwen/Qwen3-0.6B'
|
| 27 |
-
QWEN_TOKENIZER = AutoTokenizer.from_pretrained(model_name, device='auto')
|
| 28 |
-
QWEN_TOKENIZER.pad_token_id = QWEN_TOKENIZER.eos_token_id
|
| 29 |
-
print("QWEN TOKENIZER LOADED")
|
| 30 |
-
try:
|
| 31 |
-
QWEN_MODEL = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
| 32 |
-
QWEN_MODEL = QWEN_MODEL.to(device)
|
| 33 |
-
print("QWEN MODEL LOADED", flush=True)
|
| 34 |
-
except Exception as e:
|
| 35 |
-
print(f"ERROR LOADING QWEN MODEL: {str(e)}")
|
| 36 |
-
raise # Re-raise to see full traceback
|
| 37 |
-
# QWEN_MODEL = AutoModelForCausalLM.from_pretrained(model_name).half()
|
| 38 |
-
# QWEN_MODEL = QWEN_MODEL.to(device)
|
| 39 |
-
print(QWEN_MODEL)
|
| 40 |
-
print("QWEN MODEL LOADED", flush=True)
|
| 41 |
LONGFORMER_TOKENIZER = LongformerTokenizer.from_pretrained('allenai/longformer-base-4096', device='auto')
|
| 42 |
config = LongformerConfig.from_json_file("Longformer_checkpoint/config.json")
|
| 43 |
-
print("LONGFORMER TOKENIZER LOADED")
|
| 44 |
LONGFORMER_MODEL = CustomLongformerForSequenceClassification(config).from_pretrained('SFM2001/LongFormerScorer')
|
| 45 |
LONGFORMER_MODEL = LONGFORMER_MODEL.to(device)
|
| 46 |
-
print(LONGFORMER_MODEL)
|
| 47 |
-
print("LONGFORMER MODEL LOADED", flush=True)
|
| 48 |
LONGFORMER_MODEL.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
MODELS_LOADED = True
|
| 50 |
-
print("LOAD ENDED", flush=True)
|
| 51 |
-
|
| 52 |
|
| 53 |
def create_app():
|
| 54 |
set_seed(42)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join('/instance', 'users.db')
|
| 59 |
-
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 60 |
-
app.config['SECRET_KEY'] = 'your-very-secret-key-here' # Must be set!
|
| 61 |
-
|
| 62 |
-
# Ensure instance folder exists
|
| 63 |
-
try:
|
| 64 |
-
os.makedirs(app.instance_path)
|
| 65 |
-
except OSError:
|
| 66 |
-
pass
|
| 67 |
-
|
| 68 |
-
# Initialize extensions
|
| 69 |
db.init_app(app)
|
| 70 |
login_manager.init_app(app)
|
| 71 |
login_manager.login_view = 'auth.login'
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
# Load models (after db initialization)
|
| 74 |
with app.app_context():
|
| 75 |
-
load_models()
|
| 76 |
-
db.create_all() # Create tables if they don't exist
|
| 77 |
-
|
| 78 |
-
# Register blueprints
|
| 79 |
from views import auth_bp, dashboard_bp, infer_bp, about_bp, error_bp
|
| 80 |
app.register_blueprint(auth_bp)
|
| 81 |
app.register_blueprint(dashboard_bp)
|
| 82 |
app.register_blueprint(infer_bp)
|
| 83 |
app.register_blueprint(about_bp)
|
| 84 |
app.register_blueprint(error_bp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
return app
|
|
|
|
| 5 |
from transformers import LongformerTokenizer, AutoTokenizer, AutoModelForCausalLM, LongformerConfig
|
| 6 |
from models.model import *
|
| 7 |
from utils.util_func import *
|
| 8 |
+
from safetensors.torch import load_file
|
| 9 |
|
| 10 |
db = SQLAlchemy()
|
| 11 |
login_manager = LoginManager()
|
|
|
|
| 20 |
def load_models():
|
| 21 |
global MODELS_LOADED, LONGFORMER_TOKENIZER, LONGFORMER_MODEL, QWEN_TOKENIZER, QWEN_MODEL
|
| 22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 23 |
if not MODELS_LOADED:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
LONGFORMER_TOKENIZER = LongformerTokenizer.from_pretrained('allenai/longformer-base-4096', device='auto')
|
| 25 |
config = LongformerConfig.from_json_file("Longformer_checkpoint/config.json")
|
|
|
|
| 26 |
LONGFORMER_MODEL = CustomLongformerForSequenceClassification(config).from_pretrained('SFM2001/LongFormerScorer')
|
| 27 |
LONGFORMER_MODEL = LONGFORMER_MODEL.to(device)
|
|
|
|
|
|
|
| 28 |
LONGFORMER_MODEL.eval()
|
| 29 |
+
|
| 30 |
+
model_name = 'Qwen/Qwen3-1.7B'
|
| 31 |
+
QWEN_TOKENIZER = AutoTokenizer.from_pretrained(model_name, device='auto')
|
| 32 |
+
QWEN_TOKENIZER.pad_token_id = QWEN_TOKENIZER.eos_token_id
|
| 33 |
+
QWEN_MODEL = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16).half()
|
| 34 |
MODELS_LOADED = True
|
|
|
|
|
|
|
| 35 |
|
| 36 |
def create_app():
|
| 37 |
set_seed(42)
|
| 38 |
+
load_models()
|
| 39 |
+
app = Flask(__name__)
|
| 40 |
+
app.config.from_pyfile('configs.py')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
db.init_app(app)
|
| 42 |
login_manager.init_app(app)
|
| 43 |
login_manager.login_view = 'auth.login'
|
| 44 |
+
@login_manager.user_loader
|
| 45 |
+
def load_user(user_id):
|
| 46 |
+
return User.query.get(int(user_id))
|
| 47 |
|
|
|
|
| 48 |
with app.app_context():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
from views import auth_bp, dashboard_bp, infer_bp, about_bp, error_bp
|
| 50 |
app.register_blueprint(auth_bp)
|
| 51 |
app.register_blueprint(dashboard_bp)
|
| 52 |
app.register_blueprint(infer_bp)
|
| 53 |
app.register_blueprint(about_bp)
|
| 54 |
app.register_blueprint(error_bp)
|
| 55 |
+
@app.errorhandler(Exception)
|
| 56 |
+
def handle_all_exceptions(e):
|
| 57 |
+
code = getattr(e, 'code', 500)
|
| 58 |
+
error_message = str(e) if hasattr(e, 'description') else "Something went wrong."
|
| 59 |
+
return render_template('error.html', code=code, error_message=error_message), code
|
| 60 |
+
from database import User, History
|
| 61 |
+
db.create_all()
|
| 62 |
|
| 63 |
+
return app
|
|
@@ -3,17 +3,19 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
|
| 3 |
from datetime import datetime
|
| 4 |
from create_app import db
|
| 5 |
|
|
|
|
| 6 |
class User(UserMixin, db.Model):
|
| 7 |
id = db.Column(db.Integer, primary_key=True)
|
| 8 |
email = db.Column(db.String(100), unique=True, nullable=False)
|
| 9 |
nickname = db.Column(db.String(100), unique=True, nullable=False)
|
| 10 |
-
password_hash = db.Column(db.String(
|
| 11 |
|
| 12 |
def set_password(self, password):
|
| 13 |
self.password_hash = generate_password_hash(password)
|
| 14 |
|
| 15 |
def check_password(self, password):
|
| 16 |
return check_password_hash(self.password_hash, password)
|
|
|
|
| 17 |
class History(db.Model):
|
| 18 |
id = db.Column(db.Integer, primary_key=True)
|
| 19 |
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
|
@@ -24,4 +26,4 @@ class History(db.Model):
|
|
| 24 |
score_cc = db.Column(db.Integer, nullable=False)
|
| 25 |
score_lr = db.Column(db.Integer, nullable=False)
|
| 26 |
score_gra = db.Column(db.Integer, nullable=False)
|
| 27 |
-
user = db.relationship('User', backref=db.backref('histories', lazy=True))
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
from create_app import db
|
| 5 |
|
| 6 |
+
|
| 7 |
class User(UserMixin, db.Model):
|
| 8 |
id = db.Column(db.Integer, primary_key=True)
|
| 9 |
email = db.Column(db.String(100), unique=True, nullable=False)
|
| 10 |
nickname = db.Column(db.String(100), unique=True, nullable=False)
|
| 11 |
+
password_hash = db.Column(db.String(200))
|
| 12 |
|
| 13 |
def set_password(self, password):
|
| 14 |
self.password_hash = generate_password_hash(password)
|
| 15 |
|
| 16 |
def check_password(self, password):
|
| 17 |
return check_password_hash(self.password_hash, password)
|
| 18 |
+
|
| 19 |
class History(db.Model):
|
| 20 |
id = db.Column(db.Integer, primary_key=True)
|
| 21 |
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
|
|
|
| 26 |
score_cc = db.Column(db.Integer, nullable=False)
|
| 27 |
score_lr = db.Column(db.Integer, nullable=False)
|
| 28 |
score_gra = db.Column(db.Integer, nullable=False)
|
| 29 |
+
user = db.relationship('User', backref=db.backref('histories', lazy=True))
|
|
Binary files a/inference/__pycache__/__init__.cpython-312.pyc and b/inference/__pycache__/__init__.cpython-312.pyc differ
|
|
|
|
Binary files a/inference/__pycache__/infer_single.cpython-312.pyc and b/inference/__pycache__/infer_single.cpython-312.pyc differ
|
|
|
|
Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ
|
|
|
|
Binary files a/models/__pycache__/model.cpython-312.pyc and b/models/__pycache__/model.cpython-312.pyc differ
|
|
|
|
Binary files a/utils/__pycache__/__init__.cpython-312.pyc and b/utils/__pycache__/__init__.cpython-312.pyc differ
|
|
|
|
Binary files a/utils/__pycache__/data_utils.cpython-312.pyc and b/utils/__pycache__/data_utils.cpython-312.pyc differ
|
|
|
|
Binary files a/utils/__pycache__/prompts.cpython-312.pyc and b/utils/__pycache__/prompts.cpython-312.pyc differ
|
|
|
|
Binary files a/utils/__pycache__/util_func.cpython-312.pyc and b/utils/__pycache__/util_func.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/__init__.cpython-312.pyc and b/views/__pycache__/__init__.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/about.cpython-312.pyc and b/views/__pycache__/about.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/auth.cpython-312.pyc and b/views/__pycache__/auth.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/dashboard.cpython-312.pyc and b/views/__pycache__/dashboard.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/error.cpython-312.pyc and b/views/__pycache__/error.cpython-312.pyc differ
|
|
|
|
Binary files a/views/__pycache__/infer.cpython-312.pyc and b/views/__pycache__/infer.cpython-312.pyc differ
|
|
|
|
@@ -34,9 +34,13 @@ def login():
|
|
| 34 |
if request.method == 'POST':
|
| 35 |
email = request.form['email']
|
| 36 |
password = request.form['password']
|
|
|
|
| 37 |
user = User.query.filter_by(email=email).first()
|
|
|
|
| 38 |
if user and user.check_password(password):
|
|
|
|
| 39 |
login_user(user)
|
|
|
|
| 40 |
return redirect(url_for('dashboard.dashboard'))
|
| 41 |
else:
|
| 42 |
return render_template('login.html', message="Invalid email or password.")
|
|
@@ -47,4 +51,4 @@ def login():
|
|
| 47 |
@login_required
|
| 48 |
def logout():
|
| 49 |
logout_user()
|
| 50 |
-
return redirect(url_for('auth.login'))
|
|
|
|
| 34 |
if request.method == 'POST':
|
| 35 |
email = request.form['email']
|
| 36 |
password = request.form['password']
|
| 37 |
+
print(email, password)
|
| 38 |
user = User.query.filter_by(email=email).first()
|
| 39 |
+
print(user)
|
| 40 |
if user and user.check_password(password):
|
| 41 |
+
print("LOGIN?")
|
| 42 |
login_user(user)
|
| 43 |
+
|
| 44 |
return redirect(url_for('dashboard.dashboard'))
|
| 45 |
else:
|
| 46 |
return render_template('login.html', message="Invalid email or password.")
|
|
|
|
| 51 |
@login_required
|
| 52 |
def logout():
|
| 53 |
logout_user()
|
| 54 |
+
return redirect(url_for('auth.login'))
|