Jayce-Ping commited on
Commit
0ce0b49
·
verified ·
1 Parent(s): ce02331

Add files using upload-large-folder tool

Browse files
annotator/__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/annotator/__pycache__/utils.cpython-312.pyc and b/annotator/__pycache__/utils.cpython-312.pyc differ
 
annotator/__pycache__/utils.cpython-38.pyc ADDED
Binary file (608 Bytes). View file
 
annotator/annotate.py CHANGED
@@ -2,26 +2,53 @@ import os
2
  import json
3
  from datetime import datetime
4
  from utils import divide_prompt
 
5
  from flask import Flask, render_template, request, send_from_directory, jsonify
6
 
7
  app = Flask(__name__)
8
 
 
 
9
  # 设置图像目录路径
10
- IMAGE_DIR = "../images_divided"
11
  ITEMS_PER_PAGE = 1 # 每页显示的 data 项目数
12
- DATA_FILE = "data/annotation.jsonl" # 保存排序结果的文件
13
- PROMPT_DATA_FILE = 'data/extended_data_summary_v2.jsonl'
14
 
15
  with open(PROMPT_DATA_FILE, 'r', encoding='utf-8') as f:
16
  PROMPT_DATA = [json.loads(line) for line in f if line.strip()]
17
  PROMPT_DATA = {item['idx']: item for item in PROMPT_DATA}
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  @app.route('/')
20
  def index():
21
  # 读取所有文件夹
 
 
 
 
22
  folders = sorted([
23
- f for f in os.listdir(IMAGE_DIR)
24
- if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')
25
  ])
26
  data = []
27
 
@@ -31,12 +58,9 @@ def index():
31
  for record in existing_records:
32
  folder = record.get('folder')
33
  ref_image = record.get('ref_image')
34
- compare_images = tuple(sorted(record.get('compare_images', []))) # 使用排序后的元组作为键的一部分
35
  key = (folder, ref_image, compare_images)
36
- existing_dict[key] = {
37
- 'compare_images': record.get('compare_images', []),
38
- 'rank_images': record.get('rank_images', [])
39
- }
40
 
41
  for cnt, idx in enumerate(folders):
42
  folder_path = os.path.join(IMAGE_DIR, idx)
@@ -59,39 +83,59 @@ def index():
59
  for y in second_indices if y != j
60
  ]
61
 
62
- items = [
63
- {
 
64
  'ref_image': f"/images/{idx}/{ref_img}",
65
- 'compare_images': [f"/images/{idx}/{cand_img}" for cand_img in cand], # 待比较的图像列表
66
  'folder': idx,
67
  'ref_index': (i, j),
68
  'candidate_column': y,
69
  'prompt': divide_prompt(PROMPT_DATA[idx]['prompt'])[0] if idx in PROMPT_DATA and 'prompt' in PROMPT_DATA[idx] else '',
70
- 'existing_compare_images': [], # 临时占位,后面会更新
71
- 'existing_rank_images': [], # 临时占位,后面会更新
72
- 'is_annotated': False, # 临时占位,后面会更新
73
- } for y, cand in zip([y for y in second_indices if y != j], candidates)
74
- ]
75
-
76
- # 对每个 item 检查是否已有标注
77
- for item in items:
78
- # 从完整路径中提取文件名
79
  current_compare_images = [img.split('/')[-1] for img in item['compare_images']]
80
-
81
- # 检查是否已有标注(使用 ref_image 和 compare_images 一起判定)
82
  ref_filename = item['ref_image'].split('/')[-1]
83
  lookup_key = (idx, ref_filename, tuple(sorted(current_compare_images)))
84
  existing_data = existing_dict.get(lookup_key, {})
85
 
86
- # 更新 item 的标注信息
87
  item['existing_compare_images'] = existing_data.get('compare_images', [])
88
  item['existing_rank_images'] = existing_data.get('rank_images', [])
89
- item['is_annotated'] = len(existing_data.get('rank_images', [])) > 0
 
 
 
 
90
 
91
  data.extend(items)
92
 
93
- # 分页逻辑
94
- page = int(request.args.get('page', 1))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  start = (page - 1) * ITEMS_PER_PAGE
96
  end = start + ITEMS_PER_PAGE
97
  paginated_data = data[start:end]
@@ -103,135 +147,252 @@ def index():
103
  total_pages=(len(data) + ITEMS_PER_PAGE - 1) // ITEMS_PER_PAGE
104
  )
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  @app.route('/sort', methods=['POST'])
107
  def sort_images():
108
  try:
109
- # 获取排序后的数据
110
  sorted_images = request.form.getlist('sorted_images')
111
-
112
  if not sorted_images:
113
  return jsonify({'status': 'error', 'message': '没有排序数据'}), 400
114
 
115
- # 解析排序数据
116
  ranking = []
117
  for item in sorted_images:
118
  rank, image_path = item.split(':', 1)
119
- ranking.append({
120
- 'rank': int(rank),
121
- 'image_path': image_path
122
- })
123
-
124
- # 排序以确保顺序正确
125
  ranking.sort(key=lambda x: x['rank'])
126
 
127
- # 提取有用信息
128
  if ranking:
129
  first_image = ranking[0]['image_path']
130
  parts = first_image.split('/')
131
- folder = parts[2] # folder_name
132
-
133
- # 获取参考图像信息(从表单中)
134
  ref_image = request.form.get('ref_image', '')
135
-
136
- # 解析参考图像文件名
137
- ref_filename = ref_image.split('/')[-1] # x_y.png
138
-
139
- # 获取原始的 compare_images(所有候选图像的原始顺序)
140
  all_compare_images = request.form.get('all_compare_images', '')
141
  if all_compare_images:
142
  all_compare_images = json.loads(all_compare_images)
143
  else:
144
  all_compare_images = []
 
145
 
146
- # 解析排序图像的文件名 - 这是用户的排序结果
147
- ranked_filenames = []
148
- for item in ranking:
149
- filename = item['image_path'].split('/')[-1]
150
- ranked_filenames.append(filename)
151
-
152
- # 创建唯一的数据记录
153
  record = {
154
  'folder': folder,
155
  'ref_image': ref_filename,
156
- 'compare_images': all_compare_images, # 原始顺序的所有候选图像
157
- 'rank_images': ranked_filenames, # 用户的排序结果
158
  'timestamp': datetime.now().isoformat()
159
  }
160
 
161
- # 读取现有数据以检查唯一性
162
  existing_records = load_existing_records()
163
-
164
- # 检查是否已存在相同的记录(基于 folder, ref_image 和 compare_images)
165
  updated = False
166
  for i, existing in enumerate(existing_records):
167
- existing_compare_sorted = tuple(sorted(existing.get('compare_images', [])))
168
- current_compare_sorted = tuple(sorted(all_compare_images))
169
-
170
  if (existing.get('folder') == folder and
171
  existing.get('ref_image') == ref_filename and
172
- existing_compare_sorted == current_compare_sorted):
173
- # 更新现有记录
 
 
174
  existing_records[i] = record
175
  updated = True
176
  break
177
 
178
  if not updated:
179
- # 添加新记录
 
 
180
  existing_records.append(record)
181
 
182
- # 保存到文件
183
  save_records(existing_records)
184
-
185
- print(f"{'更新' if updated else '添加'}排序记录:", record)
186
-
187
- return jsonify({
188
- 'status': 'success',
189
- 'message': f"排序已{'更新' if updated else '保存'}!",
190
- 'record': record
191
- })
192
 
193
  except Exception as e:
194
- print(f"错误: {str(e)}")
195
- import traceback
196
- traceback.print_exc()
197
  return jsonify({'status': 'error', 'message': str(e)}), 500
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  def load_existing_records():
200
- """加载现有的记录"""
201
  if not os.path.exists(DATA_FILE):
202
  return []
203
-
204
  records = []
205
  with open(DATA_FILE, 'r', encoding='utf-8') as f:
206
  for line in f:
207
- line = line.strip()
208
- if line:
209
  records.append(json.loads(line))
 
 
210
  return records
211
 
212
  def save_records(records):
213
- """保存记录到JSONL文件"""
214
- # 确保目录存在
215
- os.makedirs(os.path.dirname(DATA_FILE), exist_ok=True)
216
-
217
  with open(DATA_FILE, 'w', encoding='utf-8') as f:
218
  for record in records:
219
  f.write(json.dumps(record, ensure_ascii=False) + '\n')
220
 
221
- # 添加一个路由来提供图片文件
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  @app.route('/images/<path:filename>')
223
- def serve_images(filename):
224
  return send_from_directory(IMAGE_DIR, filename)
225
 
226
- # 添加一个查看已保存数据的路由
227
  @app.route('/view_data')
228
  def view_data():
229
- """查看已保存的排序数据"""
230
- records = load_existing_records()
231
- return jsonify({
232
- 'total': len(records),
233
- 'records': records
234
- })
 
 
 
235
 
236
  if __name__ == '__main__':
237
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import json
3
  from datetime import datetime
4
  from utils import divide_prompt
5
+ import argparse
6
  from flask import Flask, render_template, request, send_from_directory, jsonify
7
 
8
  app = Flask(__name__)
9
 
10
+ FILE_PATH = os.path.dirname(os.path.abspath(__file__))
11
+
12
  # 设置图像目录路径
13
+ IMAGE_DIR = os.path.join(FILE_PATH, "../images_divided")
14
  ITEMS_PER_PAGE = 1 # 每页显示的 data 项目数
15
+ # PROMPT_DATA_FILE = os.path.join(FILE_PATH, 'data/extended_data_summary_v2.jsonl')
16
+ PROMPT_DATA_FILE = os.path.join(FILE_PATH, 'data/2by2_data_summary.jsonl')
17
 
