feat: compile manual labels and AI results into unified JSON files in sources folder
This commit is contained in:
1 parent
e3acc36a89
commit
995347a0ea
3 files changed
+2786
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import json
|
||||
import os
|
||||
import glob
|
||||
|
||||
def main():
|
||||
uploads_dir = "backend/uploads"
|
||||
sources_dir = "backend/sources"
|
||||
|
||||
if not os.path.exists(uploads_dir):
|
||||
# Fallback to local paths if run from backend folder
|
||||
uploads_dir = "uploads"
|
||||
sources_dir = "sources"
|
||||
|
||||
manual_pattern = os.path.join(uploads_dir, "manual_label_*.json")
|
||||
results_jsonl = os.path.join(uploads_dir, "test_images_results.jsonl")
|
||||
|
||||
output_manual = os.path.join(sources_dir, "manual_labels.json")
|
||||
output_ai = os.path.join(sources_dir, "ai_results.json")
|
||||
|
||||
# 1. Compile Manual Labels
|
||||
manual_files = glob.glob(manual_pattern)
|
||||
manual_list = []
|
||||
|
||||
for mf in sorted(manual_files):
|
||||
try:
|
||||
with open(mf, "r") as f:
|
||||
data = json.load(f)
|
||||
manual_list.append(data)
|
||||
except Exception as e:
|
||||
print(f"Error reading manual label {mf}: {e}")
|
||||
|
||||
with open(output_manual, "w", encoding="utf-8") as f:
|
||||
json.dump(manual_list, f, indent=2, ensure_ascii=False)
|
||||
print(f"Successfully compiled {len(manual_list)} manual labels into: {output_manual}")
|
||||
|
||||
# 2. Compile AI Results
|
||||
ai_list = []
|
||||
if os.path.exists(results_jsonl):
|
||||
try:
|
||||
with open(results_jsonl, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if not line.strip():
|
||||
continue
|
||||
data = json.loads(line)
|
||||
ai_list.append(data)
|
||||
except Exception as e:
|
||||
print(f"Error reading JSONL results: {e}")
|
||||
|
||||
with open(output_ai, "w", encoding="utf-8") as f:
|
||||
json.dump(ai_list, f, indent=2, ensure_ascii=False)
|
||||
print(f"Successfully compiled {len(ai_list)} AI results into: {output_ai}")
|
||||
else:
|
||||
print(f"Warning: JSONL results file not found at {results_jsonl}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user