mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-29 01:57:41 +03:00
Run genai in thread
This commit is contained in:
parent
5abef619d0
commit
3feca459c7
@ -1,9 +1,11 @@
|
|||||||
"""Post processor for review items to get descriptions."""
|
"""Post processor for review items to get descriptions."""
|
||||||
|
|
||||||
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
@ -60,15 +62,13 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
|||||||
Path(os.path.join(CLIPS_DIR, f"genai-requests/{id}")).mkdir(
|
Path(os.path.join(CLIPS_DIR, f"genai-requests/{id}")).mkdir(
|
||||||
parents=True, exist_ok=True
|
parents=True, exist_ok=True
|
||||||
)
|
)
|
||||||
|
shutil.copy(
|
||||||
for idx, data in enumerate(self.tracked_review_items[id], 1):
|
thumb_path,
|
||||||
shutil.copy(
|
os.path.join(
|
||||||
thumb_path,
|
CLIPS_DIR,
|
||||||
os.path.join(
|
f"genai-requests/{id}/{thumb_time}.webp",
|
||||||
CLIPS_DIR,
|
),
|
||||||
f"genai-requests/{id}/{idx}.webp",
|
)
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if id not in self.tracked_review_items:
|
if id not in self.tracked_review_items:
|
||||||
@ -90,19 +90,35 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
|||||||
self.tracked_review_items.pop(id)
|
self.tracked_review_items.pop(id)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.genai_client.generate_review_description(
|
# kickoff analysis
|
||||||
{
|
threading.Thread(
|
||||||
"camera": camera,
|
target=self.run_analysis,
|
||||||
"objects": final_data["data"]["objects"],
|
args=(
|
||||||
"recognized_objects": final_data["data"]["sub_labels"],
|
self.genai_client,
|
||||||
"zones": final_data["data"]["zones"],
|
camera,
|
||||||
"timestamp": datetime.datetime.fromtimestamp(
|
final_data,
|
||||||
final_data["end_time"]
|
copy.copy([r[1] for r in self.tracked_review_items[id]]),
|
||||||
),
|
),
|
||||||
},
|
).start()
|
||||||
[r[1] for r in self.tracked_review_items[id]],
|
|
||||||
)
|
|
||||||
self.tracked_review_items.pop(id)
|
self.tracked_review_items.pop(id)
|
||||||
|
|
||||||
|
def run_analysis(
|
||||||
|
self,
|
||||||
|
genai_client: GenAIClient,
|
||||||
|
camera: str,
|
||||||
|
final_data: dict[str, str],
|
||||||
|
thumbs: list[bytes],
|
||||||
|
) -> None:
|
||||||
|
genai_client.generate_review_description(
|
||||||
|
{
|
||||||
|
"camera": camera,
|
||||||
|
"objects": final_data["data"]["objects"],
|
||||||
|
"recognized_objects": final_data["data"]["sub_labels"],
|
||||||
|
"zones": final_data["data"]["zones"],
|
||||||
|
"timestamp": datetime.datetime.fromtimestamp(final_data["end_time"]),
|
||||||
|
},
|
||||||
|
thumbs,
|
||||||
|
)
|
||||||
|
|
||||||
def handle_request(self, request_data):
|
def handle_request(self, request_data):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user