Files

50 lines
1.4 KiB
Python

import sys
import os
import argparse
from flask import Flask, request, jsonify
# Add current dir to path to import detector and config
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from detector import FacialRotationDetector
app = Flask(__name__)
detector = None
@app.route('/process', methods=['POST'])
def process():
data = request.json
input_path = data.get('input')
output_path = data.get('output')
if not input_path or not output_path:
return jsonify({'success': False, 'error': 'Missing input or output path'})
try:
result = detector.process_image(input_path, output_path)
return jsonify(result)
except Exception as e:
return jsonify({'success': False, 'error': str(e)})
@app.route('/health', methods=['GET'])
def health():
return jsonify({'status': 'ok'})
def main():
global detector
parser = argparse.ArgumentParser()
parser.add_argument('--port', type=int, required=True, help='Port to run the worker on')
args = parser.parse_args()
# Pre-load the model
print("Loading facial rotation model...")
detector = FacialRotationDetector()
detector.load_model()
print("Model loaded successfully.")
# Disable reloader to prevent double loading
app.run(host='127.0.0.1', port=args.port, debug=False, use_reloader=False)
if __name__ == '__main__':
main()