Spaces:
Sleeping
Sleeping
Commit
·
f33202d
1
Parent(s):
6a612eb
use data dir for db
Browse files- app.py +1 -1
- eval_round_r1.db → data/eval_round_r1.db +0 -0
- src/database.py +27 -30
- src/eval_server.py +9 -9
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from src.eval_server import app_main
|
|
| 8 |
|
| 9 |
REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
|
| 11 |
-
DB_PATH = os.path.join(REPO_ROOT, 'eval_round_r1.db')
|
| 12 |
IMAGE_TEMPLATE = os.path.join(REPO_ROOT, 'images', '{label}', '{path}')
|
| 13 |
REDUNDANCY = int(os.environ['REDUNDANCY'])
|
| 14 |
ALLOWED_USERS_STR = os.environ['ALLOW_USERS']
|
|
|
|
| 8 |
|
| 9 |
REPO_ROOT = os.path.dirname(os.path.abspath(__file__))
|
| 10 |
|
| 11 |
+
DB_PATH = os.path.join(REPO_ROOT, 'data', 'eval_round_r1.db')
|
| 12 |
IMAGE_TEMPLATE = os.path.join(REPO_ROOT, 'images', '{label}', '{path}')
|
| 13 |
REDUNDANCY = int(os.environ['REDUNDANCY'])
|
| 14 |
ALLOWED_USERS_STR = os.environ['ALLOW_USERS']
|
eval_round_r1.db → data/eval_round_r1.db
RENAMED
|
File without changes
|
src/database.py
CHANGED
|
@@ -3,14 +3,11 @@
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import sqlite3
|
| 6 |
-
import subprocess
|
| 7 |
import threading
|
| 8 |
from contextlib import contextmanager
|
| 9 |
from datetime import datetime, timezone
|
| 10 |
from typing import Optional
|
| 11 |
|
| 12 |
-
from huggingface_hub import CommitOperationAdd, HfApi
|
| 13 |
-
|
| 14 |
REQUIRED_TABLES = ('tasks', 'assignments', 'task_config', 'answers', 'allocation_history')
|
| 15 |
|
| 16 |
|
|
@@ -133,30 +130,30 @@ class DB:
|
|
| 133 |
)
|
| 134 |
return cur.rowcount or 0
|
| 135 |
|
| 136 |
-
# ========== Auto Commit (For HF Spaces) ==========
|
| 137 |
-
def commit_and_push_db(self) -> None:
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import sqlite3
|
|
|
|
| 6 |
import threading
|
| 7 |
from contextlib import contextmanager
|
| 8 |
from datetime import datetime, timezone
|
| 9 |
from typing import Optional
|
| 10 |
|
|
|
|
|
|
|
| 11 |
REQUIRED_TABLES = ('tasks', 'assignments', 'task_config', 'answers', 'allocation_history')
|
| 12 |
|
| 13 |
|
|
|
|
| 130 |
)
|
| 131 |
return cur.rowcount or 0
|
| 132 |
|
| 133 |
+
# # ========== Auto Commit (For HF Spaces) ==========
|
| 134 |
+
# def commit_and_push_db(self) -> None:
|
| 135 |
+
# """Commit and push the database to the repository."""
|
| 136 |
+
# space_id = os.getenv('SPACE_ID', None)
|
| 137 |
+
# if not space_id:
|
| 138 |
+
# return
|
| 139 |
+
|
| 140 |
+
# try:
|
| 141 |
+
# repo_root = subprocess.run(
|
| 142 |
+
# ['git', 'rev-parse', '--show-toplevel'],
|
| 143 |
+
# check=True,
|
| 144 |
+
# capture_output=True,
|
| 145 |
+
# text=True,
|
| 146 |
+
# ).stdout.strip()
|
| 147 |
+
|
| 148 |
+
# ts = _get_time_now()
|
| 149 |
+
# db_rel = os.path.relpath(self.db_path, repo_root)
|
| 150 |
+
# subprocess.run(['git', 'add', db_rel], check=True, cwd=repo_root)
|
| 151 |
+
# api = HfApi(token=os.getenv('HF_TOKEN', None))
|
| 152 |
+
# api.create_commit(
|
| 153 |
+
# repo_id='JaneDing2025/IconEval',
|
| 154 |
+
# repo_type='space',
|
| 155 |
+
# operations=[CommitOperationAdd(path_in_repo=db_rel, path_or_fileobj=self.db_path)],
|
| 156 |
+
# commit_message=f'update db {ts}',
|
| 157 |
+
# )
|
| 158 |
+
# except Exception as e:
|
| 159 |
+
# raise RuntimeError(f'Failed to commit and push the database: {e}')
|
src/eval_server.py
CHANGED
|
@@ -480,15 +480,15 @@ def app_main(args) -> None:
|
|
| 480 |
)
|
| 481 |
|
| 482 |
# db auto commit
|
| 483 |
-
if (
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
):
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
|
| 493 |
if current_idx_in_list is None or current_idx_in_list >= len(items_list) - 1:
|
| 494 |
# This was the last item - show completion message but stay on current item
|
|
|
|
| 480 |
)
|
| 481 |
|
| 482 |
# db auto commit
|
| 483 |
+
# if (
|
| 484 |
+
# args.auto_commit > 0
|
| 485 |
+
# and current_idx_in_list is not None
|
| 486 |
+
# and (current_idx_in_list + 1) % args.auto_commit == 0
|
| 487 |
+
# ):
|
| 488 |
+
# try:
|
| 489 |
+
# db.commit_and_push_db()
|
| 490 |
+
# except Exception as e:
|
| 491 |
+
# print(f'Failed to commit and push the database: {e}')
|
| 492 |
|
| 493 |
if current_idx_in_list is None or current_idx_in_list >= len(items_list) - 1:
|
| 494 |
# This was the last item - show completion message but stay on current item
|