Spaces:
Paused
Paused
Commit
·
e3fc741
1
Parent(s):
5ccd0e8
updated
Browse files
app.py
CHANGED
|
@@ -6,8 +6,8 @@ os.environ["HF_HOME"] = "/tmp/huggingface"
|
|
| 6 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface/transformers"
|
| 7 |
os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface/hub"
|
| 8 |
|
| 9 |
-
# Force Flask instance path to a writable
|
| 10 |
-
safe_instance_path =
|
| 11 |
os.makedirs(safe_instance_path, exist_ok=True)
|
| 12 |
|
| 13 |
from flask import Flask, render_template, redirect, url_for, flash, request
|
|
@@ -21,8 +21,6 @@ from datetime import datetime
|
|
| 21 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
sys.path.append(current_dir)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
# Import and initialize DB
|
| 27 |
from backend.models.database import db, Job, Application, init_db
|
| 28 |
from backend.models.user import User
|
|
@@ -36,40 +34,23 @@ app = Flask(
|
|
| 36 |
static_folder='backend/static',
|
| 37 |
static_url_path='/static',
|
| 38 |
template_folder='backend/templates',
|
| 39 |
-
instance_path=safe_instance_path # ✅ points to
|
| 40 |
)
|
| 41 |
|
| 42 |
-
os.makedirs(safe_instance_path, exist_ok=True)
|
| 43 |
-
|
| 44 |
-
|
| 45 |
app.config['SECRET_KEY'] = 'your-secret-key'
|
| 46 |
-
|
| 47 |
# Configure the database connection
|
| 48 |
-
#
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
# platforms like Hugging Face Spaces the `/tmp` directory is not
|
| 52 |
-
# persistent across sessions. That means any data stored in
|
| 53 |
-
# `/tmp/codingo.db` would be lost once the process restarts, and
|
| 54 |
-
# newly created user accounts would appear to disappear immediately.
|
| 55 |
-
#
|
| 56 |
-
# To fix this we store the database file inside the project under
|
| 57 |
-
# `backend/instance/codingo.db`. The `backend/instance` directory
|
| 58 |
-
# already exists (it is created by `os.makedirs` below) and is
|
| 59 |
-
# persisted across requests, so user registrations and other data
|
| 60 |
-
# remain available. SQLAlchemy requires three slashes for a relative
|
| 61 |
-
# SQLite URI (e.g. `sqlite:///relative/path.db`). Here we use four
|
| 62 |
-
# leading slashes because the path is relative to the project
|
| 63 |
-
# directory when using `sqlite:///backend/instance/codingo.db`.
|
| 64 |
-
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///codingo.db'
|
| 65 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 66 |
from flask_wtf.csrf import CSRFProtect
|
| 67 |
|
| 68 |
# csrf = CSRFProtect(app)
|
| 69 |
|
| 70 |
-
# Create necessary directories
|
| 71 |
-
os.makedirs('static/audio', exist_ok=True)
|
| 72 |
-
os.makedirs('temp', exist_ok=True)
|
| 73 |
|
| 74 |
# Initialize DB with app
|
| 75 |
init_db(app)
|
|
@@ -94,7 +75,7 @@ def handle_resume_upload(file):
|
|
| 94 |
|
| 95 |
try:
|
| 96 |
filename = secure_filename(file.filename)
|
| 97 |
-
temp_dir =
|
| 98 |
os.makedirs(temp_dir, exist_ok=True)
|
| 99 |
filepath = os.path.join(temp_dir, filename)
|
| 100 |
|
|
|
|
| 6 |
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface/transformers"
|
| 7 |
os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface/hub"
|
| 8 |
|
| 9 |
+
# Force Flask instance path to a writable temporary folder
|
| 10 |
+
safe_instance_path = "/tmp/flask_instance"
|
| 11 |
os.makedirs(safe_instance_path, exist_ok=True)
|
| 12 |
|
| 13 |
from flask import Flask, render_template, redirect, url_for, flash, request
|
|
|
|
| 21 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
sys.path.append(current_dir)
|
| 23 |
|
|
|
|
|
|
|
| 24 |
# Import and initialize DB
|
| 25 |
from backend.models.database import db, Job, Application, init_db
|
| 26 |
from backend.models.user import User
|
|
|
|
| 34 |
static_folder='backend/static',
|
| 35 |
static_url_path='/static',
|
| 36 |
template_folder='backend/templates',
|
| 37 |
+
instance_path=safe_instance_path # ✅ points to writable '/tmp/flask_instance'
|
| 38 |
)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
| 40 |
app.config['SECRET_KEY'] = 'your-secret-key'
|
| 41 |
+
|
| 42 |
# Configure the database connection
|
| 43 |
+
# Use /tmp directory for database in Hugging Face Spaces
|
| 44 |
+
# Note: Data will be lost when the space restarts
|
| 45 |
+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/codingo.db'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
| 47 |
from flask_wtf.csrf import CSRFProtect
|
| 48 |
|
| 49 |
# csrf = CSRFProtect(app)
|
| 50 |
|
| 51 |
+
# Create necessary directories in writable locations
|
| 52 |
+
os.makedirs('/tmp/static/audio', exist_ok=True)
|
| 53 |
+
os.makedirs('/tmp/temp', exist_ok=True)
|
| 54 |
|
| 55 |
# Initialize DB with app
|
| 56 |
init_db(app)
|
|
|
|
| 75 |
|
| 76 |
try:
|
| 77 |
filename = secure_filename(file.filename)
|
| 78 |
+
temp_dir = '/tmp/temp' # Use /tmp for temporary files
|
| 79 |
os.makedirs(temp_dir, exist_ok=True)
|
| 80 |
filepath = os.path.join(temp_dir, filename)
|
| 81 |
|