Prompting.py ; Miscs for Interro29
This commit is contained in:
+17
-1
@@ -13,7 +13,7 @@ print("o to open pdf, O original pdf, e to emacs part, p to go back, i to interr
|
||||
|
||||
# --- Configuration & Globals ---
|
||||
padding = 60
|
||||
|
||||
valid_labels_set = None
|
||||
|
||||
# Queue payload: (pil_image, json_path, metadata)
|
||||
# metadata is a dict: {'copie': str, 'part': int, 'schema': dict}
|
||||
@@ -277,6 +277,17 @@ class ImageViewer:
|
||||
self.current_meta["schema"]
|
||||
)
|
||||
|
||||
labels = [v["label"] for v in current_data["list"]]
|
||||
labels = [label for label in labels if label != "_"]
|
||||
labels = [label[1:] for label in labels if label[0] == "|"]
|
||||
labels = [label[:-1] for label in labels if label[-1] == "|"]
|
||||
false_labels = [label for label in labels if label not in valid_labels_set]
|
||||
|
||||
if false_labels:
|
||||
msg = f"Wrong label in {self.current_json_path.name}: {false_labels}\n\n\tPlease press 'e' to fix it, then press Enter again."
|
||||
print(msg)
|
||||
messagebox.showerror("Label Error", msg)
|
||||
return
|
||||
num_added = len(converted_items)
|
||||
|
||||
# Add to accumulator
|
||||
@@ -362,6 +373,7 @@ if __name__ == "__main__":
|
||||
input_path = Path(sys.argv[1])
|
||||
files_to_process = []
|
||||
|
||||
|
||||
if input_path.is_file():
|
||||
# Correctly identify base_dir if we are in 'Copies' or 'Cutleft'
|
||||
if input_path.parent.name in ["Copies", "Cutleft"]:
|
||||
@@ -386,6 +398,10 @@ if __name__ == "__main__":
|
||||
sys.exit(1)
|
||||
files_to_process = sorted(cutleft_dir.glob("*.jpg"))
|
||||
|
||||
labels_txt = (base_dir / "labels").read_text()
|
||||
valid_labels_set = set(line.strip() for line in labels_txt.splitlines() if line.strip())
|
||||
|
||||
|
||||
try:
|
||||
all_labels = read_all_labels(base_dir)
|
||||
except FileNotFoundError:
|
||||
|
||||
Reference in New Issue
Block a user