mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 05:24:11 +03:00
fix trigger logic
This commit is contained in:
parent
e957f8d9f9
commit
bf5e0c76fe
@ -1731,37 +1731,40 @@ def create_trigger_embedding(
|
|||||||
if event.data.get("type") != "object":
|
if event.data.get("type") != "object":
|
||||||
return
|
return
|
||||||
|
|
||||||
if thumbnail := get_event_thumbnail_bytes(event):
|
# Get the thumbnail
|
||||||
cursor = context.db.execute_sql(
|
thumbnail = get_event_thumbnail_bytes(event)
|
||||||
"""
|
|
||||||
SELECT thumbnail_embedding FROM vec_thumbnails WHERE id = ?
|
if thumbnail is None:
|
||||||
""",
|
return JSONResponse(
|
||||||
[body.data],
|
content={
|
||||||
|
"success": False,
|
||||||
|
"message": f"Failed to get thumbnail for {body.data} for {body.type} trigger",
|
||||||
|
},
|
||||||
|
status_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
row = cursor.fetchone() if cursor else None
|
# Try to reuse existing embedding from database
|
||||||
|
cursor = context.db.execute_sql(
|
||||||
|
"""
|
||||||
|
SELECT thumbnail_embedding FROM vec_thumbnails WHERE id = ?
|
||||||
|
""",
|
||||||
|
[body.data],
|
||||||
|
)
|
||||||
|
|
||||||
if row:
|
row = cursor.fetchone() if cursor else None
|
||||||
query_embedding = row[0]
|
|
||||||
embedding = np.frombuffer(query_embedding, dtype=np.float32)
|
if row:
|
||||||
|
query_embedding = row[0]
|
||||||
|
embedding = np.frombuffer(query_embedding, dtype=np.float32)
|
||||||
else:
|
else:
|
||||||
# Extract valid thumbnail
|
# Generate new embedding
|
||||||
thumbnail = get_event_thumbnail_bytes(event)
|
|
||||||
|
|
||||||
if thumbnail is None:
|
|
||||||
return JSONResponse(
|
|
||||||
content={
|
|
||||||
"success": False,
|
|
||||||
"message": f"Failed to get thumbnail for {body.data} for {body.type} trigger",
|
|
||||||
},
|
|
||||||
status_code=400,
|
|
||||||
)
|
|
||||||
|
|
||||||
embedding = context.generate_image_embedding(
|
embedding = context.generate_image_embedding(
|
||||||
body.data, (base64.b64encode(thumbnail).decode("ASCII"))
|
body.data, (base64.b64encode(thumbnail).decode("ASCII"))
|
||||||
)
|
)
|
||||||
|
|
||||||
if not embedding:
|
if embedding is None or (
|
||||||
|
isinstance(embedding, (list, np.ndarray)) and len(embedding) == 0
|
||||||
|
):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"success": False,
|
"success": False,
|
||||||
@ -1896,7 +1899,9 @@ def update_trigger_embedding(
|
|||||||
body.data, (base64.b64encode(thumbnail).decode("ASCII"))
|
body.data, (base64.b64encode(thumbnail).decode("ASCII"))
|
||||||
)
|
)
|
||||||
|
|
||||||
if not embedding:
|
if embedding is None or (
|
||||||
|
isinstance(embedding, (list, np.ndarray)) and len(embedding) == 0
|
||||||
|
):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content={
|
content={
|
||||||
"success": False,
|
"success": False,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user