Skip to content

Commit 44586d6

Browse files
committed
Fix in the logic of the code.
Signed-off-by: Bepitic <bepitic@gmail.com>
1 parent 7f454c4 commit 44586d6

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/anomalib/models/image/gptvad/chatgpt.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def api_call(
6969
# If multiple images are provided, the last one is considered anomalous,
7070
# and the rest are treated as normal examples.
7171
prompt = """
72-
You will receive an image that is going to be an example of the typical image without any anomaly,
72+
You will receive a group of images that are going to be an example
73+
of the typical image without any anomaly,
7374
and the last image that you need to decide if it has an anomaly or not.
7475
Answer with a 'NO' if it does not have any anomalies and 'YES: description'
7576
where description is a description of the anomaly provided, position.
@@ -81,21 +82,23 @@ def api_call(
8182
"content": prompt,
8283
},
8384
)
84-
# Add the single image
85-
messages.append(
86-
{
87-
"role": "user",
88-
"content": [
89-
{
90-
"type": "image_url",
91-
"image_url": {
92-
"url": f"data:image/{extension};base64,{images[0]}",
93-
"detail": detail_img,
85+
for image in images:
86+
image_message = [
87+
{
88+
"role": "user",
89+
"content": [
90+
{
91+
"type": "image_url",
92+
"image_url": {
93+
"url": f"data:image/{extension};base64,{image}",
94+
"detail": detail_img,
95+
},
9496
},
95-
},
96-
],
97-
},
98-
)
97+
],
98+
},
99+
]
100+
messages.extend(image_message)
101+
99102
elif len(images) == 1:
100103
# If only one image is provided,
101104
# it is treated as the anomalous image.
@@ -133,22 +136,21 @@ def api_call(
133136
"content": prompt,
134137
},
135138
)
136-
for image in images:
137-
image_message = [
138-
{
139-
"role": "user",
140-
"content": [
141-
{
142-
"type": "image_url",
143-
"image_url": {
144-
"url": f"data:image/{extension};base64,{image}",
145-
"detail": detail_img,
146-
},
139+
# Add the single image
140+
messages.append(
141+
{
142+
"role": "user",
143+
"content": [
144+
{
145+
"type": "image_url",
146+
"image_url": {
147+
"url": f"data:image/{extension};base64,{images[0]}",
148+
"detail": detail_img,
147149
},
148-
],
149-
},
150-
]
151-
messages.extend(image_message)
150+
},
151+
],
152+
},
153+
)
152154
else:
153155
msg = "No images provided for anomaly detection."
154156
raise ValueError(msg)

0 commit comments

Comments
 (0)