18
  with open(PROMPT_DATA_FILE, 'r', encoding='utf-8') as f:
19
  PROMPT_DATA = [json.loads(line) for line in f if line.strip()]
20
  PROMPT_DATA = {item['idx']: item for item in PROMPT_DATA}
21
 
22
+ def load_metadata():
23
+ """加载用户的元数据"""
24
+ if not os.path.exists(METADATA_FILE):
25
+ return {"last_page": None, "last_updated": None}
26
+ try:
27
+ with open(METADATA_FILE, 'r', encoding='utf-8') as f:
28
+ return json.load(f)
29
+ except:
30
+ return {"last_page": None, "last_updated": None}
31
+
32
+ def save_metadata(page):
33
+ """保存当前页码到元数据文件"""
34
+ metadata = {
35
+ "last_page": page,
36
+ "last_updated": datetime.now().isoformat()
37
+ }
38
+ os.makedirs(os.path.dirname(METADATA_FILE), exist_ok=True)
39
+ with open(METADATA_FILE, 'w', encoding='utf-8') as f:
40
+ json.dump(metadata, f, ensure_ascii=False, indent=2)
41
+
42
  @app.route('/')
43
  def index():
44
  # 读取所有文件夹
45
+ # folders = sorted([
46
+ # f for f in os.listdir(IMAGE_DIR)
47
+ # if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')
48
+ # ])
49
  folders = sorted([
50
+ idx for idx in PROMPT_DATA.keys()
51
+ if os.path.isdir(os.path.join(IMAGE_DIR, idx))
52
  ])
53
  data = []
54
 
 
58
  for record in existing_records:
59
  folder = record.get('folder')
60
  ref_image = record.get('ref_image')
61
+ compare_images = tuple(sorted(record.get('compare_images', [])))
62
  key = (folder, ref_image, compare_images)
63
+ existing_dict[key] = record
 
 
 
64
 
65
  for cnt, idx in enumerate(folders):
66
  folder_path = os.path.join(IMAGE_DIR, idx)
 
83
  for y in second_indices if y != j
84
  ]
85
 
86
+ items = []
87
+ for y, cand in zip([y for y in second_indices if y != j], candidates):
88
+ item = {
89
  'ref_image': f"/images/{idx}/{ref_img}",
90
+ 'compare_images': [f"/images/{idx}/{cand_img}" for cand_img in cand],
91
  'folder': idx,
92
  'ref_index': (i, j),
93
  'candidate_column': y,
94
  'prompt': divide_prompt(PROMPT_DATA[idx]['prompt'])[0] if idx in PROMPT_DATA and 'prompt' in PROMPT_DATA[idx] else '',
95
+ 'existing_compare_images': [],
96
+ 'existing_rank_images': [],
97
+ 'is_annotated': False,
98
+ 'stared': False,
99
+ 'discarded': False,
100
+ 'grid_issue': False
101
+ }
 
 
102
  current_compare_images = [img.split('/')[-1] for img in item['compare_images']]
 
 
103
  ref_filename = item['ref_image'].split('/')[-1]
104
  lookup_key = (idx, ref_filename, tuple(sorted(current_compare_images)))
105
  existing_data = existing_dict.get(lookup_key, {})
106
 
 
107
  item['existing_compare_images'] = existing_data.get('compare_images', [])
108
  item['existing_rank_images'] = existing_data.get('rank_images', [])
109
+ item['is_annotated'] = len(item['existing_rank_images']) > 0
110
+ item['stared'] = existing_data.get('stared', False)
111
+ item['discarded'] = existing_data.get('discarded', False)
112
+ item['grid_issue'] = existing_data.get('grid_issue', False)
113
+ items.append(item)
114
 
115
  data.extend(items)
116
 
117
+ # 获取页码参数,优先级:URL参数 > 元数据文件 > start_idx配置 > 默认1
118
+ url_page = request.args.get('page')
119
+ if url_page:
120
+ # 如果URL明确指定了页码,使用URL的页码
121
+ page = int(url_page)
122
+ else:
123
+ metadata = load_metadata()
124
+ last_page = metadata.get('last_page', None)
125
+ if last_page:
126
+ # 如果元数据文件中有记录,使用元数据中的页码
127
+ page = last_page
128
+ elif not app.config.get('START_IDX_USED', False):
129
+ # 如果start_idx还没被使用过,使用start_idx
130
+ page = app.config.get('START_IDX', 1)
131
+ app.config['START_IDX_USED'] = True
132
+ else:
133
+ # 否则使用默认页码1
134
+ page = 1
135
+
136
+ # 保存当前页码到元数据
137
+ save_metadata(page)
138
+
139
  start = (page - 1) * ITEMS_PER_PAGE
140
  end = start + ITEMS_PER_PAGE
141
  paginated_data = data[start:end]
 
147
  total_pages=(len(data) + ITEMS_PER_PAGE - 1) // ITEMS_PER_PAGE
148
  )
149
 
150
+ @app.route('/update_page', methods=['POST'])
151
+ def update_page():
152
+ """更新当前页码到元数据文件"""
153
+ try:
154
+ data = request.get_json()
155
+ page = data.get('page')
156
+ if page:
157
+ save_metadata(int(page))
158
+ return jsonify({'status': 'success'})
159
+ return jsonify({'status': 'error', 'message': '无效的页码'}), 400
160
+ except Exception as e:
161
+ return jsonify({'status': 'error', 'message': str(e)}), 500
162
+
163
  @app.route('/sort', methods=['POST'])
164
  def sort_images():
165
  try:
 
166
  sorted_images = request.form.getlist('sorted_images')
 
167
  if not sorted_images:
168
  return jsonify({'status': 'error', 'message': '没有排序数据'}), 400
169
 
 
170
  ranking = []
171
  for item in sorted_images:
172
  rank, image_path = item.split(':', 1)
173
+ ranking.append({'rank': int(rank), 'image_path': image_path})
 
 
 
 
 
174
  ranking.sort(key=lambda x: x['rank'])
175
 
 
176
  if ranking:
177
  first_image = ranking[0]['image_path']
178
  parts = first_image.split('/')
179
+ folder = parts[2]
 
 
180
  ref_image = request.form.get('ref_image', '')
181
+ ref_filename = ref_image.split('/')[-1]
 
 
 
 
182
  all_compare_images = request.form.get('all_compare_images', '')
183
  if all_compare_images:
184
  all_compare_images = json.loads(all_compare_images)
185
  else:
186
  all_compare_images = []
187
+ ranked_filenames = [item['image_path'].split('/')[-1] for item in ranking]
188
 
 
 
 
 
 
 
 
189
  record = {
190
  'folder': folder,
191
  'ref_image': ref_filename,
192
+ 'compare_images': all_compare_images,
193
+ 'rank_images': ranked_filenames,
194
  'timestamp': datetime.now().isoformat()
195
  }
196
 
 
197
  existing_records = load_existing_records()
 
 
198
  updated = False
199
  for i, existing in enumerate(existing_records):
 
 
 
200
  if (existing.get('folder') == folder and
201
  existing.get('ref_image') == ref_filename and
202
+ tuple(sorted(existing.get('compare_images', []))) == tuple(sorted(all_compare_images))):
203
+ record['stared'] = existing.get('stared', False)
204
+ record['discarded'] = existing.get('discarded', False)
205
+ record['grid_issue'] = existing.get('grid_issue', False)
206
  existing_records[i] = record
207
  updated = True
208
  break
209
 
210
  if not updated:
211
+ record['stared'] = False
212
+ record['discarded'] = False
213
+ record['grid_issue'] = False
214
  existing_records.append(record)
215
 
 
216
  save_records(existing_records)
217
+ return jsonify({'status': 'success','message': f"排序已{'更新' if updated else '保存'}!",'record': record})
 
 
 
 
 
 
 
218
 
219
  except Exception as e:
 
 
 
220
  return jsonify({'status': 'error', 'message': str(e)}), 500
221
 
222
+ @app.route('/star', methods=['POST'])
223
+ def star_image():
224
+ try:
225
+ data = request.get_json()
226
+ folder = data.get("folder")
227
+ ref_image = data.get("ref_image")
228
+ stared = data.get("stared", False)
229
+ compare_images = data.get("compare_images", [])
230
+ rank_images = data.get("rank_images", [])
231
+
232
+ existing_records = load_existing_records()
233
+ updated = False
234
+
235
+ for record in existing_records:
236
+ if (record.get("folder") == folder and
237
+ record.get("ref_image") == ref_image and
238
+ tuple(sorted(record.get("compare_images", []))) == tuple(sorted(compare_images))):
239
+ record["stared"] = stared
240
+ if rank_images:
241
+ record["rank_images"] = rank_images
242
+ record["timestamp"] = datetime.now().isoformat()
243
+ updated = True
244
+ break
245
+
246
+ if not updated:
247
+ new_record = {
248
+ "folder": folder,
249
+ "ref_image": ref_image,
250
+ "compare_images": compare_images,
251
+ "rank_images": rank_images,
252
+ "stared": stared,
253
+ "timestamp": datetime.now().isoformat()
254
+ }
255
+ existing_records.append(new_record)
256
+
257
+ save_records(existing_records)
258
+ return jsonify({"status": "success", "message": f"{'已收藏' if stared else '已取消收藏'}"})
259
+ except Exception as e:
260
+ print(f"Error in star_image: {str(e)}")
261
+ return jsonify({"status": "error", "message": str(e)}), 500
262
+
263
+ @app.route('/discard', methods=['POST'])
264
+ def discard_image():
265
+ try:
266
+ data = request.get_json()
267
+ folder = data.get("folder")
268
+ ref_image = data.get("ref_image")
269
+ discarded = data.get("discarded", False)
270
+ compare_images = data.get("compare_images", [])
271
+ rank_images = data.get("rank_images", [])
272
+
273
+ existing_records = load_existing_records()
274
+ updated = False
275
+
276
+ for record in existing_records:
277
+ if (record.get("folder") == folder and
278
+ record.get("ref_image") == ref_image and
279
+ tuple(sorted(record.get("compare_images", []))) == tuple(sorted(compare_images))):
280
+ record["discarded"] = discarded
281
+ if rank_images:
282
+ record["rank_images"] = rank_images
283
+ record["timestamp"] = datetime.now().isoformat()
284
+ updated = True
285
+ break
286
+
287
+ if not updated:
288
+ new_record = {
289
+ "folder": folder,
290
+ "ref_image": ref_image,
291
+ "compare_images": compare_images,
292
+ "rank_images": rank_images,
293
+ "discarded": discarded,
294
+ "timestamp": datetime.now().isoformat()
295
+ }
296
+ existing_records.append(new_record)
297
+
298
+ save_records(existing_records)
299
+ return jsonify({"status": "success", "message": f"{'已丢弃' if discarded else '已取消丢弃'}"})
300
+ except Exception as e:
301
+ print(f"Error in discard_image: {str(e)}")
302
+ return jsonify({"status": "error", "message": str(e)}), 500
303
+
304
  def load_existing_records():
 
