diff --git a/main.py b/main.py index f1a0c52..73518ca 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,17 @@ -# main.py import os from flask import Flask, request, render_template from timelapse import process_faces app = Flask(__name__) -# Read critical parameters from environment variables -DEFAULT_API_KEY = os.environ.get("IMMICH_API_KEY", "") -DEFAULT_BASE_URL = os.environ.get("IMMICH_BASE_URL", "") -DEFAULT_OUTPUT_FOLDER = os.environ.get("IMMICH_OUTPUT_FOLDER", "output") +# Critical parameters provided via environment variables +API_KEY = os.environ.get("IMMICH_API_KEY", "") +BASE_URL = os.environ.get("IMMICH_BASE_URL", "") +OUTPUT_FOLDER = os.environ.get("OUTPUT_FOLDER", "output") + +# model paths +FACE_DETECT_MODEL = "mmod_human_face_detector.dat" +LANDMARK_MODEL = "shape_predictor_68_face_landmarks.dat" @app.route("/", methods=["GET", "POST"]) @@ -17,24 +20,17 @@ def index(): error = None if request.method == "POST": try: - # Use environment variable defaults if form fields are empty - api_key = request.form.get("api_key") or DEFAULT_API_KEY - base_url = request.form.get("base_url") or DEFAULT_BASE_URL - output_folder = request.form.get("output_folder") or DEFAULT_OUTPUT_FOLDER + api_key = API_KEY + base_url = BASE_URL + output_folder = OUTPUT_FOLDER person_id = request.form["person_id"] - - # Convert numeric parameters with defaults if conversion fails padding_percent = float(request.form.get("padding_percent", 0.3)) - resize_width = int(request.form.get("resize_width", 512)) - resize_height = int(request.form.get("resize_height", 512)) - min_face_width = int(request.form.get("min_face_width", 128)) - min_face_height = int(request.form.get("min_face_height", 128)) + resize_size = int(request.form.get("resize_size", 512)) + face_resolution_threshold = int(request.form.get("face_resolution_threshold", 128)) pose_threshold = float(request.form.get("pose_threshold", 25)) desired_left_eye_x = float(request.form.get("desired_left_eye_x", 0.35)) desired_left_eye_y = float(request.form.get("desired_left_eye_y", 0.45)) max_workers = int(request.form.get("max_workers", 4)) - face_detect_model_path = request.form.get("face_detect_model_path", "mmod_human_face_detector.dat") - landmark_model_path = request.form.get("landmark_model_path", "shape_predictor_68_face_landmarks.dat") processed_files = process_faces( api_key=api_key, @@ -42,15 +38,15 @@ def index(): person_id=person_id, output_folder=output_folder, padding_percent=padding_percent, - resize_width=resize_width, - resize_height=resize_height, - min_face_width=min_face_width, - min_face_height=min_face_height, + resize_width=resize_size, + resize_height=resize_size, + min_face_width=face_resolution_threshold, + min_face_height=face_resolution_threshold, pose_threshold=pose_threshold, desired_left_eye=(desired_left_eye_x, desired_left_eye_y), max_workers=max_workers, - face_detect_model_path=face_detect_model_path, - landmark_model_path=landmark_model_path + face_detect_model_path=FACE_DETECT_MODEL, + landmark_model_path=LANDMARK_MODEL ) result = f"Finished processing. {len(processed_files)} images saved in '{output_folder}'." except Exception as e: diff --git a/templates/index.html b/templates/index.html index 61ab142..b206aad 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,61 +1,128 @@
+{{ error }}
- {% endif %} - - {% if result %} -{{ error }}
+ {% endif %} + + {% if result %} +{{ result }}
+ {% endif %} +