hailey2024 commited on
Commit
f33202d
·
1 Parent(s): 6a612eb

use data dir for db

Browse files
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
- """Commit and push the database to the repository."""
139
- space_id = os.getenv('SPACE_ID', None)
140
- if not space_id:
141
- return
142
-
143
- try:
144
- repo_root = subprocess.run(
145
- ['git', 'rev-parse', '--show-toplevel'],
146
- check=True,
147
- capture_output=True,
148
- text=True,
149
- ).stdout.strip()
150
-
151
- ts = _get_time_now()
152
- db_rel = os.path.relpath(self.db_path, repo_root)
153
- subprocess.run(['git', 'add', db_rel], check=True, cwd=repo_root)
154
- api = HfApi(token=os.getenv('HF_TOKEN', None))
155
- api.create_commit(
156
- repo_id='JaneDing2025/IconEval',
157
- repo_type='space',
158
- operations=[CommitOperationAdd(path_in_repo=db_rel, path_or_fileobj=self.db_path)],
159
- commit_message=f'update db {ts}',
160
- )
161
- except Exception as e:
162
- raise RuntimeError(f'Failed to commit and push the database: {e}')
 
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
- 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
 
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