305
  if not os.path.exists(DATA_FILE):
306
  return []
 
307
  records = []
308
  with open(DATA_FILE, 'r', encoding='utf-8') as f:
309
  for line in f:
310
+ try:
 
311
  records.append(json.loads(line))
312
+ except json.JSONDecodeError:
313
+ continue
314
  return records
315
 
316
  def save_records(records):
 
 
 
 
317
  with open(DATA_FILE, 'w', encoding='utf-8') as f:
318
  for record in records:
319
  f.write(json.dumps(record, ensure_ascii=False) + '\n')
320
 
321
+ @app.route('/grid_issue', methods=['POST'])
322
+ def grid_issue_image():
323
+ try:
324
+ data = request.get_json()
325
+ folder = data.get("folder")
326
+ ref_image = data.get("ref_image")
327
+ grid_issue = data.get("grid_issue", False)
328
+ compare_images = data.get("compare_images", [])
329
+ rank_images = data.get("rank_images", [])
330
+
331
+ existing_records = load_existing_records()
332
+ updated = False
333
+
334
+ for record in existing_records:
335
+ if (record.get("folder") == folder and
336
+ record.get("ref_image") == ref_image and
337
+ tuple(sorted(record.get("compare_images", []))) == tuple(sorted(compare_images))):
338
+ record["grid_issue"] = grid_issue
339
+ if rank_images:
340
+ record["rank_images"] = rank_images
341
+ record["timestamp"] = datetime.now().isoformat()
342
+ updated = True
343
+ break
344
+
345
+ if not updated:
346
+ new_record = {
347
+ "folder": folder,
348
+ "ref_image": ref_image,
349
+ "compare_images": compare_images,
350
+ "rank_images": rank_images,
351
+ "grid_issue": grid_issue,
352
+ "timestamp": datetime.now().isoformat()
353
+ }
354
+ existing_records.append(new_record)
355
+
356
+ save_records(existing_records)
357
+ return jsonify({"status": "success", "message": f"{'已标记网格问题' if grid_issue else '已取消网格问题标记'}"})
358
+ except Exception as e:
359
+ print(f"Error in grid_issue_image: {str(e)}")
360
+ return jsonify({"status": "error", "message": str(e)}), 500
361
+
362
  @app.route('/images/<path:filename>')
363
+ def images(filename):
364
  return send_from_directory(IMAGE_DIR, filename)
365
 
 
366
  @app.route('/view_data')
367
  def view_data():
368
+ existing_records = load_existing_records()
369
+ return jsonify(existing_records)
370
+
371
+ def parse_args():
372
+ parser = argparse.ArgumentParser(description="Run the annotation server.")
373
+ parser.add_argument('--port', type=str, default='5000', help='Host address to run the server on')
374
+ parser.add_argument('--user', type=str, default='user', help='User name for the session')
375
+ parser.add_argument('--start_idx', type=int, default=1, help='Starting page index for initialization')
376
+ return parser.parse_args()
377
 
378
  if __name__ == '__main__':
