This commit is contained in:
2026-06-06 22:09:00 +02:00
parent a80187ba80
commit 27c0dae20e
9 changed files with 315 additions and 69 deletions
+14 -2
View File
@@ -61,6 +61,8 @@ be missing.
##labels##
##wrong_labels##
Here's a list of the names of the students, pick the one that matches
the best or `\"Unknown\"` if you cannot read the name
@@ -116,6 +118,8 @@ be missing.
##labels##
##wrong_labels##
Since this copy isn't the first part of a sequence, simply set the
name to `\"Continued\"`."""
@@ -128,7 +132,7 @@ class AnnotationData(BaseModel):
list: List[BoxItem] = Field(description="List of bounding box items")
def generate_request(file, labels, names, context_labels):
def generate_request(file, labels, names, context_labels, wrong_labels):
"""Generates request for Gemini with context."""
image_path = Path(file)
@@ -142,6 +146,11 @@ def generate_request(file, labels, names, context_labels):
else:
text = my_prompt2.replace("##labels##", labels)\
.replace("##prev_context##", context_str)
if wrong_labels:
text= text.replace("##wrong_labels##\n\n", f"On a previous request, you answered with the following wrong labels : {wrong_labels}. These are wrong, since they do not exactly match any of the labels in the previous list.")
else:
text = text.replace("##wrong_labels##\n\n", "")
contents = [
types.Content(
@@ -271,12 +280,14 @@ def process_copy_group(group_key, files):
print(f"[{group_key}] Processing {image_file.name} with {len(accumulated_labels)} accumulated labels...")
attempt = -1
wrong_labels = []
while True:
attempt += 1
if attempt > 0:
time.sleep(10 * attempt)
try:
contents, config = generate_request(image_file, labels_txt, names_txt, accumulated_labels)
contents, config = generate_request(image_file, labels_txt, names_txt, accumulated_labels,
wrong_labels)
response = client.models.generate_content(
model=MODEL_ID,
@@ -289,6 +300,7 @@ def process_copy_group(group_key, files):
name = annota.name
if unknown:
print(f"Error: {image_file.name} contained unknown labels: {unknown}")
wrong_labels.extend(unknown)
print("Retrying request...")
continue # Retry immediately