aa
This commit is contained in:
@@ -10,6 +10,13 @@ import sys
|
||||
import fcntl
|
||||
import re
|
||||
|
||||
try:
|
||||
from . import database
|
||||
from . import embeddings
|
||||
except ImportError:
|
||||
import database
|
||||
import embeddings
|
||||
|
||||
# Load configuration
|
||||
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "config.json")
|
||||
|
||||
@@ -142,6 +149,7 @@ def process_image(filename):
|
||||
output_filename = f"{timestamp}_{filename}"
|
||||
output_path = os.path.join(CONF["output_dir"], output_filename)
|
||||
|
||||
temp_path = input_path + ".tmp.png"
|
||||
try:
|
||||
logging.info(f"Starting processing for {filename}...")
|
||||
cropped_img = crop_to_bbox(
|
||||
@@ -152,7 +160,6 @@ def process_image(filename):
|
||||
)
|
||||
|
||||
# Save temporary cropped image for upload
|
||||
temp_path = input_path + ".tmp.png"
|
||||
cropped_img.save(temp_path, format="PNG")
|
||||
|
||||
with open(temp_path, 'rb') as f:
|
||||
@@ -169,6 +176,22 @@ def process_image(filename):
|
||||
with open(output_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
logging.info(f"Successfully processed {filename} -> {output_path}")
|
||||
|
||||
# Register in DB
|
||||
try:
|
||||
embedding = embeddings.generate_embedding(output_path)
|
||||
gid = filename
|
||||
database.upsert_person(output_filename, filepath=output_path, embedding=embedding, group_id=gid)
|
||||
|
||||
# Also trigger tagging to get auto-name and clip description
|
||||
tag_url = CONF["api_url"].replace("/edit", "/tag")
|
||||
try:
|
||||
requests.post(tag_url, json={"filename": output_filename, "group_id": gid}, timeout=30)
|
||||
except Exception as tag_err:
|
||||
logging.error(f"Error triggering tagging for {output_filename}: {tag_err}")
|
||||
except Exception as db_err:
|
||||
logging.error(f"Database error registering {output_filename}: {db_err}")
|
||||
|
||||
if os.path.exists(temp_path):
|
||||
os.remove(temp_path)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user