Save study.db to writable /tmp or /data directory
Browse files
main.py
CHANGED
|
@@ -27,7 +27,10 @@ def read_root():
|
|
| 27 |
return RedirectResponse(url="/static/index.html")
|
| 28 |
|
| 29 |
# --- SQLite Database Setup ---
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def init_db():
|
| 33 |
conn = sqlite3.connect(DB_FILE)
|
|
|
|
| 27 |
return RedirectResponse(url="/static/index.html")
|
| 28 |
|
| 29 |
# --- SQLite Database Setup ---
|
| 30 |
+
# Hugging Face Spaces make the /app directory read-only by default.
|
| 31 |
+
# We must write the database to /data (if persistent storage is enabled) or /tmp.
|
| 32 |
+
DB_DIR = "/data" if os.path.exists("/data") else "/tmp"
|
| 33 |
+
DB_FILE = os.path.join(DB_DIR, "study.db")
|
| 34 |
|
| 35 |
def init_db():
|
| 36 |
conn = sqlite3.connect(DB_FILE)
|