379
+ args = parse_args()
380
+ user = args.user
381
+ port = int(args.port)
382
+ start_idx = args.start_idx
383
+
384
+ global DATA_FILE, METADATA_FILE
385
+ DATA_FILE = os.path.join(FILE_PATH, "data", f"annotation_{user}.jsonl")
386
+ METADATA_FILE = os.path.join(FILE_PATH, "data", f"metadata_{user}.json")
387
+
388
+ # 将start_idx存储到app配置中
389
+ app.config['START_IDX'] = start_idx
390
+
391
+ print(f"启动服务器:")
392
+ print(f" 用户: {user}")
393
+ print(f" 端口: {port}")
394
+ print(f" 起始页码: {start_idx}")
395
+ print(f" 数据文件: {DATA_FILE}")
396
+ print(f" 元数据文件: {METADATA_FILE}")
397
+
398
+ app.run(debug=True, port=port)
annotator/data/2by2_data_summary.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
annotator/data/annotation_jcy.jsonl ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"folder": "1191", "ref_image": "3_5.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "timestamp": "2025-10-03T13:02:28.341510", "stared": false, "discarded": false, "grid_issue": false}
2
+ {"folder": "0857", "ref_image": "2_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["0_1.png", "2_1.png", "1_1.png", "3_1.png"], "timestamp": "2025-10-03T21:49:59.362507", "stared": false, "discarded": false, "grid_issue": false}
3
+ {"folder": "0857", "ref_image": "2_0.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["2_3.png", "1_3.png", "3_3.png", "0_3.png"], "timestamp": "2025-10-03T21:53:25.454401", "stared": false, "discarded": false, "grid_issue": false}
4
+ {"folder": "0857", "ref_image": "2_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "1_0.png", "0_0.png", "3_0.png"], "timestamp": "2025-10-03T21:54:09.560820", "stared": false, "discarded": false, "grid_issue": false}
5
+ {"folder": "0857", "ref_image": "2_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["2_2.png", "1_2.png", "3_2.png", "0_2.png"], "timestamp": "2025-10-03T21:54:30.138636", "stared": false, "discarded": false, "grid_issue": false}
6
+ {"folder": "0857", "ref_image": "2_1.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["2_3.png", "1_3.png", "3_3.png", "0_3.png"], "timestamp": "2025-10-03T21:55:22.814752", "stared": false, "discarded": false, "grid_issue": false}
7
+ {"folder": "0857", "ref_image": "2_2.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "1_0.png", "3_0.png", "0_0.png"], "timestamp": "2025-10-03T21:55:41.729521", "stared": false, "discarded": false, "grid_issue": false}
8
+ {"folder": "0857", "ref_image": "2_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["2_1.png", "1_1.png", "0_1.png", "3_1.png"], "timestamp": "2025-10-03T21:55:59.291103", "stared": false, "discarded": false, "grid_issue": false}
9
+ {"folder": "0857", "ref_image": "2_2.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["1_3.png", "2_3.png", "0_3.png", "3_3.png"], "timestamp": "2025-10-03T21:56:23.223379", "stared": false, "discarded": false, "grid_issue": false}
10
+ {"folder": "0857", "ref_image": "2_3.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "1_0.png", "3_0.png", "0_0.png"], "timestamp": "2025-10-03T21:58:00.541402", "stared": false, "discarded": false, "grid_issue": false}
11
+ {"folder": "0857", "ref_image": "2_3.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["2_1.png", "1_1.png", "0_1.png", "3_1.png"], "timestamp": "2025-10-03T21:58:14.974827", "stared": false, "discarded": false, "grid_issue": false}
12
+ {"folder": "0857", "ref_image": "2_3.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["2_2.png", "1_2.png", "3_2.png", "0_2.png"], "timestamp": "2025-10-03T21:58:30.908891", "stared": false, "discarded": false, "grid_issue": false}
13
+ {"folder": "0857", "ref_image": "3_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["3_1.png", "0_1.png", "1_1.png", "2_1.png"], "timestamp": "2025-10-03T21:58:54.567588", "stared": false, "discarded": false, "grid_issue": false}
14
+ {"folder": "0857", "ref_image": "3_0.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["3_2.png", "1_2.png", "2_2.png", "0_2.png"], "timestamp": "2025-10-03T21:59:14.418967", "stared": false, "discarded": false, "grid_issue": false}
15
+ {"folder": "0857", "ref_image": "3_0.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "1_3.png", "3_3.png", "2_3.png"], "timestamp": "2025-10-03T21:59:35.663823", "stared": false, "discarded": false, "grid_issue": false}
16
+ {"folder": "0857", "ref_image": "3_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "1_0.png", "3_0.png", "0_0.png"], "timestamp": "2025-10-03T21:59:52.769238", "stared": false, "discarded": false, "grid_issue": false}
17
+ {"folder": "0857", "ref_image": "3_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["2_2.png", "1_2.png", "3_2.png", "0_2.png"], "timestamp": "2025-10-03T22:00:08.141177", "stared": false, "discarded": false, "grid_issue": false}
18
+ {"folder": "0857", "ref_image": "3_1.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["3_3.png", "0_3.png", "1_3.png", "2_3.png"], "timestamp": "2025-10-03T22:00:24.770808", "stared": false, "discarded": false, "grid_issue": false}
19
+ {"folder": "0857", "ref_image": "3_2.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["3_0.png", "1_0.png", "2_0.png", "0_0.png"], "timestamp": "2025-10-03T22:00:42.386253", "stared": false, "discarded": false, "grid_issue": false}
20
+ {"folder": "0857", "ref_image": "3_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["1_1.png", "3_1.png", "0_1.png", "2_1.png"], "timestamp": "2025-10-03T22:01:06.104992", "stared": false, "discarded": false, "grid_issue": false}
21
+ {"folder": "0857", "ref_image": "3_2.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "1_3.png", "3_3.png", "2_3.png"], "timestamp": "2025-10-03T22:01:25.057215", "stared": false, "discarded": false, "grid_issue": false}
22
+ {"folder": "0857", "ref_image": "3_3.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["3_0.png", "1_0.png", "2_0.png", "0_0.png"], "timestamp": "2025-10-03T22:02:24.904242", "stared": false, "discarded": false, "grid_issue": false}
23
+ {"folder": "0857", "ref_image": "3_3.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["1_1.png", "0_1.png", "2_1.png", "3_1.png"], "timestamp": "2025-10-03T22:02:44.461246", "stared": false, "discarded": false, "grid_issue": false}
24
+ {"folder": "0857", "ref_image": "3_3.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "3_2.png", "2_2.png", "0_2.png"], "timestamp": "2025-10-03T22:03:02.705541", "stared": false, "discarded": false, "grid_issue": false}
25
+ {"folder": "0867", "ref_image": "0_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["3_1.png", "2_1.png", "1_1.png", "0_1.png"], "timestamp": "2025-10-03T22:04:25.943013", "stared": false, "discarded": false, "grid_issue": false}
26
+ {"folder": "0867", "ref_image": "0_0.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "2_2.png", "0_2.png", "3_2.png"], "timestamp": "2025-10-03T22:04:48.945051", "stared": false, "discarded": false, "grid_issue": false}
27
+ {"folder": "0867", "ref_image": "0_0.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["2_3.png", "1_3.png", "3_3.png", "0_3.png"], "timestamp": "2025-10-03T22:05:25.104251", "stared": false, "discarded": false, "grid_issue": false}
28
+ {"folder": "0867", "ref_image": "0_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["1_0.png", "3_0.png", "2_0.png", "0_0.png"], "timestamp": "2025-10-03T22:06:29.925387", "stared": false, "discarded": false, "grid_issue": false}
29
+ {"folder": "0867", "ref_image": "0_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["0_2.png", "2_2.png", "1_2.png", "3_2.png"], "timestamp": "2025-10-03T22:06:49.091470", "stared": false, "discarded": false, "grid_issue": false}
30
+ {"folder": "0867", "ref_image": "0_1.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": [], "discarded": true, "timestamp": "2025-10-03T22:07:17.770983"}
31
+ {"folder": "0867", "ref_image": "0_2.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["1_0.png", "0_0.png", "2_0.png", "3_0.png"], "timestamp": "2025-10-03T22:07:36.797015", "stared": false, "discarded": false, "grid_issue": false}
32
+ {"folder": "0867", "ref_image": "0_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["2_1.png", "0_1.png", "1_1.png", "3_1.png"], "timestamp": "2025-10-03T22:07:54.571586", "stared": false, "discarded": false, "grid_issue": false}
33
+ {"folder": "0867", "ref_image": "0_2.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": [], "discarded": true, "timestamp": "2025-10-03T22:08:10.545457"}
34
+ {"folder": "0867", "ref_image": "0_3.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["0_0.png", "3_0.png", "1_0.png", "2_0.png"], "timestamp": "2025-10-03T22:08:26.360537", "stared": false, "discarded": false, "grid_issue": false}
35
+ {"folder": "0867", "ref_image": "0_3.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["3_1.png", "2_1.png", "1_1.png", "0_1.png"], "timestamp": "2025-10-03T22:08:44.908431", "stared": false, "discarded": false, "grid_issue": false}
36
+ {"folder": "0867", "ref_image": "0_3.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "0_2.png", "2_2.png", "3_2.png"], "timestamp": "2025-10-03T22:09:02.813181", "stared": false, "discarded": false, "grid_issue": false}
37
+ {"folder": "0867", "ref_image": "1_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["0_1.png", "3_1.png", "2_1.png", "1_1.png"], "timestamp": "2025-10-03T22:09:32.613520", "stared": false, "discarded": false, "grid_issue": false}
38
+ {"folder": "0867", "ref_image": "1_0.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "0_2.png", "2_2.png", "3_2.png"], "timestamp": "2025-10-03T22:09:50.270377", "stared": false, "discarded": false, "grid_issue": false}
39
+ {"folder": "0867", "ref_image": "1_0.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "2_3.png", "1_3.png", "3_3.png"], "timestamp": "2025-10-03T22:10:05.132118", "stared": false, "discarded": false, "grid_issue": false}
40
+ {"folder": "0867", "ref_image": "1_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "3_0.png", "1_0.png", "0_0.png"], "timestamp": "2025-10-03T22:10:20.460630", "stared": false, "discarded": false, "grid_issue": false}
41
+ {"folder": "0867", "ref_image": "1_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "2_2.png", "3_2.png", "0_2.png"], "timestamp": "2025-10-03T22:11:18.256846", "stared": false, "discarded": false, "grid_issue": false}
42
+ {"folder": "0867", "ref_image": "1_1.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["2_3.png", "0_3.png", "3_3.png", "1_3.png"], "timestamp": "2025-10-03T22:11:51.577986", "stared": false, "discarded": false, "grid_issue": false}
43
+ {"folder": "0867", "ref_image": "1_2.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["1_0.png", "0_0.png", "2_0.png", "3_0.png"], "timestamp": "2025-10-03T22:12:06.619408", "stared": false, "discarded": false, "grid_issue": false}
44
+ {"folder": "0867", "ref_image": "1_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["3_1.png", "0_1.png", "1_1.png", "2_1.png"], "timestamp": "2025-10-03T22:12:22.297656", "stared": false, "discarded": false, "grid_issue": false}
45
+ {"folder": "0867", "ref_image": "1_2.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "2_3.png", "3_3.png", "1_3.png"], "timestamp": "2025-10-03T22:12:34.811645", "stared": false, "discarded": false, "grid_issue": false}
46
+ {"folder": "0867", "ref_image": "1_3.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["0_0.png", "3_0.png", "1_0.png", "2_0.png"], "timestamp": "2025-10-03T22:12:47.534657", "stared": false, "discarded": false, "grid_issue": false}
47
+ {"folder": "0867", "ref_image": "1_3.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["3_1.png", "0_1.png", "2_1.png", "1_1.png"], "timestamp": "2025-10-03T22:13:05.897688", "stared": false, "discarded": false, "grid_issue": false}
48
+ {"folder": "0867", "ref_image": "1_3.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["1_2.png", "3_2.png", "2_2.png", "0_2.png"], "timestamp": "2025-10-03T22:14:16.835026", "stared": false, "discarded": false, "grid_issue": false}
49
+ {"folder": "0867", "ref_image": "2_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["2_1.png", "3_1.png", "1_1.png", "0_1.png"], "timestamp": "2025-10-03T22:14:34.012034", "stared": false, "discarded": false, "grid_issue": false}
50
+ {"folder": "0867", "ref_image": "2_0.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["3_2.png", "0_2.png", "2_2.png", "1_2.png"], "timestamp": "2025-10-03T22:15:09.533749", "stared": false, "discarded": false, "grid_issue": false}
51
+ {"folder": "0867", "ref_image": "2_0.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["0_3.png", "2_3.png", "1_3.png", "3_3.png"], "timestamp": "2025-10-03T22:15:26.137162", "stared": false, "discarded": false, "grid_issue": false}
52
+ {"folder": "0867", "ref_image": "2_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": ["2_0.png", "1_0.png", "0_0.png", "3_0.png"], "timestamp": "2025-10-03T22:15:44.115114", "stared": false, "discarded": false, "grid_issue": false}
53
+ {"folder": "0867", "ref_image": "2_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["0_2.png", "3_2.png", "2_2.png", "1_2.png"], "timestamp": "2025-10-03T22:16:24.396877", "stared": false, "discarded": false, "grid_issue": false}
54
+ {"folder": "0867", "ref_image": "2_1.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": ["2_3.png", "0_3.png", "3_3.png", "1_3.png"], "timestamp": "2025-10-03T22:17:31.696199", "stared": false, "discarded": false, "grid_issue": false}
annotator/data/annotation_pbw.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
annotator/data/annotation_wcx.jsonl ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {"folder": "0194", "ref_image": "2_3.png", "compare_images": ["0_4.png", "1_4.png", "2_4.png", "3_4.png"], "rank_images": [], "grid_issue": false, "timestamp": "2025-10-03T13:59:56.317772"}
2
+ {"folder": "0043", "ref_image": "0_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["0_1.png", "3_1.png", "2_1.png", "1_1.png"], "timestamp": "2025-10-03T14:01:51.212963", "stared": false, "discarded": false, "grid_issue": false}
3
+ {"folder": "2151", "ref_image": "3_1.png", "compare_images": ["0_4.png", "1_4.png", "2_4.png", "3_4.png"], "rank_images": [], "grid_issue": true, "timestamp": "2025-10-03T14:02:33.834546"}
4
+ {"folder": "2151", "ref_image": "3_2.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": [], "grid_issue": true, "timestamp": "2025-10-03T14:03:13.020670"}
5
+ {"folder": "2168", "ref_image": "3_1.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": [], "discarded": true, "timestamp": "2025-10-03T19:13:35.202185"}
6
+ {"folder": "2168", "ref_image": "3_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": [], "discarded": false, "timestamp": "2025-10-03T19:14:57.777722"}
annotator/data/annotation_xcl.jsonl ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {"folder": "0328", "ref_image": "3_2.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": [], "stared": true, "timestamp": "2025-10-03T13:11:54.328616"}
2
+ {"folder": "0329", "ref_image": "0_0.png", "compare_images": ["0_1.png", "1_1.png", "2_1.png", "3_1.png"], "rank_images": ["0_1.png", "3_1.png", "1_1.png", "2_1.png"], "timestamp": "2025-10-03T13:12:58.055853", "stared": false, "discarded": false, "grid_issue": false}
3
+ {"folder": "0518", "ref_image": "3_1.png", "compare_images": ["0_0.png", "1_0.png", "2_0.png", "3_0.png"], "rank_images": [], "grid_issue": false, "timestamp": "2025-10-03T13:13:53.689728", "stared": true}
4
+ {"folder": "0592", "ref_image": "3_0.png", "compare_images": ["0_4.png", "1_4.png", "2_4.png", "3_4.png"], "rank_images": [], "grid_issue": true, "timestamp": "2025-10-03T13:14:06.347085"}
5
+ {"folder": "0671", "ref_image": "2_3.png", "compare_images": ["0_4.png", "1_4.png", "2_4.png", "3_4.png"], "rank_images": ["2_4.png", "3_4.png", "1_4.png", "0_4.png"], "timestamp": "2025-10-03T13:14:38.075308", "stared": false, "discarded": false, "grid_issue": false}
6
+ {"folder": "0984", "ref_image": "1_4.png", "compare_images": ["0_3.png", "1_3.png", "2_3.png", "3_3.png"], "rank_images": [], "grid_issue": true, "timestamp": "2025-10-03T13:15:03.189176"}
7
+ {"folder": "1453", "ref_image": "3_3.png", "compare_images": ["0_2.png", "1_2.png", "2_2.png", "3_2.png"], "rank_images": ["3_2.png", "0_2.png", "1_2.png", "2_2.png"], "timestamp": "2025-10-03T13:16:18.934409", "stared": false, "discarded": false, "grid_issue": false}
annotator/data/metadata_jcy.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "last_page": 16063,
3
+ "last_updated": "2025-10-03T22:17:40.608391"
4
+ }
annotator/data/metadata_pbw.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "last_page": 11041,
3
+ "last_updated": "2025-10-03T22:15:39.557914"
4
+ }
annotator/data/metadata_wjy.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "last_page": 21345,
3
+ "last_updated": "2025-10-03T21:45:38.747150"
4
+ }
annotator/templates/index.html CHANGED
@@ -8,6 +8,95 @@
8
  body {
9
  font-family: Arial, sans-serif;
10
  padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
 
13
  .rank-btn {
@@ -68,6 +157,72 @@
68
  font-size: 14px;
69
  font-weight: bold;
70
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  /* 消息提示样式 */
72
  .message-box {
73
  position: fixed;
@@ -116,45 +271,51 @@
116
  .message-box.hiding {
117
  animation: slideOut 0.3s ease-out;
118
  }
 
 
 
 
 
 
 
 
 
119
 
120
- /* 固定在右上角的分页条 */
121
- .page-control {
122
- position: fixed;
123
- top: 20px;
124
- right: 20px;
125
- background: rgba(255,255,255,0.9);
126
- border: 1px solid #ddd;
127
- padding: 8px 12px;
128
- border-radius: 6px;
129
- box-shadow: 0 2px 6px rgba(0,0,0,0.1);
130
- z-index: 999;
131
- display: flex;
132
- align-items: center;
133
- gap: 8px;
134
- font-size: 14px;
135
- }
136
- .page-control input {
137
- width: 60px;
138
- padding: 3px 5px;
139
- border: 1px solid #ccc;
140
- border-radius: 4px;
141
  }
142
- .page-control button {
143
- padding: 4px 8px;
144
- background-color: #2196F3;
145
- color: white;
146
- border: none;
147
- border-radius: 4px;
148
- cursor: pointer;
149
  }
150
- .page-control button:hover {
151
- background-color: #0b7dda;
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
- </style>
154
- <script>
155
- let rankCounter = 1;
156
- const rankedImages = new Map();
157
- let allCompareImages = [];
158
 
159
  function initializeCompareImages() {
160
  allCompareImages = [];
@@ -167,39 +328,479 @@
167
  }
168
  });
169
  }
 
170
  window.addEventListener('DOMContentLoaded', function() {
171
  initializeCompareImages();
 
 
 
 
172
  });
173
 
174
- /* 这里省略 rankImage、loadExistingAnnotation、showMessage、submitRanking 的原有实现 */
175
- /* ... 你的原始脚本保持不变 ... */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
- // 新增跳转函数
178
- function jumpToPage(event) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  event.preventDefault();
180
- const input = document.getElementById('pageInput');
181
- let page = parseInt(input.value);
182
- if (isNaN(page) || page < 1) page = 1;
183
- if (page > {{ total_pages }}) page = {{ total_pages }};
184
- window.location.href = "/?page=" + page;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  return false;
186
  }
187
  </script>
188
  </head>
189
  <body>
190
- <!-- 消息提示框 -->
191
- <div id="messageBox" class="message-box"></div>
192
 
193
- <!-- 固定在右上角的分页控制条 -->
194
- <div class="page-control">
195
- <span>{{ page }}/{{ total_pages }}</span>
196
- <form id="pageJumpForm" onsubmit="return jumpToPage(event)" style="display:inline;">
197
- <input type="number" id="pageInput" min="1" max="{{ total_pages }}" value="{{ page }}">
198
- <button type="submit">跳转</button>
199
- </form>
 
 
 
 
 
 
 
 
 
200
  </div>
 
 
201
 
202
  <h1>Image Ranking</h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  <form id="rankingForm" action="/sort" method="POST" onsubmit="return submitRanking(event)">
204
  {% for item in data %}
205
  <div>
@@ -209,26 +810,44 @@
209
  <p style="font-size: 16px; line-height: 1.6; margin-bottom: 0; color: #555;">{{ item.prompt }}</p>
210
  </div>
211
  {% endif %}
212
- <h3>Reference Image: {{ item.ref_image }}
 
213
  {% if item.is_annotated %}
214
  <span class="annotation-status">已标注</span>
215
  {% endif %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  </h3>
217
  <p>Folder: {{ item.folder }}</p>
218
- <img src="{{ item.ref_image }}" alt="ref_image" width="200">
 
 
219
  <input type="hidden" name="ref_image" value="{{ item.ref_image }}">
220
  {% if item.is_annotated %}
221
  <button type="button" class="show-annotation-btn"
222
- data-loaded="false"
223
  onclick='loadExistingAnnotation(this, "{{ item.folder }}", "{{ item.ref_image.split("/")[-1] }}", {{ item.existing_rank_images|tojson|safe }})'>
224
  显示已有标注
225
  </button>
226
  {% endif %}
227
  <h4>Compare Images:</h4>
228
- <div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-start;">
229
  {% for compare_image in item.compare_images %}
230
- <div class="image-item" style="display: flex; flex-direction: column; align-items: center; gap: 5px;">
231
- <img src="{{ compare_image }}" alt="compare_image" width="100">
232
  <button type="button"
233
  class="rank-btn"
234
  data-image="{{ compare_image }}"
@@ -252,4 +871,4 @@
252
  {% endif %}
253
  </div>
254
  </body>
255
- </html>
 
8
  body {
9
  font-family: Arial, sans-serif;
10
  padding: 20px;
11
+ padding-top: 80px;
12
+ }
13
+
14
+ /* 进度条样式 */
15
+ .progress-container {
16
+ position: fixed;
17
+ top: 0;
18
+ left: 0;
19
+ right: 0;
20
+ background-color: white;
21
+ padding: 15px 20px;
22
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
23
+ z-index: 999;
24
+ display: flex;
25
+ align-items: center;
26
+ gap: 15px;
27
+ justify-content: flex-end; /* 右上角对齐 */
28
+ }
29
+
30
+ .progress-info {
31
+ display: flex;
32
+ align-items: center;
33
+ gap: 8px;
34
+ font-size: 16px;
35
+ font-weight: bold;
36
+ color: #333;
37
+ }
38
+
39
+ .progress-input {
40
+ width: 80px;
41
+ padding: 5px 8px;
42
+ border: 2px solid #2196F3;
43
+ border-radius: 4px;
44
+ font-size: 16px;
45
+ font-weight: bold;
46
+ text-align: center;
47
+ }
48
+
49
+ .progress-input:focus {
50
+ outline: none;
51
+ border-color: #0b7dda;
52
+ box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
53
+ }
54
+
55
+ .progress-bar-wrapper {
56
+ flex: 1;
57
+ height: 20px;
58
+ background-color: #e0e0e0;
59
+ border-radius: 10px;
60
+ overflow: hidden;
61
+ position: relative;
62
+ }
63
+
64
+ .progress-bar {
65
+ height: 100%;
66
+ background: linear-gradient(90deg, #4CAF50 0%, #2196F3 100%);
67
+ transition: width 0.3s ease;
68
+ border-radius: 10px;
69
+ }
70
+
71
+ .progress-percentage {
72
+ position: absolute;
73
+ top: 50%;
74
+ left: 50%;
75
+ transform: translate(-50%, -50%);
76
+ font-size: 12px;
77
+ font-weight: bold;
78
+ color: #333;
79
+ text-shadow: 0 0 3px white;
80
+ }
81
+
82
+ .jump-btn {
83
+ padding: 6px 15px;
84
+ background-color: #2196F3;
85
+ color: white;
86
+ border: none;
87
+ border-radius: 4px;
88
+ cursor: pointer;
89
+ font-size: 14px;
90
+ font-weight: bold;
91
+ transition: background-color 0.3s;
92
+ }
93
+
94
+ .jump-btn:hover {
95
+ background-color: #0b7dda;
96
+ }
97
+
98
+ .jump-btn:active {
99
+ transform: scale(0.98);
100
  }
101
 
102
  .rank-btn {
 
157
  font-size: 14px;
158
  font-weight: bold;
159
  }
160
+
161
+ /* 收藏按钮样式 */
162
+ .star-btn {
163
+ display: inline-block;
164
+ margin-left: 15px;
165
+ padding: 8px 15px;
166
+ background-color: transparent;
167
+ border: 2px solid #FFC107;
168
+ color: #FFC107;
169
+ border-radius: 4px;
170
+ cursor: pointer;
171
+ font-size: 20px;
172
+ transition: all 0.3s ease;
173
+ vertical-align: middle;
174
+ }
175
+ .star-btn:hover {
176
+ transform: scale(1.1);
177
+ }
178
+ .star-btn.starred {
179
+ background-color: #FFC107;
180
+ color: white;
181
+ }
182
+ .discard-btn {
183
+ display: inline-block;
184
+ margin-left: 15px;
185
+ padding: 8px 15px;
186
+ background-color: transparent;
187
+ border: 2px solid #F44336;
188
+ color: #F44336;
189
+ border-radius: 4px;
190
+ cursor: pointer;
191
+ font-size: 18px;
192
+ font-weight: bold;
193
+ transition: all 0.3s ease;
194
+ vertical-align: middle;
195
+ }
196
+ .discard-btn:hover {
197
+ transform: scale(1.1);
198
+ }
199
+ .discard-btn.discarded {
200
+ background-color: #F44336;
201
+ color: white;
202
+ }
203
+ /* 网格问题按钮样式 */
204
+ .grid-issue-btn {
205
+ display: inline-block;
206
+ margin-left: 15px;
207
+ padding: 8px 15px;
208
+ background-color: transparent;
209
+ border: 2px solid #9C27B0;
210
+ color: #9C27B0;
211
+ border-radius: 4px;
212
+ cursor: pointer;
213
+ font-size: 16px;
214
+ font-weight: bold;
215
+ transition: all 0.3s ease;
216
+ vertical-align: middle;
217
+ }
218
+ .grid-issue-btn:hover {
219
+ transform: scale(1.1);
220
+ }
221
+ .grid-issue-btn.grid-issue {
222
+ background-color: #9C27B0;
223
+ color: white;
224
+ }
225
+
226
  /* 消息提示样式 */
227
  .message-box {
228
  position: fixed;
 
271
  .message-box.hiding {
272
  animation: slideOut 0.3s ease-out;
273
  }
274
+ </style>
275
+ <script>
276
+ let rankCounter = 1;
277
+ const rankedImages = new Map();
278
+ let allCompareImages = [];
279
+
280
+ // 获取当前页面和总页数
281
+ const currentPage = {{ page }};
282
+ const totalPages = {{ total_pages }};
283
 
284
+ function updatePageMetadata(page) {
285
+ // 异步更新页码到后端
286
+ fetch('/update_page', {
287
+ method: 'POST',
288
+ headers: {
289
+ 'Content-Type': 'application/json',
290
+ },
291
+ body: JSON.stringify({ page: page })
292
+ }).catch(error => {
293
+ console.error('Error updating page metadata:', error);
294
+ });
 
 
 
 
 
 
 
 
 
 
295
  }
296
+
297
+ function updateProgressBar() {
298
+ const progressBar = document.querySelector('.progress-bar');
299
+ const progressPercentage = document.querySelector('.progress-percentage');
300
+ const percentage = (currentPage / totalPages * 100).toFixed(1);
301
+ progressBar.style.width = percentage + '%';
302
+ progressPercentage.textContent = percentage + '%';
303
  }
304
+
305
+ function jumpToPage() {
306
+ const input = document.getElementById('pageInput');
307
+ const targetPage = parseInt(input.value);
308
+
309
+ if (isNaN(targetPage) || targetPage < 1 || targetPage > totalPages) {
310
+ showMessage(`请输入1到${totalPages}之间的页码`, 'error');
311
+ input.value = currentPage;
312
+ return;
313
+ }
314
+
315
+ // 在跳转前更新元数据
316
+ updatePageMetadata(targetPage);
317
+ window.location.href = `/?page=${targetPage}`;
318
  }
 
 
 
 
 
319
 
320
  function initializeCompareImages() {
321
  allCompareImages = [];
 
328
  }
329
  });
330
  }
331
+
332
  window.addEventListener('DOMContentLoaded', function() {
333
  initializeCompareImages();
334
+ setupKeyboardShortcuts();
335
+ updateProgressBar();
336
+ // 页面加载时更新元数据
337
+ updatePageMetadata(currentPage);
338
  });
339
 
340
+ function setupKeyboardShortcuts() {
341
+ const pageInput = document.getElementById('pageInput');
342
+
343
+ document.addEventListener('keydown', function(event) {
344
+ // 在输入框中按Enter键跳转页面
345
+ if (event.target === pageInput && event.key === 'Enter') {
346
+ jumpToPage();
347
+ event.preventDefault();
348
+ return;
349
+ }
350
+
351
+ // 忽略在输入框中的其他按键
352
+ if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') {
353
+ return;
354
+ }
355
+
356
+ // 数字键 1-4 对应第 0-3 张图像
357
+ if (event.key >= '1' && event.key <= '4') {
358
+ const index = parseInt(event.key) - 1;
359
+ const rankButtons = document.querySelectorAll('.rank-btn');
360
+ if (index < rankButtons.length) {
361
+ const button = rankButtons[index];
362
+ const imagePath = button.getAttribute('data-image');
363
+ rankImage(button, imagePath);
364
+ }
365
+ event.preventDefault();
366
+ }
367
+
368
+ // S 键收藏/取消收藏
369
+ if (event.key === 's' || event.key === 'S') {
370
+ const starButton = document.querySelector('.star-btn');
371
+ if (starButton) {
372
+ starButton.click();
373
+ }
374
+ event.preventDefault();
375
+ }
376
+
377
+ // D 键丢弃/取消丢弃
378
+ if (event.key === 'd' || event.key === 'D') {
379
+ const discardButton = document.querySelector('.discard-btn');
380
+ if (discardButton) {
381
+ discardButton.click();
382
+ }
383
+ event.preventDefault();
384
+ }
385
+ // G 键网格问题/取消网格问题
386
+ if (event.key === 'g' || event.key === 'G') {
387
+ const gridIssueButton = document.querySelector('.grid-issue-btn');
388
+ if (gridIssueButton) {
389
+ gridIssueButton.click();
390
+ }
391
+ event.preventDefault();
392
+ }
393
+
394
+ // Shift + 左箭头/上箭头 = 上一页
395
+ if (event.shiftKey && (event.key === 'ArrowLeft' || event.key === 'ArrowUp')) {
396
+ const prevLink = document.querySelector('a[href*="page="]');
397
+ if (prevLink && prevLink.textContent.includes('上一页')) {
398
+ const url = new URL(prevLink.href);
399
+ const prevPage = parseInt(url.searchParams.get('page'));
400
+ updatePageMetadata(prevPage);
401
+ window.location.href = prevLink.href;
402
+ }
403
+ event.preventDefault();
404
+ }
405
+
406
+ // Shift + 右箭头/下箭头 = 下一页
407
+ if (event.shiftKey && (event.key === 'ArrowRight' || event.key === 'ArrowDown')) {
408
+ const links = document.querySelectorAll('a[href*="page="]');
409
+ links.forEach(link => {
410
+ if (link.textContent.includes('下一页')) {
411
+ const url = new URL(link.href);
412
+ const nextPage = parseInt(url.searchParams.get('page'));
413
+ updatePageMetadata(nextPage);
414
+ window.location.href = link.href;
415
+ }
416
+ });
417
+ event.preventDefault();
418
+ }
419
+
420
+ // Enter 键提交排序
421
+ if (event.key === 'Enter') {
422
+ const form = document.getElementById('rankingForm');
423
+ const submitEvent = new Event('submit', { bubbles: true, cancelable: true });
424
+ form.dispatchEvent(submitEvent);
425
+ event.preventDefault();
426
+ }
427
+ });
428
+ }
429
+
430
+ function rankImage(button, imagePath) {
431
+ const currentRank = button.dataset.rank;
432
+
433
+ if (!currentRank) {
434
+ button.textContent = rankCounter;
435
+ button.dataset.rank = rankCounter;
436
+ button.classList.add('ranked');
437
+
438
+ rankedImages.set(imagePath, rankCounter);
439
+
440
+ const input = document.createElement('input');
441
+ input.type = 'hidden';
442
+ input.name = 'sorted_images';
443
+ input.value = `${rankCounter}:${imagePath}`;
444
+ input.id = `input-${imagePath.replace(/[^a-zA-Z0-9]/g, '_')}`;
445
+ document.getElementById('rankingForm').appendChild(input);
446
+
447
+ rankCounter++;
448
+ } else {
449
+ const rankToRemove = parseInt(currentRank);
450
+
451
+ button.textContent = "排序";
452
+ button.removeAttribute('data-rank');
453
+ button.classList.remove('ranked');
454
+
455
+ rankedImages.delete(imagePath);
456
+
457
+ const inputId = `input-${imagePath.replace(/[^a-zA-Z0-9]/g, '_')}`;
458
+ const inputToRemove = document.getElementById(inputId);
459
+ if (inputToRemove) {
460
+ inputToRemove.remove();
461
+ }
462
+
463
+ const allButtons = document.querySelectorAll('.rank-btn[data-rank]');
464
+ allButtons.forEach(btn => {
465
+ const btnRank = parseInt(btn.dataset.rank);
466
+ if (btnRank > rankToRemove) {
467
+ const newRank = btnRank - 1;
468
+ btn.dataset.rank = newRank;
469
+ btn.textContent = newRank;
470
+
471
+ const btnImagePath = btn.getAttribute('data-image');
472
+ rankedImages.set(btnImagePath, newRank);
473
+
474
+ const btnInputId = `input-${btnImagePath.replace(/[^a-zA-Z0-9]/g, '_')}`;
475
+ const btnInput = document.getElementById(btnInputId);
476
+ if (btnInput) {
477
+ btnInput.value = `${newRank}:${btnImagePath}`;
478
+ }
479
+ }
480
+ });
481
+
482
+ rankCounter--;
483
+ }
484
+
485
+ button.blur();
486
+ }
487
+
488
+ function toggleStar(button, folder, refImage) {
489
+ const isStarred = button.classList.contains('starred');
490
+ const newStarState = !isStarred;
491
+
492
+ // 获取当前排序结果
493
+ const currentRankImages = [];
494
+ for (let i = 1; i < rankCounter; i++) {
495
+ for (const [imagePath, rank] of rankedImages.entries()) {
496
+ if (rank === i) {
497
+ currentRankImages.push(imagePath.split('/').pop());
498
+ break;
499
+ }
500
+ }
501
+ }
502
+
503
+ fetch('/star', {
504
+ method: 'POST',
505
+ headers: {
506
+ 'Content-Type': 'application/json',
507
+ },
508
+ body: JSON.stringify({
509
+ folder: folder,
510
+ ref_image: refImage,
511
+ stared: newStarState,
512
+ compare_images: allCompareImages,
513
+ rank_images: currentRankImages
514
+ })
515
+ })
516
+ .then(response => response.json())
517
+ .then(data => {
518
+ if (data.status === 'success') {
519
+ if (newStarState) {
520
+ button.classList.add('starred');
521
+ button.textContent = '★';
522
+ } else {
523
+ button.classList.remove('starred');
524
+ button.textContent = '☆';
525
+ }
526
+ showMessage(data.message, 'success');
527
+ } else {
528
+ showMessage(data.message || '收藏操作失败', 'error');
529
+ }
530
+ })
531
+ .catch(error => {
532
+ console.error('Error:', error);
533
+ showMessage('收藏操作时发生错误', 'error');
534
+ });
535
+ }
536
 
537
+ function toggleDiscard(button, folder, refImage) {
538
+ const isDiscarded = button.classList.contains('discarded');
539
+ const newDiscardState = !isDiscarded;
540
+
541
+ // 获取当前排序结果
542
+ const currentRankImages = [];
543
+ for (let i = 1; i < rankCounter; i++) {
544
+ for (const [imagePath, rank] of rankedImages.entries()) {
545
+ if (rank === i) {
546
+ currentRankImages.push(imagePath.split('/').pop());
547
+ break;
548
+ }
549
+ }
550
+ }
551
+
552
+ fetch('/discard', {
553
+ method: 'POST',
554
+ headers: {
555
+ 'Content-Type': 'application/json',
556
+ },
557
+ body: JSON.stringify({
558
+ folder: folder,
559
+ ref_image: refImage,
560
+ discarded: newDiscardState,
561
+ compare_images: allCompareImages,
562
+ rank_images: currentRankImages
563
+ })
564
+ })
565
+ .then(response => response.json())
566
+ .then(data => {
567
+ if (data.status === 'success') {
568
+ if (newDiscardState) {
569
+ button.classList.add('discarded');
570
+ button.textContent = '🗑️';
571
+ } else {
572
+ button.classList.remove('discarded');
573
+ button.textContent = '丢弃';
574
+ }
575
+ showMessage(data.message, 'success');
576
+ } else {
577
+ showMessage(data.message || '丢弃操作失败', 'error');
578
+ }
579
+ })
580
+ .catch(error => {
581
+ console.error('Error:', error);
582
+ showMessage('丢弃操作时发生错误', 'error');
583
+ });
584
+ }
585
+ function toggleGridIssue(button, folder, refImage) {
586
+ const isGridIssue = button.classList.contains('grid-issue');
587
+ const newGridIssueState = !isGridIssue;
588
+
589
+ // 获取当前排序结果
590
+ const currentRankImages = [];
591
+ for (let i = 1; i < rankCounter; i++) {
592
+ for (const [imagePath, rank] of rankedImages.entries()) {
593
+ if (rank === i) {
594
+ currentRankImages.push(imagePath.split('/').pop());
595
+ break;
596
+ }
597
+ }
598
+ }
599
+
600
+ fetch('/grid_issue', {
601
+ method: 'POST',
602
+ headers: {
603
+ 'Content-Type': 'application/json',
604
+ },
605
+ body: JSON.stringify({
606
+ folder: folder,
607
+ ref_image: refImage,
608
+ grid_issue: newGridIssueState,
609
+ compare_images: allCompareImages,
610
+ rank_images: currentRankImages
611
+ })
612
+ })
613
+ .then(response => response.json())
614
+ .then(data => {
615
+ if (data.status === 'success') {
616
+ if (newGridIssueState) {
617
+ button.classList.add('grid-issue');
618
+ button.textContent = '⚠️';
619
+ } else {
620
+ button.classList.remove('grid-issue');
621
+ button.textContent = '网格问题';
622
+ }
623
+ showMessage(data.message, 'success');
624
+ } else {
625
+ showMessage(data.message || '网格问题标记失败', 'error');
626
+ }
627
+ })
628
+ .catch(error => {
629
+ console.error('Error:', error);
630
+ showMessage('网格问题标记时发生错误', 'error');
631
+ });
632
+ }
633
+
634
+ function loadExistingAnnotation(button, folder, refImage, rankImagesFilenames) {
635
+ const isLoaded = button.dataset.loaded === 'true';
636
+
637
+ if (isLoaded) {
638
+ const allButtons = document.querySelectorAll('.rank-btn');
639
+ allButtons.forEach(btn => {
640
+ btn.textContent = "排序";
641
+ btn.removeAttribute('data-rank');
642
+ btn.classList.remove('ranked');
643
+ });
644
+
645
+ rankedImages.clear();
646
+ rankCounter = 1;
647
+
648
+ const hiddenInputs = document.querySelectorAll('input[name="sorted_images"]');
649
+ hiddenInputs.forEach(input => input.remove());
650
+
651
+ button.textContent = '显示已有标注';
652
+ button.dataset.loaded = 'false';
653
+ showMessage('已清除标注结果', 'success');
654
+ } else {
655
+ const allButtons = document.querySelectorAll('.rank-btn');
656
+ allButtons.forEach(btn => {
657
+ btn.textContent = "排序";
658
+ btn.removeAttribute('data-rank');
659
+ btn.classList.remove('ranked');
660
+ });
661
+
662
+ rankedImages.clear();
663
+ rankCounter = 1;
664
+
665
+ const hiddenInputs = document.querySelectorAll('input[name="sorted_images"]');
666
+ hiddenInputs.forEach(input => input.remove());
667
+
668
+ rankImagesFilenames.forEach((filename, index) => {
669
+ const rank = index + 1;
670
+ const imagePath = `/images/${folder}/${filename}`;
671
+
672
+ const rankBtn = document.querySelector(`.rank-btn[data-image="${imagePath}"]`);
673
+
674
+ if (rankBtn) {
675
+ rankBtn.textContent = rank;
676
+ rankBtn.dataset.rank = rank;
677
+ rankBtn.classList.add('ranked');
678
+
679
+ rankedImages.set(imagePath, rank);
680
+
681
+ const input = document.createElement('input');
682
+ input.type = 'hidden';
683
+ input.name = 'sorted_images';
684
+ input.value = `${rank}:${imagePath}`;
685
+ input.id = `input-${imagePath.replace(/[^a-zA-Z0-9]/g, '_')}`;
686
+ document.getElementById('rankingForm').appendChild(input);
687
+ }
688
+ });
689
+
690
+ rankCounter = rankImagesFilenames.length + 1;
691
+
692
+ button.textContent = '关闭已有标注';
693
+ button.dataset.loaded = 'true';
694
+ showMessage('已加载现有标注结果', 'success');
695
+ }
696
+ }
697
+
698
+ function showMessage(message, type = 'success', duration = 2000) {
699
+ const messageBox = document.getElementById('messageBox');
700
+ messageBox.textContent = message;
701
+ messageBox.className = `message-box ${type} show`;
702
+
703
+ setTimeout(() => {
704
+ messageBox.classList.add('hiding');
705
+ setTimeout(() => {
706
+ messageBox.classList.remove('show', 'hiding');
707
+ }, 300);
708
+ }, duration);
709
+ }
710
+
711
+ function submitRanking(event) {
712
  event.preventDefault();
713
+
714
+ if (rankedImages.size === 0) {
715
+ showMessage('请至少选择一张图片进行排序!', 'error');
716
+ return false;
717
+ }
718
+
719
+ const form = document.getElementById('rankingForm');
720
+ const formData = new FormData(form);
721
+
722
+ formData.append('all_compare_images', JSON.stringify(allCompareImages));
723
+
724
+ const submitBtn = form.querySelector('.submit-btn');
725
+
726
+ submitBtn.disabled = true;
727
+ submitBtn.textContent = '提交中...';
728
+
729
+ fetch('/sort', {
730
+ method: 'POST',
731
+ body: formData
732
+ })
733
+ .then(response => response.json())
734
+ .then(data => {
735
+ if (data.status === 'success') {
736
+ showMessage(data.message, 'success');
737
+ const statusBadge = document.querySelector('.annotation-status');
738
+ if (!statusBadge) {
739
+ const h3 = document.querySelector('h3');
740
+ if (h3) {
741
+ const badge = document.createElement('span');
742
+ badge.className = 'annotation-status';
743
+ badge.textContent = '已标注';
744
+ h3.appendChild(badge);
745
+ }
746
+ }
747
+ } else {
748
+ showMessage(data.message || '提交失败', 'error');
749
+ }
750
+ })
751
+ .catch(error => {
752
+ console.error('Error:', error);
753
+ showMessage('提交时发生错误', 'error');
754
+ })
755
+ .finally(() => {
756
+ submitBtn.disabled = false;
757
+ submitBtn.textContent = '提交排序';
758
+ });
759
+
760
  return false;
761
  }
762
  </script>
763
  </head>
764
  <body>
 
 
765
 
766
+ <div class="progress-container">
767
+ <div class="progress-info">
768
+ <input id="pageInput"
769
+ class="progress-input"
770
+ type="number"
771
+ min="1"
772
+ max="{{ total_pages }}"
773
+ value="{{ page }}"
774
+ aria-label="页码">
775
+ <span>/ {{ total_pages }}</span>
776
+ </div>
777
+ <div class="progress-bar-wrapper" aria-label="进度">
778
+ <div class="progress-bar" style="width: 0%"></div>
779
+ <div class="progress-percentage">0%</div>
780
+ </div>
781
+ <button class="jump-btn" type="button" onclick="jumpToPage()">跳转</button>
782
  </div>
783
+
784
+ <div id="messageBox" class="message-box"></div>
785
 
786
  <h1>Image Ranking</h1>
787
+ <div style="background-color: #e3f2fd; padding: 12px 20px; margin-bottom: 20px; border-radius: 4px; border-left: 4px solid #2196F3;">
788
+ <div style="background-color: #e3f2fd; padding: 12px 20px; margin-bottom: 20px; border-radius: 4px; border-left: 4px solid #2196F3;">
789
+ <p style="margin: 0; font-size: 14px; color: #1976d2; line-height: 1.8;">
790
+ <strong>快捷键提示:</strong><br>
791
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">S</kbd> 收藏 |
792
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">D</kbd> 丢弃 |
793
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">G</kbd> 网格问题 |
794
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">Enter</kbd> 提交排序<br>
795
+ 对前4张图像排序 |
796
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">S</kbd> 收藏 |
797
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">D</kbd> 丢弃 |
798
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">Enter</kbd> 提交排序<br>
799
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">Shift+←/↑</kbd> 上一条 |
800
+ 按 <kbd style="background: #fff; padding: 2px 6px; border: 1px solid #ccc; border-radius: 3px; font-family: monospace;">Shift+→/↓</kbd> 下一条
801
+ </p>
802
+ </div>
803
+ </div>
804
  <form id="rankingForm" action="/sort" method="POST" onsubmit="return submitRanking(event)">
805
  {% for item in data %}
806
  <div>
 
810
  <p style="font-size: 16px; line-height: 1.6; margin-bottom: 0; color: #555;">{{ item.prompt }}</p>
811
  </div>
812
  {% endif %}
813
+ <h3>
814
+ Reference Image: {{ item.ref_image }}
815
  {% if item.is_annotated %}
816
  <span class="annotation-status">已标注</span>
817
  {% endif %}
818
+ <button type="button"
819
+ class="star-btn {% if item.stared %}starred{% endif %}"
820
+ onclick="toggleStar(this, '{{ item.folder }}', '{{ item.ref_image.split('/')[-1] }}')">
821
+ {% if item.stared %}★{% else %}☆{% endif %}
822
+ </button>
823
+ <button type="button"
824
+ class="discard-btn {% if item.discarded %}discarded{% endif %}"
825
+ onclick="toggleDiscard(this, '{{ item.folder }}', '{{ item.ref_image.split('/')[-1] }}')">
826
+ {% if item.discarded %}🗑️{% else %}丢弃{% endif %}
827
+ </button>
828
+ <button type="button"
829
+ class="grid-issue-btn {% if item.grid_issue %}grid-issue{% endif %}"
830
+ onclick="toggleGridIssue(this, '{{ item.folder }}', '{{ item.ref_image.split('/')[-1] }}')">
831
+ {% if item.grid_issue %}⚠️{% else %}网格问题{% endif %}
832
+ </button>
833
+ </h3>
834
  </h3>
835
  <p>Folder: {{ item.folder }}</p>
836
+ <div style="text-align: center; margin: 20px 0;">
837
+ <img src="{{ item.ref_image }}" alt="ref_image" width="400">
838
+ </div>
839
  <input type="hidden" name="ref_image" value="{{ item.ref_image }}">
840
  {% if item.is_annotated %}
841
  <button type="button" class="show-annotation-btn"
 
842
  onclick='loadExistingAnnotation(this, "{{ item.folder }}", "{{ item.ref_image.split("/")[-1] }}", {{ item.existing_rank_images|tojson|safe }})'>
843
  显示已有标注
844
  </button>
845
  {% endif %}
846
  <h4>Compare Images:</h4>
847
+ <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; width: 100%;">
848
  {% for compare_image in item.compare_images %}
849
+ <div class="image-item" style="display: flex; flex-direction: column; align-items: center; gap: 8px;">
850
+ <img src="{{ compare_image }}" alt="compare_image" style="width: 100%; height: auto; max-width: 100%;">
851
  <button type="button"
852
  class="rank-btn"
853
  data-image="{{ compare_image }}"
 
871
  {% endif %}
872
  </div>
873
  </body>
874
+ </html>
annotator/test.ipynb CHANGED
@@ -2,8 +2,8 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 16,
6
- "id": "5bdfe87c",
7
  "metadata": {},
8
  "outputs": [],
9
  "source": [
@@ -13,6 +13,25 @@
13
  "IMAGE_DIR = \"/root/siton-tmp/images_divided\""
14
  ]
15
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  {
17
  "cell_type": "code",
18
  "execution_count": null,
@@ -108,7 +127,7 @@
108
  ],
109
  "metadata": {
110
  "kernelspec": {
111
- "display_name": "pytorch-env",
112
  "language": "python",
113
  "name": "python3"
114
  },
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "4835cc14",
7
  "metadata": {},
8
  "outputs": [],
9
  "source": [
 
13
  "IMAGE_DIR = \"/root/siton-tmp/images_divided\""
14
  ]
15
  },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 3,
19
+ "id": "5bdfe87c",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "data_file = 'data/extended_data_summary_v2.jsonl'\n",
24
+ "with open(data_file, 'r') as f:\n",
25
+ " data = [json.loads(line) for line in f]\n",
26
+ "\n",
27
+ "data_2by2 = [\n",
28
+ " item for item in data if item['layout'] == '2x2'\n",
29
+ "]\n",
30
+ "with open('data/2by2_data_summary.jsonl', 'w') as f:\n",
31
+ " for item in data_2by2:\n",
32
+ " f.write(json.dumps(item) + '\\n')"
33
+ ]
34
+ },
35
  {
36
  "cell_type": "code",
37
  "execution_count": null,
 
127
  ],
128
  "metadata": {
129
  "kernelspec": {
130
+ "display_name": "pbw-torch-env",
131
  "language": "python",
132
  "name": "python3"
133
  },
launch.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import argparse
3
+ import json
4
+
5
+ user_names = [
6
+ 'xcl', 'sx', 'pbw', 'jcy', 'wjy', 'wcx'
7
+ ]
8
+ user_to_port = {
9
+ 'pbw': 5002,
10
+ 'jcy': 5011,
11
+ 'xcl': 5021,
12
+ 'sx': 5031,
13
+ 'wjy': 5041,
14
+ 'wcx': 5051,
15
+ }
16
+
17
+ total_data_num = 32016
18
+ data_per_user = total_data_num // len(user_names)
19
+ user_to_data_range = {
20
+ user: start_idx for user, start_idx in zip(
21
+ user_names,
22
+ range(1, total_data_num + 1, data_per_user)
23
+ )
24
+ }
25
+
26
+ def launch(user):
27
+ if user not in user_names:
28
+ raise ValueError(f"User {user} not recognized. Available users: {user_names}")
29
+
30
+ port = user_to_port[user]
31
+ start_idx = user_to_data_range[user]
32
+
33
+ command = f"python annotator/annotate.py --user {user} --port {port} --start_idx {start_idx}"
34
+ print(f"Launching for user {user} on port {port}")
35
+ os.system(command)
36
+
37
+ def parse_args():
38
+ parser = argparse.ArgumentParser(description="Launch annotation server for a specific user.")
39
+ parser.add_argument('--user', type=str, required=True, help='Username to launch the server for.')
40
+ args = parser.parse_args()
41
+ return args
42
+
43
+ def main():
44
+ args = parse_args()
45
+ launch(args.user)
46
+
47
+ if __name__ == "__main__":
48
+ main()
note.md ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ # Stars
2
+
3
+ star: 所有compare_images的一致性都较好,难以选出最优和最劣。
4
+ discard: 所有compare_images的一致性都很差。
5
+ 网格问题:ref_image存在网格问题。如果compare_images存在网格问题,则视为一致性很差即可。
6
+
7
+ pbw: 10673->11041