Spaces:
Starting
Starting
Hodfa commited on
Commit ·
f1edeb6
0
Parent(s):
deploy: Vision AI Engine - Face Recognition App
Browse files- .gitattributes +38 -0
- .gitignore +8 -0
- Dockerfile +40 -0
- README.md +10 -0
- app/__init__.py +44 -0
- app/routes/__init__.py +0 -0
- app/routes/analysis_routes.py +130 -0
- app/routes/main_routes.py +31 -0
- app/routes/recognition_routes.py +59 -0
- app/static/demo/cv_match.png +3 -0
- app/static/demo/verification.png +3 -0
- app/static/favicon.png +3 -0
- app/static/uploads/.gitkeep +0 -0
- app/templates/404.html +12 -0
- app/templates/500.html +13 -0
- app/templates/about.html +55 -0
- app/templates/analysis.html +84 -0
- app/templates/analysis_result.html +116 -0
- app/templates/dashboard.html +104 -0
- app/templates/identify.html +31 -0
- app/templates/layout.html +266 -0
- app/templates/live.html +509 -0
- app/templates/verification.html +76 -0
- app/templates/verification_result.html +68 -0
- app/utils/__init__.py +0 -0
- app/utils/ml_engine.py +144 -0
- requirements.txt +11 -0
- run.py +30 -0
- scripts/download.py +52 -0
- scripts/download_weights.py +81 -0
- scripts/start_project.py +50 -0
.gitattributes
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
app/static/uploads/*
|
| 2 |
+
!app/static/uploads/.gitkeep
|
| 3 |
+
**/__pycache__/
|
| 4 |
+
*.pyc
|
| 5 |
+
*.pyo
|
| 6 |
+
.env
|
| 7 |
+
.deepface/
|
| 8 |
+
*.log
|
Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# VISION.AI - Hugging Face Spaces Optimized
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# System dependencies for OpenCV & TensorFlow
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
build-essential \
|
| 7 |
+
git \
|
| 8 |
+
libgl1-mesa-glx \
|
| 9 |
+
libglib2.0-0 \
|
| 10 |
+
libsm6 \
|
| 11 |
+
libxext6 \
|
| 12 |
+
libxrender-dev \
|
| 13 |
+
libatlas-base-dev \
|
| 14 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
+
|
| 16 |
+
WORKDIR /app
|
| 17 |
+
|
| 18 |
+
# Create model cache directory
|
| 19 |
+
RUN mkdir -p /tmp/deepface_weights
|
| 20 |
+
|
| 21 |
+
# Install Python dependencies
|
| 22 |
+
COPY requirements.txt .
|
| 23 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 24 |
+
pip install --no-cache-dir -r requirements.txt
|
| 25 |
+
|
| 26 |
+
# Copy application code
|
| 27 |
+
COPY . .
|
| 28 |
+
|
| 29 |
+
# Pre-download AI models during build
|
| 30 |
+
RUN python -c "from deepface import DeepFace; DeepFace.build_model('Age'); DeepFace.build_model('Gender'); DeepFace.build_model('Emotion'); DeepFace.build_model('Race')" 2>&1 | grep -v "^$" || true
|
| 31 |
+
|
| 32 |
+
# Expose port 7860 (Hugging Face Spaces standard)
|
| 33 |
+
EXPOSE 7860
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
| 37 |
+
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/').read()" || exit 1
|
| 38 |
+
|
| 39 |
+
# Start app on port 7860
|
| 40 |
+
CMD ["gunicorn", "-w", "2", "-b", "0.0.0.0:7860", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "run:app"]
|
README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Vision Ai Engine
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app/__init__.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, jsonify
|
| 2 |
+
from flask_cors import CORS
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def create_app(test_config=None):
|
| 9 |
+
# create and configure the app
|
| 10 |
+
app = Flask(__name__, instance_relative_config=True)
|
| 11 |
+
app.config.from_mapping(
|
| 12 |
+
SECRET_KEY='dev',
|
| 13 |
+
UPLOAD_FOLDER=os.path.join(app.root_path, 'static', 'uploads'),
|
| 14 |
+
ALLOWED_EXTENSIONS={'png', 'jpg', 'jpeg'},
|
| 15 |
+
MAX_CONTENT_LENGTH=16 * 1024 * 1024, # 16MB max
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
if test_config is None:
|
| 19 |
+
# load the instance config, if it exists, when not testing
|
| 20 |
+
app.config.from_pyfile('config.py', silent=True)
|
| 21 |
+
else:
|
| 22 |
+
# load the test config if passed in
|
| 23 |
+
app.config.from_mapping(test_config)
|
| 24 |
+
|
| 25 |
+
# ensure the upload folder exists
|
| 26 |
+
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 27 |
+
|
| 28 |
+
CORS(app)
|
| 29 |
+
|
| 30 |
+
# Register Blueprints
|
| 31 |
+
from .routes import main_routes, analysis_routes, recognition_routes
|
| 32 |
+
app.register_blueprint(main_routes.bp)
|
| 33 |
+
app.register_blueprint(analysis_routes.bp)
|
| 34 |
+
app.register_blueprint(recognition_routes.bp)
|
| 35 |
+
|
| 36 |
+
@app.errorhandler(404)
|
| 37 |
+
def page_not_found(e):
|
| 38 |
+
return render_template('404.html'), 404
|
| 39 |
+
|
| 40 |
+
@app.errorhandler(500)
|
| 41 |
+
def internal_server_error(e):
|
| 42 |
+
return render_template('500.html'), 500
|
| 43 |
+
|
| 44 |
+
return app
|
app/routes/__init__.py
ADDED
|
File without changes
|
app/routes/analysis_routes.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, flash, current_app, jsonify, redirect, url_for
|
| 2 |
+
import os
|
| 3 |
+
import uuid
|
| 4 |
+
import base64
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from werkzeug.utils import secure_filename
|
| 8 |
+
from ..utils.ml_engine import FaceAnalyzer
|
| 9 |
+
|
| 10 |
+
bp = Blueprint('analysis', __name__, url_prefix='/analysis')
|
| 11 |
+
analyzer = FaceAnalyzer()
|
| 12 |
+
|
| 13 |
+
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
| 14 |
+
|
| 15 |
+
def allowed_file(filename):
|
| 16 |
+
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 17 |
+
|
| 18 |
+
@bp.route('/')
|
| 19 |
+
def index():
|
| 20 |
+
"""Upload and analyze face for emotions, age, gender."""
|
| 21 |
+
return render_template('analysis.html')
|
| 22 |
+
|
| 23 |
+
@bp.route('/upload', methods=['POST'])
|
| 24 |
+
def upload_and_analyze():
|
| 25 |
+
"""Handle image upload and run DeepFace analysis."""
|
| 26 |
+
if 'file' not in request.files:
|
| 27 |
+
flash('No file part')
|
| 28 |
+
return redirect(request.url)
|
| 29 |
+
|
| 30 |
+
file = request.files['file']
|
| 31 |
+
|
| 32 |
+
if file.filename == '':
|
| 33 |
+
flash('No selected file')
|
| 34 |
+
return redirect(request.url)
|
| 35 |
+
|
| 36 |
+
if file and allowed_file(file.filename):
|
| 37 |
+
# Save file with unique name
|
| 38 |
+
extension = file.filename.rsplit('.', 1)[1].lower()
|
| 39 |
+
unique_filename = f"{uuid.uuid4()}.{extension}"
|
| 40 |
+
filepath = os.path.join(current_app.config['UPLOAD_FOLDER'], unique_filename)
|
| 41 |
+
file.save(filepath)
|
| 42 |
+
|
| 43 |
+
# Run analysis
|
| 44 |
+
result = analyzer.analyze(filepath)
|
| 45 |
+
|
| 46 |
+
# Handle engine errors (e.g., model loading issues)
|
| 47 |
+
if 'error' in result:
|
| 48 |
+
flash(f"Analysis Engine Error: {result['error']}")
|
| 49 |
+
return redirect(url_for('analysis.index'))
|
| 50 |
+
|
| 51 |
+
# Handle cases where no faces were detected
|
| 52 |
+
if not result.get('faces') or result.get('count', 0) == 0:
|
| 53 |
+
flash("No faces detected in the provided image.")
|
| 54 |
+
return redirect(url_for('analysis.index'))
|
| 55 |
+
|
| 56 |
+
return render_template('analysis_result.html', result=result, image=unique_filename)
|
| 57 |
+
|
| 58 |
+
@bp.route('/live')
|
| 59 |
+
def live_view():
|
| 60 |
+
"""Render the live webcam analysis view."""
|
| 61 |
+
return render_template('live.html')
|
| 62 |
+
|
| 63 |
+
@bp.route('/live_frame', methods=['POST'])
|
| 64 |
+
def live_frame():
|
| 65 |
+
"""Handle base64 frame from webcam and return analysis."""
|
| 66 |
+
try:
|
| 67 |
+
data = request.json
|
| 68 |
+
if not data or 'image' not in data:
|
| 69 |
+
return jsonify({"error": "No image data"}), 400
|
| 70 |
+
|
| 71 |
+
# Robust base64 extraction
|
| 72 |
+
image_b64 = data['image']
|
| 73 |
+
if "," in image_b64:
|
| 74 |
+
image_b64 = image_b64.split(",")[1]
|
| 75 |
+
|
| 76 |
+
image_data = base64.b64decode(image_b64)
|
| 77 |
+
|
| 78 |
+
# Save temp frame (with enhancement)
|
| 79 |
+
temp_filename = f"live_{uuid.uuid4()}.jpg"
|
| 80 |
+
temp_path = os.path.join(current_app.config['UPLOAD_FOLDER'], temp_filename)
|
| 81 |
+
|
| 82 |
+
# Load and Enhance for AI precision
|
| 83 |
+
img = Image.open(BytesIO(image_data))
|
| 84 |
+
from PIL import ImageEnhance
|
| 85 |
+
enhancer = ImageEnhance.Sharpness(img)
|
| 86 |
+
img = enhancer.enhance(2.2) # High intensity sharpening for glasses
|
| 87 |
+
contrast = ImageEnhance.Contrast(img)
|
| 88 |
+
img = contrast.enhance(1.4)
|
| 89 |
+
img = img.convert("RGB")
|
| 90 |
+
img.save(temp_path, "JPEG", quality=95)
|
| 91 |
+
|
| 92 |
+
# Set accuracy backend
|
| 93 |
+
accuracy = data.get('accuracy', 'standard')
|
| 94 |
+
if accuracy == 'high':
|
| 95 |
+
# Temporary hi-res analyzer for this specific frame
|
| 96 |
+
hi_res_analyzer = FaceAnalyzer(detector_backend='retinaface')
|
| 97 |
+
result = hi_res_analyzer.analyze(temp_path)
|
| 98 |
+
else:
|
| 99 |
+
# Use global high-speed analyzer
|
| 100 |
+
result = analyzer.analyze(temp_path)
|
| 101 |
+
|
| 102 |
+
# Cleanup
|
| 103 |
+
if os.path.exists(temp_path):
|
| 104 |
+
os.remove(temp_path)
|
| 105 |
+
|
| 106 |
+
return jsonify({"results": result})
|
| 107 |
+
|
| 108 |
+
except Exception as e:
|
| 109 |
+
current_app.logger.error(f"Live Frame Error: {str(e)}")
|
| 110 |
+
return jsonify({"error": str(e)}), 500
|
| 111 |
+
|
| 112 |
+
return render_template('analysis.html', error="Invalid file type.")
|
| 113 |
+
|
| 114 |
+
@bp.route('/api/analyze', methods=['POST'])
|
| 115 |
+
def api_analyze():
|
| 116 |
+
"""API endpoint for asynchronous analysis (webcam or direct upload)."""
|
| 117 |
+
if 'file' not in request.files:
|
| 118 |
+
return jsonify({"error": "No file uploaded"}), 400
|
| 119 |
+
|
| 120 |
+
file = request.files['file']
|
| 121 |
+
if file and allowed_file(file.filename):
|
| 122 |
+
extension = file.filename.rsplit('.', 1)[1].lower()
|
| 123 |
+
unique_filename = f"{uuid.uuid4()}.{extension}"
|
| 124 |
+
filepath = os.path.join(current_app.config['UPLOAD_FOLDER'], unique_filename)
|
| 125 |
+
file.save(filepath)
|
| 126 |
+
|
| 127 |
+
result = analyzer.analyze(filepath)
|
| 128 |
+
return jsonify(result)
|
| 129 |
+
|
| 130 |
+
return jsonify({"error": "Invalid format"}), 400
|
app/routes/main_routes.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
bp = Blueprint('main', __name__)
|
| 5 |
+
|
| 6 |
+
@bp.route('/')
|
| 7 |
+
def index():
|
| 8 |
+
"""Redirect to dashboard or render home."""
|
| 9 |
+
return render_template('dashboard.html')
|
| 10 |
+
|
| 11 |
+
@bp.route('/dashboard')
|
| 12 |
+
def dashboard():
|
| 13 |
+
"""Main dashboard with use case selection."""
|
| 14 |
+
return render_template('dashboard.html')
|
| 15 |
+
|
| 16 |
+
@bp.route('/base')
|
| 17 |
+
def legacy_base():
|
| 18 |
+
return redirect(url_for('main.dashboard'))
|
| 19 |
+
|
| 20 |
+
@bp.route('/faceapp')
|
| 21 |
+
def legacy_faceapp():
|
| 22 |
+
return redirect(url_for('analysis.index'))
|
| 23 |
+
|
| 24 |
+
@bp.route('/faceapp/gender', methods=['GET', 'POST'])
|
| 25 |
+
def legacy_gender():
|
| 26 |
+
return redirect(url_for('analysis.index'))
|
| 27 |
+
|
| 28 |
+
@bp.route('/about')
|
| 29 |
+
def about():
|
| 30 |
+
"""Project description and CV highlights."""
|
| 31 |
+
return render_template('about.html')
|
app/routes/recognition_routes.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, render_template, request, flash, current_app, jsonify, redirect, url_for
|
| 2 |
+
import os
|
| 3 |
+
import uuid
|
| 4 |
+
from werkzeug.utils import secure_filename
|
| 5 |
+
from ..utils.ml_engine import FaceAnalyzer
|
| 6 |
+
|
| 7 |
+
bp = Blueprint('recognition', __name__, url_prefix='/recognition')
|
| 8 |
+
analyzer = FaceAnalyzer()
|
| 9 |
+
|
| 10 |
+
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
|
| 11 |
+
|
| 12 |
+
def allowed_file(filename):
|
| 13 |
+
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
| 14 |
+
|
| 15 |
+
@bp.route('/verify', methods=['GET', 'POST'])
|
| 16 |
+
def verify_face():
|
| 17 |
+
"""Compare two images to see if they are the same person."""
|
| 18 |
+
if request.method == 'POST':
|
| 19 |
+
if 'img1' not in request.files or 'img2' not in request.files:
|
| 20 |
+
flash('Two images are required.')
|
| 21 |
+
return redirect(request.url)
|
| 22 |
+
|
| 23 |
+
img1 = request.files['img1']
|
| 24 |
+
img2 = request.files['img2']
|
| 25 |
+
|
| 26 |
+
if img1 and allowed_file(img1.filename) and img2 and allowed_file(img2.filename):
|
| 27 |
+
# Save files with unique names
|
| 28 |
+
u1 = f"v1_{uuid.uuid4()}.{img1.filename.rsplit('.', 1)[1].lower()}"
|
| 29 |
+
u2 = f"v2_{uuid.uuid4()}.{img2.filename.rsplit('.', 1)[1].lower()}"
|
| 30 |
+
|
| 31 |
+
p1 = os.path.join(current_app.config['UPLOAD_FOLDER'], u1)
|
| 32 |
+
p2 = os.path.join(current_app.config['UPLOAD_FOLDER'], u2)
|
| 33 |
+
|
| 34 |
+
img1.save(p1)
|
| 35 |
+
img2.save(p2)
|
| 36 |
+
|
| 37 |
+
# Run DeepFace verify
|
| 38 |
+
# 'VGG-Face' is a good default, also 'Facenet'
|
| 39 |
+
model_name = request.form.get('model', 'VGG-Face')
|
| 40 |
+
result = analyzer.verify(p1, p2, model_name=model_name)
|
| 41 |
+
|
| 42 |
+
if 'error' in result:
|
| 43 |
+
# If error occurs (like weights missing), show error on the verification page
|
| 44 |
+
flash(f"Verification Engine Error: {result['error']}")
|
| 45 |
+
return redirect(request.url)
|
| 46 |
+
|
| 47 |
+
return render_template('verification_result.html', result=result, img1=u1, img2=u2)
|
| 48 |
+
|
| 49 |
+
flash('Invalid image format.')
|
| 50 |
+
return redirect(request.url)
|
| 51 |
+
|
| 52 |
+
return render_template('verification.html')
|
| 53 |
+
|
| 54 |
+
@bp.route('/identify', methods=['GET', 'POST'])
|
| 55 |
+
def identify_face():
|
| 56 |
+
"""Find a face in a database of known faces."""
|
| 57 |
+
# (Optional: If the user provides a DB directory, identify the person.)
|
| 58 |
+
# For CV, we could pre-load a small DB of people.
|
| 59 |
+
return render_template('identify.html')
|
app/static/demo/cv_match.png
ADDED
|
Git LFS Details
|
app/static/demo/verification.png
ADDED
|
Git LFS Details
|
app/static/favicon.png
ADDED
|
|
Git LFS Details
|
app/static/uploads/.gitkeep
ADDED
|
File without changes
|
app/templates/404.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div style="height: 70vh; display: flex; flex-direction: column; align-items:center; justify-content:center; text-align:center;">
|
| 5 |
+
<h1 style="font-size: 8rem; font-family: 'Outfit'; color: var(--accent); opacity: 0.2;">404</h1>
|
| 6 |
+
<h2 style="margin-bottom: 1.5rem;">RESOURCE NOT FOUND</h2>
|
| 7 |
+
<p style="color: var(--text-secondary); margin-bottom: 2rem;">The analysis path or subject record you are looking for does not exist in our neural cache.</p>
|
| 8 |
+
<a href="{{ url_for('main.dashboard') }}" class="btn">
|
| 9 |
+
<i class="fa-solid fa-home"></i> Back to Dashboard
|
| 10 |
+
</a>
|
| 11 |
+
</div>
|
| 12 |
+
{% endblock %}
|
app/templates/500.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div style="height: 70vh; display: flex; flex-direction: column; align-items:center; justify-content:center; text-align:center;">
|
| 5 |
+
<h1 style="font-size: 8rem; font-family: 'Outfit'; color: var(--error); opacity: 0.2;">500</h1>
|
| 6 |
+
<h2 style="margin-bottom: 1.5rem; color: var(--error);">MODEL COLLISION DETECTED</h2>
|
| 7 |
+
<p style="color: var(--text-secondary); margin-bottom: 1rem;">An internal inference error occurred or the server ran out of memory (OOM).</p>
|
| 8 |
+
<p style="font-size: 0.8rem; color: var(--text-secondary); font-family: monospace; background: rgba(0,0,0,0.5); padding: 10px; border-radius: 5px; margin-bottom: 2rem;">[Trace: FaceDetector Initialization Failure or Image Encoding Error]</p>
|
| 9 |
+
<a href="{{ url_for('main.dashboard') }}" class="btn" style="background: var(--error); border: none;">
|
| 10 |
+
<i class="fa-solid fa-redo"></i> Restart Application Session
|
| 11 |
+
</a>
|
| 12 |
+
</div>
|
| 13 |
+
{% endblock %}
|
app/templates/about.html
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">About the Vision Engine</h1>
|
| 6 |
+
<p class="animate-up">An advanced biometric analysis suite built for modern security and social intelligence.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="card animate-up" style="line-height: 1.8; font-size: 1.1rem; border-left: 5px solid var(--accent);">
|
| 10 |
+
<h2 style="font-family: 'Outfit'; margin-bottom: 2rem;">Research & Methodology</h2>
|
| 11 |
+
<p style="margin-bottom: 1.5rem;">
|
| 12 |
+
This project implements a multi-model pipeline for facial biometric extraction. Unlike traditional Euclidean geometry-based approaches, it leverages **Deep Convolutional Neural Networks (CNNs)** to extract high-dimensional embedding vectors.
|
| 13 |
+
</p>
|
| 14 |
+
|
| 15 |
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; margin: 3rem 0;">
|
| 16 |
+
<div class="card" style="background: rgba(255,255,255,0.02);">
|
| 17 |
+
<h4 style="color: var(--accent); margin-bottom: 1rem;">Recognition Backbone</h4>
|
| 18 |
+
<p style="font-size: 0.9rem; color: var(--text-secondary);">
|
| 19 |
+
Utilizes **VGG-Face** and **FaceNet** (developed by Google researchers). These models map face images to a compact Euclidean space where distances directly correspond to a measure of face similarity.
|
| 20 |
+
</p>
|
| 21 |
+
</div>
|
| 22 |
+
<div class="card" style="background: rgba(255,255,255,0.02);">
|
| 23 |
+
<h4 style="color: var(--accent); margin-bottom: 1rem;">Detection Strategy</h4>
|
| 24 |
+
<p style="font-size: 0.9rem; color: var(--text-secondary);">
|
| 25 |
+
Supports **RetinaFace**, a state-of-the-art pixel-wise face localization method that outperforms traditional MTCNN through a joint multi-task loss approach.
|
| 26 |
+
</p>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
<h3 style="font-family: 'Outfit'; margin-bottom: 1rem;">Technical Specifications</h3>
|
| 31 |
+
<ul style="list-style: none; padding-left: 0;">
|
| 32 |
+
<li style="margin-bottom: 15px; display: flex; align-items: center; gap: 10px;">
|
| 33 |
+
<i class="fa-solid fa-check-circle" style="color: var(--success);"></i>
|
| 34 |
+
<span><strong>Framework:</strong> Flask with Blueprint Factory Pattern</span>
|
| 35 |
+
</li>
|
| 36 |
+
<li style="margin-bottom: 15px; display: flex; align-items: center; gap: 10px;">
|
| 37 |
+
<i class="fa-solid fa-check-circle" style="color: var(--success);"></i>
|
| 38 |
+
<span><strong>DL Engine:</strong> TensorFlow / Keras (oneDNN Optimized)</span>
|
| 39 |
+
</li>
|
| 40 |
+
<li style="margin-bottom: 15px; display: flex; align-items: center; gap: 10px;">
|
| 41 |
+
<i class="fa-solid fa-check-circle" style="color: var(--success);"></i>
|
| 42 |
+
<span><strong>Pre-processing:</strong> OpenCV / Pillow (Bilinear Interpolation)</span>
|
| 43 |
+
</li>
|
| 44 |
+
<li style="margin-bottom: 15px; display: flex; align-items: center; gap: 10px;">
|
| 45 |
+
<i class="fa-solid fa-check-circle" style="color: var(--success);"></i>
|
| 46 |
+
<span><strong>UI Styling:</strong> Glassmorphism (Vanilla CSS 3.0)</span>
|
| 47 |
+
</li>
|
| 48 |
+
</ul>
|
| 49 |
+
|
| 50 |
+
<div style="margin-top: 3rem; border-top: 1px solid var(--glass-border); padding-top: 2rem; display: flex; align-items: center; justify-content: space-between;">
|
| 51 |
+
<p style="color: var(--text-secondary); font-size: 0.9rem;">Revision: 2.0.4 | Engine: RetinaFace stable</p>
|
| 52 |
+
<a href="{{ url_for('main.dashboard') }}" class="btn">Return to Dashboard</a>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
{% endblock %}
|
app/templates/analysis.html
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Facial Analysis</h1>
|
| 6 |
+
<p class="animate-up">Upload an image to identify demographics and emotional state.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="card animate-up" id="dropzone" style="max-width: 600px; margin: 0 auto; text-align: center; border: 2px dashed rgba(37, 99, 235, 0.3); border-radius: 30px; transition: all 0.3s ease; padding: 3rem;">
|
| 10 |
+
{% if error %}
|
| 11 |
+
<div id="error-msg" style="background: rgba(239, 68, 68, 0.1); color: var(--error); padding: 1rem; border-radius: 12px; margin-bottom: 2rem; border: 1px solid rgba(239, 68, 68, 0.2);">
|
| 12 |
+
<i class="fa-solid fa-circle-exclamation"></i> {{ error }}
|
| 13 |
+
</div>
|
| 14 |
+
{% endif %}
|
| 15 |
+
|
| 16 |
+
<div id="upload-content">
|
| 17 |
+
<i class="fa-solid fa-dna" style="font-size: 4rem; color: var(--accent); margin-bottom: 1.5rem; animation: pulse 2s infinite;"></i>
|
| 18 |
+
<h2 style="font-family: 'Outfit'; margin-bottom: 1rem;">Neural Selection Zone</h2>
|
| 19 |
+
<p style="color: var(--text-secondary); margin-bottom: 2.5rem; font-size: 0.95rem;">Please select a clear portrait image for biometric extraction.</p>
|
| 20 |
+
|
| 21 |
+
<form id="uploadForm" action="{{ url_for('analysis.upload_and_analyze') }}" method="post" enctype="multipart/form-data">
|
| 22 |
+
<input type="file" name="file" id="fileInput" hidden accept=".jpg,.jpeg,.png">
|
| 23 |
+
<button type="button" class="btn" onclick="document.getElementById('fileInput').click()" style="padding: 1rem 3rem; font-size: 1rem; font-weight: 700; gap: 12px;">
|
| 24 |
+
<i class="fa-solid fa-camera"></i> SELECT SUBJECT
|
| 25 |
+
</button>
|
| 26 |
+
</form>
|
| 27 |
+
|
| 28 |
+
<p style="margin-top: 2rem; font-size: 0.8rem; color: rgba(255,255,255,0.3); letter-spacing: 1px;">SUPPORTED: JPG / PNG (MAX 16MB)</p>
|
| 29 |
+
</div>
|
| 30 |
+
|
| 31 |
+
<div id="loading-content" style="display: none;">
|
| 32 |
+
<i class="fa-solid fa-microchip fa-spin" style="font-size: 4rem; color: var(--accent); margin-bottom: 2rem;"></i>
|
| 33 |
+
<h2 style="font-family: 'Outfit'; color: var(--accent);">EXTRACTING BIOMETRICS...</h2>
|
| 34 |
+
<p style="color: var(--text-secondary);">Initializing RetinaFace detector. This may take 2-5 seconds.</p>
|
| 35 |
+
</div>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
<script>
|
| 39 |
+
const fileInput = document.getElementById('fileInput');
|
| 40 |
+
const uploadForm = document.getElementById('uploadForm');
|
| 41 |
+
const uploadContent = document.getElementById('upload-content');
|
| 42 |
+
const loadingContent = document.getElementById('loading-content');
|
| 43 |
+
const dropzone = document.getElementById('dropzone');
|
| 44 |
+
|
| 45 |
+
fileInput.onchange = (e) => {
|
| 46 |
+
const file = e.target.files[0];
|
| 47 |
+
if (!file) return;
|
| 48 |
+
|
| 49 |
+
// VALIDATION
|
| 50 |
+
const allowedTypes = ['image/jpeg', 'image/png', 'image/jpg'];
|
| 51 |
+
if (!allowedTypes.includes(file.type)) {
|
| 52 |
+
alert("⚠️ UNSUPPORTED FORMAT: Please select a JPG or PNG image.");
|
| 53 |
+
fileInput.value = '';
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// UI TRANSITION
|
| 58 |
+
uploadContent.style.display = 'none';
|
| 59 |
+
loadingContent.style.display = 'block';
|
| 60 |
+
dropzone.style.borderStyle = 'solid';
|
| 61 |
+
dropzone.style.borderColor = 'var(--accent)';
|
| 62 |
+
|
| 63 |
+
uploadForm.submit();
|
| 64 |
+
};
|
| 65 |
+
</script>
|
| 66 |
+
|
| 67 |
+
<div class="card animate-up" style="margin-top: 3rem;">
|
| 68 |
+
<h3 style="margin-bottom: 1.5rem; font-family: 'Outfit';">Engine Details</h3>
|
| 69 |
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem;">
|
| 70 |
+
<div style="background: rgba(37, 99, 235, 0.05); padding: 1rem; border-radius: 12px; border-left: 4px solid var(--accent);">
|
| 71 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 5px;">Detector</p>
|
| 72 |
+
<p style="font-weight: 600;">RetinaFace (SOTA)</p>
|
| 73 |
+
</div>
|
| 74 |
+
<div style="background: rgba(16, 185, 129, 0.05); padding: 1rem; border-radius: 12px; border-left: 4px solid var(--success);">
|
| 75 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 5px;">Backends</p>
|
| 76 |
+
<p style="font-weight: 600;">TensorFlow + Keras</p>
|
| 77 |
+
</div>
|
| 78 |
+
<div style="background: rgba(99, 102, 241, 0.05); padding: 1rem; border-radius: 12px; border-left: 4px solid #6366f1;">
|
| 79 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 5px;">Metrics</p>
|
| 80 |
+
<p style="font-weight: 600;">Confidence-Weighted</p>
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
</div>
|
| 84 |
+
{% endblock %}
|
app/templates/analysis_result.html
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Analysis Results</h1>
|
| 6 |
+
<p class="animate-up" style="font-weight: 500;">Processed in <span style="color: var(--accent); font-weight: 700;">{{ "%.2f"|format(result.process_time) }}s</span> • <span style="color: var(--success);">✓ {{ result.count }} face(s) detected</span></p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="grid-container" style="display: grid; grid-template-columns: 1fr 1.5fr; gap: 3rem;">
|
| 10 |
+
<!-- Image Preview Panel -->
|
| 11 |
+
<div class="card animate-up" style="padding: 1rem; overflow: hidden; border-radius: 20px; display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 2rem;">
|
| 12 |
+
<div style="position: relative; border-radius: 15px; overflow: hidden; border: 1px solid var(--glass-border);">
|
| 13 |
+
<img src="{{ url_for('static', filename='uploads/' + image) }}" style="width: 100%; display: block; border-radius: 15px;">
|
| 14 |
+
<div style="position: absolute; top: 10px; right: 10px; background: rgba(16, 185, 129, 0.9); color: white; padding: 6px 12px; border-radius: 20px; font-size: 0.75rem; font-weight: 700;">{{ result.count }} Face(s)</div>
|
| 15 |
+
</div>
|
| 16 |
+
<a href="{{ url_for('analysis.index') }}" class="btn" style="justify-content: center; width: 100%; padding: 1rem; font-weight: 700; letter-spacing: 0.5px;">
|
| 17 |
+
<i class="fa-solid fa-arrows-rotate"></i> NEW ANALYSIS
|
| 18 |
+
</a>
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<!-- Results Panel -->
|
| 22 |
+
<div style="display: flex; flex-direction: column; gap: 2rem;">
|
| 23 |
+
{% for face in result.faces %}
|
| 24 |
+
<div class="card animate-up" style="border-left: 4px solid var(--accent); overflow: hidden;">
|
| 25 |
+
<!-- Header -->
|
| 26 |
+
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--glass-border);">
|
| 27 |
+
<h2 style="font-family: 'Outfit'; font-size: 1.3rem; margin: 0;">Subject #{{ loop.index }}</h2>
|
| 28 |
+
<div style="display: flex; gap: 10px;">
|
| 29 |
+
<span style="font-size: 0.85rem; color: white; background: rgba(16, 185, 129, 0.15); padding: 6px 12px; border-radius: 20px; border: 1px solid rgba(16, 185, 129, 0.3); font-weight: 600;">
|
| 30 |
+
<i class="fa-solid fa-face-smile" style="color: var(--success); margin-right: 5px;"></i>
|
| 31 |
+
{{ "%.1f"|format(face.face_confidence * 100) }}% Match
|
| 32 |
+
</span>
|
| 33 |
+
</div>
|
| 34 |
+
</div>
|
| 35 |
+
|
| 36 |
+
<!-- Demographics Stats Grid -->
|
| 37 |
+
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 2rem; margin-bottom: 2.5rem;">
|
| 38 |
+
<!-- Gender -->
|
| 39 |
+
<div style="padding: 1.5rem; background: rgba(37, 99, 235, 0.08); border-radius: 12px; border: 1px solid rgba(37, 99, 235, 0.2);">
|
| 40 |
+
<p style="text-transform: uppercase; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 8px; font-weight: 700; letter-spacing: 0.5px;">Gender Identification</p>
|
| 41 |
+
<h3 style="font-size: 1.8rem; color: var(--accent); font-weight: 800; margin-bottom: 8px;">{{ face.dominant_gender }}</h3>
|
| 42 |
+
<div style="display: flex; align-items: center; gap: 8px;">
|
| 43 |
+
<div style="flex: 1; height: 4px; background: rgba(37, 99, 235, 0.2); border-radius: 2px; overflow: hidden;">
|
| 44 |
+
<div style="width: {{ face.gender[face.dominant_gender] }}%; height: 100%; background: linear-gradient(90deg, var(--accent), #60a5fa); transition: width 0.6s ease;"></div>
|
| 45 |
+
</div>
|
| 46 |
+
<span style="color: var(--text-secondary); font-size: 0.8rem; min-width: 35px; text-align: right;">{{ "%.0f"|format(face.gender[face.dominant_gender]) }}%</span>
|
| 47 |
+
</div>
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<!-- Age -->
|
| 51 |
+
<div style="padding: 1.5rem; background: rgba(59, 130, 246, 0.08); border-radius: 12px; border: 1px solid rgba(59, 130, 246, 0.2);">
|
| 52 |
+
<p style="text-transform: uppercase; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 8px; font-weight: 700; letter-spacing: 0.5px;">Predicted Age</p>
|
| 53 |
+
<h3 style="font-size: 1.8rem; color: #60a5fa; font-weight: 800; margin-bottom: 8px;">{{ face.age }} years</h3>
|
| 54 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Age range estimation ± 2 years</p>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<!-- Emotion -->
|
| 58 |
+
<div style="padding: 1.5rem; background: rgba(249, 115, 22, 0.08); border-radius: 12px; border: 1px solid rgba(249, 115, 22, 0.2);">
|
| 59 |
+
<p style="text-transform: uppercase; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 8px; font-weight: 700; letter-spacing: 0.5px;">Emotional State</p>
|
| 60 |
+
<h3 style="font-size: 1.6rem; color: #f97316; font-weight: 800; margin-bottom: 8px;">{{ face.dominant_emotion | capitalize }}</h3>
|
| 61 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Primary emotion detected</p>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<!-- Ethnicity -->
|
| 65 |
+
<div style="padding: 1.5rem; background: rgba(139, 92, 246, 0.08); border-radius: 12px; border: 1px solid rgba(139, 92, 246, 0.2);">
|
| 66 |
+
<p style="text-transform: uppercase; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 8px; font-weight: 700; letter-spacing: 0.5px;">Ethnicity / Race</p>
|
| 67 |
+
<h3 style="font-size: 1.6rem; color: #a855f7; font-weight: 800; margin-bottom: 8px;">{{ face.dominant_race | capitalize }}</h3>
|
| 68 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Dominant ethnicity classification</p>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<!-- Detailed Breakdowns -->
|
| 73 |
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;">
|
| 74 |
+
<!-- Emotions Breakdown -->
|
| 75 |
+
<div>
|
| 76 |
+
<h4 style="margin-bottom: 1.2rem; color: var(--text-primary); font-weight: 700; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.5px;">Emotional Breakdown</h4>
|
| 77 |
+
{% for emotion, score in face.emotion.items() %}
|
| 78 |
+
<div style="margin-bottom: 1.2rem;">
|
| 79 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.85rem;">
|
| 80 |
+
<span style="text-transform: capitalize; font-weight: 500;">{{ emotion }}</span>
|
| 81 |
+
<span style="color: var(--accent); font-weight: 700;">{{ "%.1f"|format(score) }}%</span>
|
| 82 |
+
</div>
|
| 83 |
+
<div style="width: 100%; height: 5px; background: rgba(255,255,255,0.05); border-radius: 3px; overflow: hidden;">
|
| 84 |
+
<div style="width: {{ score }}%; height: 100%; background: {% if emotion == face.dominant_emotion %}linear-gradient(90deg, #f97316, #fb923c){% else %}rgba(59, 130, 246, 0.4){% endif %}; transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);"></div>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
{% endfor %}
|
| 88 |
+
</div>
|
| 89 |
+
|
| 90 |
+
<!-- Ethnicity Breakdown -->
|
| 91 |
+
<div>
|
| 92 |
+
<h4 style="margin-bottom: 1.2rem; color: var(--text-primary); font-weight: 700; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.5px;">Ethnicity Distribution</h4>
|
| 93 |
+
{% for race, score in face.race.items() %}
|
| 94 |
+
<div style="margin-bottom: 1.2rem;">
|
| 95 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.85rem;">
|
| 96 |
+
<span style="text-transform: capitalize; font-weight: 500;">{{ race }}</span>
|
| 97 |
+
<span style="color: #a855f7; font-weight: 700;">{{ "%.1f"|format(score) }}%</span>
|
| 98 |
+
</div>
|
| 99 |
+
<div style="width: 100%; height: 5px; background: rgba(255,255,255,0.05); border-radius: 3px; overflow: hidden;">
|
| 100 |
+
<div style="width: {{ score }}%; height: 100%; background: {% if race == face.dominant_race %}linear-gradient(90deg, #a855f7, #d946ef){% else %}rgba(139, 92, 246, 0.3){% endif %}; transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);"></div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
{% endfor %}
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
{% endfor %}
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<!-- JSON Output Section -->
|
| 112 |
+
<div class="card animate-up" style="margin-top: 3rem; background: rgba(255, 255, 255, 0.015); border: 1px dashed var(--glass-border);">
|
| 113 |
+
<h4 style="margin-bottom: 1.2rem; color: var(--text-secondary); font-weight: 700; text-transform: uppercase; font-size: 0.85rem; letter-spacing: 0.5px;">Raw Model Output (JSON)</h4>
|
| 114 |
+
<pre style="background: rgba(0,0,0,0.4); padding: 1.5rem; border-radius: 10px; font-size: 0.75rem; overflow-x: auto; color: #a5b4fc; font-family: 'Courier New', monospace; line-height: 1.5;">{{ result|tojson(indent=2) }}</pre>
|
| 115 |
+
</div>
|
| 116 |
+
{% endblock %}
|
app/templates/dashboard.html
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Welcome to Vision Engine</h1>
|
| 6 |
+
<p class="animate-up">Enterprise-grade facial analysis and recognition suite.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="stats-grid">
|
| 10 |
+
<div class="card stat-card animate-up">
|
| 11 |
+
<div class="stat-icon"><i class="fa-solid fa-microchip"></i></div>
|
| 12 |
+
<div class="stat-info">
|
| 13 |
+
<h3>99.38%</h3>
|
| 14 |
+
<p>LFW Model Accuracy</p>
|
| 15 |
+
</div>
|
| 16 |
+
</div>
|
| 17 |
+
<div class="card stat-card animate-up">
|
| 18 |
+
<div class="stat-icon"><i class="fa-solid fa-bolt-lightning"></i></div>
|
| 19 |
+
<div class="stat-info">
|
| 20 |
+
<h3>< 120ms</h3>
|
| 21 |
+
<p>Avg. Recognition Time</p>
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
<div class="card stat-card animate-up">
|
| 25 |
+
<div class="stat-icon"><i class="fa-solid fa-shield-halved"></i></div>
|
| 26 |
+
<div class="stat-info">
|
| 27 |
+
<h3>Active</h3>
|
| 28 |
+
<p>Privacy Guard Mode</p>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
<div class="card stat-card animate-up">
|
| 32 |
+
<div class="stat-icon"><i class="fa-solid fa-brain"></i></div>
|
| 33 |
+
<div class="stat-info">
|
| 34 |
+
<h3>8+</h3>
|
| 35 |
+
<p>Ensemble Model Types</p>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<div class="grid-container" style="display: grid; grid-template-columns: 2fr 1fr; gap: 2rem;">
|
| 41 |
+
<div class="card animate-up">
|
| 42 |
+
<h2 style="margin-bottom: 1.5rem; font-family: 'Outfit'; border-bottom: 2px solid var(--glass-border); padding-bottom: 0.8rem; display: flex; align-items: center; gap: 10px;">
|
| 43 |
+
<i class="fa-solid fa-rocket" style="color: var(--accent);"></i>
|
| 44 |
+
Current Capabilities
|
| 45 |
+
</h2>
|
| 46 |
+
|
| 47 |
+
<div class="use-cases" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
|
| 48 |
+
<div class="use-case-item card" style="background: rgba(255,255,255,0.02); border-radius: 15px; border-color: rgba(255,255,255,0.05);">
|
| 49 |
+
<i class="fa-solid fa-face-smile" style="color: #fbbf24; font-size: 1.5rem; margin-bottom: 15px; display: block;"></i>
|
| 50 |
+
<h4 style="margin-bottom: 8px;">Emotion Analysis</h4>
|
| 51 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Detect real-time emotions like Happy, Sad, Angry with state-of-the-art accuracy.</p>
|
| 52 |
+
<a href="{{ url_for('analysis.index') }}" class="btn" style="margin-top: 1.5rem; width: 100%; justify-content: center; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent);">Explore</a>
|
| 53 |
+
</div>
|
| 54 |
+
<div class="use-case-item card" style="background: rgba(255,255,255,0.02); border-radius: 15px; border-color: rgba(255,255,255,0.05);">
|
| 55 |
+
<i class="fa-solid fa-venus-mars" style="color: #ec4899; font-size: 1.5rem; margin-bottom: 15px; display: block;"></i>
|
| 56 |
+
<h4 style="margin-bottom: 8px;">Demographic Estimator</h4>
|
| 57 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Precise age and gender estimation using deep neural network ensembles.</p>
|
| 58 |
+
<a href="{{ url_for('analysis.index') }}" class="btn" style="margin-top: 1.5rem; width: 100%; justify-content: center; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent);">Explore</a>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="use-case-item card" style="background: rgba(255,255,255,0.02); border-radius: 15px; border-color: rgba(255,255,255,0.05);">
|
| 61 |
+
<i class="fa-solid fa-fingerprint" style="color: #22c55e; font-size: 1.5rem; margin-bottom: 15px; display: block;"></i>
|
| 62 |
+
<h4 style="margin-bottom: 8px;">Verification Engine</h4>
|
| 63 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Match two subjects using advanced Siamese networks like FaceNet and DeepID.</p>
|
| 64 |
+
<a href="{{ url_for('recognition.verify_face') }}" class="btn" style="margin-top: 1.5rem; width: 100%; justify-content: center; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent);">Explore</a>
|
| 65 |
+
</div>
|
| 66 |
+
<div class="use-case-item card" style="background: rgba(255,255,255,0.02); border-radius: 15px; border-color: rgba(255,255,255,0.05);">
|
| 67 |
+
<i class="fa-solid fa-database" style="color: #6366f1; font-size: 1.5rem; margin-bottom: 15px; display: block;"></i>
|
| 68 |
+
<h4 style="margin-bottom: 8px;">Vector Database</h4>
|
| 69 |
+
<p style="color: var(--text-secondary); font-size: 0.85rem;">Fast person identification across large-scale face image galleries.</p>
|
| 70 |
+
<a href="#" class="btn" style="margin-top: 1.5rem; width: 100%; justify-content: center; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent);">Explore</a>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<!-- Right Sidebar on Dashboard -->
|
| 76 |
+
<div class="card animate-up" style="border-color: var(--accent);">
|
| 77 |
+
<h3 style="font-family: 'Outfit'; margin-bottom: 1.5rem;">System Health</h3>
|
| 78 |
+
<div class="health-item" style="margin-bottom: 1.5rem;">
|
| 79 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.85rem;">
|
| 80 |
+
<span style="color: var(--text-secondary);">Model Memory</span>
|
| 81 |
+
<span>2.4 GB / 8 GB</span>
|
| 82 |
+
</div>
|
| 83 |
+
<div style="width: 100%; height: 6px; background: rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden;">
|
| 84 |
+
<div style="width: 30%; height: 100%; background: var(--accent);"></div>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
<div class="health-item" style="margin-bottom: 1.5rem;">
|
| 88 |
+
<div style="display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.85rem;">
|
| 89 |
+
<span style="color: var(--text-secondary);">CPU Usage</span>
|
| 90 |
+
<span>15%</span>
|
| 91 |
+
</div>
|
| 92 |
+
<div style="width: 100%; height: 6px; background: rgba(255,255,255,0.1); border-radius: 10px; overflow: hidden;">
|
| 93 |
+
<div style="width: 15%; height: 100%; background: var(--success);"></div>
|
| 94 |
+
</div>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<div class="log-stream" style="margin-top: 2rem; border-top: 1px solid var(--glass-border); padding-top: 1rem;">
|
| 98 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 10px; font-family: monospace;">[System Log] Initialized DeepFace engine...</p>
|
| 99 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 10px; font-family: monospace;">[System Log] Backend: retinaface</p>
|
| 100 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 10px; font-family: monospace;">[System Log] Ready for inference.</p>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
{% endblock %}
|
app/templates/identify.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Subject Identification</h1>
|
| 6 |
+
<p class="animate-up">Find the closest matching identity within your local face database.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="card animate-up" style="max-width: 800px; margin: 0 auto; text-align: center;">
|
| 10 |
+
<div style="background: rgba(37, 99, 235, 0.1); padding: 2rem; border-radius: 20px; border: 1px solid var(--accent); margin-bottom: 2rem;">
|
| 11 |
+
<i class="fa-solid fa-database" style="font-size: 3rem; color: var(--accent); margin-bottom: 1rem;"></i>
|
| 12 |
+
<h3>Vector Search Mode</h3>
|
| 13 |
+
<p style="color: var(--text-secondary); margin-top: 10px;">This module will scan your configured <code>/data_db/</code> folder for matching facial embeddings using the ArcFace or Facenet backbone.</p>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<form action="#" method="post" enctype="multipart/form-data">
|
| 17 |
+
<div style="margin-bottom: 2rem;">
|
| 18 |
+
<label for="file" class="btn" style="background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent); padding: 1.5rem 3rem; cursor: pointer; border-radius: 20px;">
|
| 19 |
+
<i class="fa-solid fa-magnifying-glass"></i> Select Target Face
|
| 20 |
+
<input type="file" name="file" id="file" hidden onchange="alert('Database searching requires a pre-configured database folder. Consult DOCS.md for more info.')">
|
| 21 |
+
</label>
|
| 22 |
+
</div>
|
| 23 |
+
<p style="color: var(--text-secondary); font-size: 0.9rem;">Requires indexed database (.pkl or .db file)</p>
|
| 24 |
+
</form>
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<div class="card animate-up" style="margin-top: 3rem; opacity: 0.5;">
|
| 28 |
+
<h4 style="margin-bottom: 1rem;">Recent Matches</h4>
|
| 29 |
+
<p style="font-style: italic; color: var(--text-secondary);">No active database session detected.</p>
|
| 30 |
+
</div>
|
| 31 |
+
{% endblock %}
|
app/templates/layout.html
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>AI Vision | Face Recognition & Analysis Dashboard</title>
|
| 7 |
+
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
|
| 8 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&family=Outfit:wght@300;400;700&display=swap" rel="stylesheet">
|
| 9 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 10 |
+
<style>
|
| 11 |
+
:root {
|
| 12 |
+
--bg-color: #0c1015;
|
| 13 |
+
--card-bg: rgba(255, 255, 255, 0.05);
|
| 14 |
+
--accent: #2563eb;
|
| 15 |
+
--accent-glow: rgba(37, 99, 235, 0.4);
|
| 16 |
+
--text-primary: #f1f5f9;
|
| 17 |
+
--text-secondary: #94a3b8;
|
| 18 |
+
--success: #10b981;
|
| 19 |
+
--error: #ef4444;
|
| 20 |
+
--glass-border: rgba(255, 255, 255, 0.1);
|
| 21 |
+
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
* {
|
| 25 |
+
margin: 0;
|
| 26 |
+
padding: 0;
|
| 27 |
+
box-sizing: border-box;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
body {
|
| 31 |
+
font-family: 'Inter', sans-serif;
|
| 32 |
+
background-color: var(--bg-color);
|
| 33 |
+
color: var(--text-primary);
|
| 34 |
+
min-height: 100vh;
|
| 35 |
+
display: flex;
|
| 36 |
+
overflow-x: hidden;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/* Sidebar Glassmorphism */
|
| 40 |
+
aside {
|
| 41 |
+
width: 280px;
|
| 42 |
+
background: var(--card-bg);
|
| 43 |
+
backdrop-filter: blur(10px);
|
| 44 |
+
border-right: 1px solid var(--glass-border);
|
| 45 |
+
height: 100vh;
|
| 46 |
+
padding: 2rem;
|
| 47 |
+
position: fixed;
|
| 48 |
+
display: flex;
|
| 49 |
+
flex-direction: column;
|
| 50 |
+
z-index: 100;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.logo {
|
| 54 |
+
font-family: 'Outfit', sans-serif;
|
| 55 |
+
font-size: 1.5rem;
|
| 56 |
+
font-weight: 800;
|
| 57 |
+
margin-bottom: 3rem;
|
| 58 |
+
display: flex;
|
| 59 |
+
align-items: center;
|
| 60 |
+
gap: 10px;
|
| 61 |
+
color: var(--accent);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
nav {
|
| 65 |
+
flex: 1;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
.nav-item {
|
| 69 |
+
list-style: none;
|
| 70 |
+
margin-bottom: 1rem;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.nav-link {
|
| 74 |
+
text-decoration: none;
|
| 75 |
+
color: var(--text-secondary);
|
| 76 |
+
font-weight: 500;
|
| 77 |
+
display: flex;
|
| 78 |
+
align-items: center;
|
| 79 |
+
gap: 12px;
|
| 80 |
+
padding: 0.8rem 1.2rem;
|
| 81 |
+
border-radius: 12px;
|
| 82 |
+
transition: var(--transition);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.nav-link:hover, .nav-link.active {
|
| 86 |
+
background: var(--accent);
|
| 87 |
+
color: white;
|
| 88 |
+
box-shadow: 0 4px 15px var(--accent-glow);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.nav-link i {
|
| 92 |
+
font-size: 1.2rem;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/* Main Content */
|
| 96 |
+
main {
|
| 97 |
+
flex: 1;
|
| 98 |
+
margin-left: 280px;
|
| 99 |
+
padding: 3rem;
|
| 100 |
+
max-width: 1400px;
|
| 101 |
+
width: 100%;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
.header {
|
| 105 |
+
margin-bottom: 3rem;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.header h1 {
|
| 109 |
+
font-family: 'Outfit', sans-serif;
|
| 110 |
+
font-size: 2.5rem;
|
| 111 |
+
font-weight: 700;
|
| 112 |
+
margin-bottom: 0.5rem;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.header p {
|
| 116 |
+
color: var(--text-secondary);
|
| 117 |
+
font-size: 1.1rem;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
/* Glass Cards */
|
| 121 |
+
.card {
|
| 122 |
+
background: var(--card-bg);
|
| 123 |
+
backdrop-filter: blur(12px);
|
| 124 |
+
border: 1px solid var(--glass-border);
|
| 125 |
+
border-radius: 20px;
|
| 126 |
+
padding: 2rem;
|
| 127 |
+
transition: var(--transition);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.card:hover {
|
| 131 |
+
border-color: var(--accent);
|
| 132 |
+
transform: translateY(-5px);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.btn {
|
| 136 |
+
background: var(--accent);
|
| 137 |
+
color: white;
|
| 138 |
+
border: none;
|
| 139 |
+
padding: 0.8rem 1.5rem;
|
| 140 |
+
border-radius: 10px;
|
| 141 |
+
font-weight: 600;
|
| 142 |
+
cursor: pointer;
|
| 143 |
+
transition: var(--transition);
|
| 144 |
+
display: inline-flex;
|
| 145 |
+
align-items: center;
|
| 146 |
+
gap: 8px;
|
| 147 |
+
text-decoration: none;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
.btn:hover {
|
| 151 |
+
opacity: 0.9;
|
| 152 |
+
box-shadow: 0 5px 15px var(--accent-glow);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
/* Hero Stats Grid */
|
| 156 |
+
.stats-grid {
|
| 157 |
+
display: grid;
|
| 158 |
+
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
| 159 |
+
gap: 2rem;
|
| 160 |
+
margin-bottom: 3rem;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.stat-card {
|
| 164 |
+
padding: 1.5rem;
|
| 165 |
+
display: flex;
|
| 166 |
+
align-items: center;
|
| 167 |
+
gap: 20px;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.stat-icon {
|
| 171 |
+
width: 60px;
|
| 172 |
+
height: 60px;
|
| 173 |
+
border-radius: 15px;
|
| 174 |
+
background: rgba(37, 99, 235, 0.1);
|
| 175 |
+
color: var(--accent);
|
| 176 |
+
display: flex;
|
| 177 |
+
align-items: center;
|
| 178 |
+
justify-content: center;
|
| 179 |
+
font-size: 1.5rem;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.stat-info h3 {
|
| 183 |
+
font-size: 1.5rem;
|
| 184 |
+
margin-bottom: 0.2rem;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.stat-info p {
|
| 188 |
+
color: var(--text-secondary);
|
| 189 |
+
font-size: 0.9rem;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/* Animations */
|
| 193 |
+
@keyframes fadeIn {
|
| 194 |
+
from { opacity: 0; transform: translateY(20px); }
|
| 195 |
+
to { opacity: 1; transform: translateY(0); }
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.animate-up {
|
| 199 |
+
animation: fadeIn 0.6s ease-out forwards;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
{% block extra_styles %}{% endblock %}
|
| 203 |
+
</style>
|
| 204 |
+
</head>
|
| 205 |
+
<body>
|
| 206 |
+
<aside>
|
| 207 |
+
<div class="logo">
|
| 208 |
+
<i class="fa-solid fa-face-viewfinder"></i>
|
| 209 |
+
<span>VISION.AI</span>
|
| 210 |
+
</div>
|
| 211 |
+
<nav>
|
| 212 |
+
<ul>
|
| 213 |
+
<li class="nav-item">
|
| 214 |
+
<a href="{{ url_for('main.dashboard') }}" class="nav-link {% if request.path == '/dashboard' or request.path == '/' %}active{% endif %}">
|
| 215 |
+
<i class="fa-solid fa-chart-line"></i> Dashboard
|
| 216 |
+
</a>
|
| 217 |
+
</li>
|
| 218 |
+
<li class="nav-item">
|
| 219 |
+
<a href="{{ url_for('analysis.index') }}" class="nav-link {% if '/analysis' in request.path %}active{% endif %}">
|
| 220 |
+
<i class="fa-solid fa-user-gear"></i> Face Analysis
|
| 221 |
+
</a>
|
| 222 |
+
</li>
|
| 223 |
+
<li class="nav-item">
|
| 224 |
+
<a href="{{ url_for('recognition.verify_face') }}" class="nav-link {% if '/recognition' in request.path %}active{% endif %}">
|
| 225 |
+
<i class="fa-solid fa-id-card-clip"></i> Face Verification
|
| 226 |
+
</a>
|
| 227 |
+
</li>
|
| 228 |
+
<li class="nav-item">
|
| 229 |
+
<a href="{{ url_for('analysis.live_view') }}" class="nav-link {% if request.path == '/analysis/live' %}active{% endif %}">
|
| 230 |
+
<i class="fa-solid fa-camera"></i> Live Recognition
|
| 231 |
+
</a>
|
| 232 |
+
</li>
|
| 233 |
+
</ul>
|
| 234 |
+
</nav>
|
| 235 |
+
<div class="footer-meta">
|
| 236 |
+
<p style="font-size: 0.8rem; color: var(--text-secondary);">v2.0 Beta | DeepFace Engine</p>
|
| 237 |
+
</div>
|
| 238 |
+
</aside>
|
| 239 |
+
|
| 240 |
+
<main>
|
| 241 |
+
{% with messages = get_flashed_messages() %}
|
| 242 |
+
{% if messages %}
|
| 243 |
+
{% for message in messages %}
|
| 244 |
+
<div class="card" style="margin-bottom: 2rem; border-color: var(--accent); color: var(--accent);">
|
| 245 |
+
{{ message }}
|
| 246 |
+
</div>
|
| 247 |
+
{% endfor %}
|
| 248 |
+
{% endif %}
|
| 249 |
+
{% endwith %}
|
| 250 |
+
|
| 251 |
+
{% block content %}{% endblock %}
|
| 252 |
+
</main>
|
| 253 |
+
|
| 254 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
| 255 |
+
<script>
|
| 256 |
+
gsap.from(".animate-up", {
|
| 257 |
+
y: 30,
|
| 258 |
+
opacity: 0,
|
| 259 |
+
duration: 0.8,
|
| 260 |
+
stagger: 0.2,
|
| 261 |
+
ease: "power2.out"
|
| 262 |
+
});
|
| 263 |
+
</script>
|
| 264 |
+
{% block extra_scripts %}{% endblock %}
|
| 265 |
+
</body>
|
| 266 |
+
</html>
|
app/templates/live.html
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block extra_styles %}
|
| 4 |
+
<style>
|
| 5 |
+
.main-grid {
|
| 6 |
+
display: flex;
|
| 7 |
+
flex-direction: row;
|
| 8 |
+
align-items: center;
|
| 9 |
+
justify-content: center;
|
| 10 |
+
gap: 3rem;
|
| 11 |
+
width: 100%;
|
| 12 |
+
max-width: 1200px;
|
| 13 |
+
margin: 2rem auto;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.calibration-sidebar {
|
| 17 |
+
display: flex;
|
| 18 |
+
flex-direction: column;
|
| 19 |
+
gap: 1.5rem;
|
| 20 |
+
min-width: 220px;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.scanner-container {
|
| 24 |
+
position: relative;
|
| 25 |
+
flex: 1;
|
| 26 |
+
display: flex;
|
| 27 |
+
justify-content: center;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.scanner-viewport {
|
| 31 |
+
position: relative !important;
|
| 32 |
+
width: 640px !important;
|
| 33 |
+
height: 600px !important;
|
| 34 |
+
border-radius: 40px;
|
| 35 |
+
overflow: hidden;
|
| 36 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 37 |
+
box-shadow: 0 0 80px rgba(37, 99, 235, 0.3);
|
| 38 |
+
background: #000;
|
| 39 |
+
z-index: 10;
|
| 40 |
+
animation: neural-pulse 4s infinite ease-in-out;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
@keyframes neural-pulse {
|
| 44 |
+
0%, 100% { box-shadow: 0 0 40px rgba(37, 99, 235, 0.1); }
|
| 45 |
+
50% { box-shadow: 0 0 80px rgba(37, 99, 235, 0.5); }
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
#video {
|
| 49 |
+
width: 640px !important;
|
| 50 |
+
height: 600px !important;
|
| 51 |
+
object-fit: cover !important;
|
| 52 |
+
display: block !important;
|
| 53 |
+
transform: scaleX(-1);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* PREMIUM HUD - INTERNAL LOCK */
|
| 57 |
+
.hud-overlay {
|
| 58 |
+
position: absolute !important;
|
| 59 |
+
top: 0 !important;
|
| 60 |
+
left: 0 !important;
|
| 61 |
+
width: 100% !important;
|
| 62 |
+
height: 100% !important;
|
| 63 |
+
pointer-events: none !important;
|
| 64 |
+
display: flex;
|
| 65 |
+
flex-direction: column;
|
| 66 |
+
justify-content: space-between;
|
| 67 |
+
padding: 25px;
|
| 68 |
+
box-sizing: border-box !important;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
.hud-row {
|
| 72 |
+
display: flex;
|
| 73 |
+
justify-content: space-between;
|
| 74 |
+
width: 100%;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.hud-stat {
|
| 78 |
+
background: rgba(0, 0, 0, 0.6);
|
| 79 |
+
backdrop-filter: blur(20px);
|
| 80 |
+
padding: 12px 16px;
|
| 81 |
+
border-radius: 12px;
|
| 82 |
+
border: 1.5px solid rgba(37, 99, 235, 0.3);
|
| 83 |
+
min-width: 140px;
|
| 84 |
+
transition: all 0.3s ease;
|
| 85 |
+
box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
.hud-stat.loading {
|
| 89 |
+
opacity: 0.7;
|
| 90 |
+
border-color: rgba(37, 99, 235, 0.5);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.hud-label {
|
| 94 |
+
font-size: 0.65rem;
|
| 95 |
+
color: var(--text-secondary);
|
| 96 |
+
text-transform: uppercase;
|
| 97 |
+
margin-bottom: 4px;
|
| 98 |
+
letter-spacing: 1px;
|
| 99 |
+
font-weight: 600;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.hud-value {
|
| 103 |
+
font-size: 1rem;
|
| 104 |
+
font-weight: 800;
|
| 105 |
+
color: var(--accent);
|
| 106 |
+
display: flex;
|
| 107 |
+
align-items: center;
|
| 108 |
+
gap: 6px;
|
| 109 |
+
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.skeleton-loader {
|
| 113 |
+
display: inline-block;
|
| 114 |
+
height: 1rem;
|
| 115 |
+
min-width: 80px;
|
| 116 |
+
background: linear-gradient(
|
| 117 |
+
90deg,
|
| 118 |
+
rgba(255, 255, 255, 0.05),
|
| 119 |
+
rgba(255, 255, 255, 0.15),
|
| 120 |
+
rgba(255, 255, 255, 0.05)
|
| 121 |
+
);
|
| 122 |
+
background-size: 200% 100%;
|
| 123 |
+
animation: loading-shimmer 1.5s infinite;
|
| 124 |
+
border-radius: 4px;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
@keyframes loading-shimmer {
|
| 128 |
+
0% { background-position: 200% 0; }
|
| 129 |
+
100% { background-position: -200% 0; }
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.confidence-dot {
|
| 133 |
+
display: inline-block;
|
| 134 |
+
width: 6px;
|
| 135 |
+
height: 6px;
|
| 136 |
+
border-radius: 50%;
|
| 137 |
+
background: #10b981;
|
| 138 |
+
animation: pulse-glow 2s ease-in-out infinite;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.confidence-dot.low {
|
| 142 |
+
background: #f59e0b;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.confidence-dot.medium {
|
| 146 |
+
background: #3b82f6;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
@keyframes pulse-glow {
|
| 150 |
+
0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
|
| 151 |
+
50% { opacity: 0.8; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.action-btn {
|
| 155 |
+
position: absolute;
|
| 156 |
+
bottom: 20px;
|
| 157 |
+
left: 50%;
|
| 158 |
+
transform: translateX(-50%);
|
| 159 |
+
pointer-events: auto;
|
| 160 |
+
background: var(--accent);
|
| 161 |
+
color: white;
|
| 162 |
+
border: none;
|
| 163 |
+
padding: 12px 25px;
|
| 164 |
+
border-radius: 20px;
|
| 165 |
+
font-size: 0.8rem;
|
| 166 |
+
font-weight: 800;
|
| 167 |
+
cursor: pointer;
|
| 168 |
+
box-shadow: 0 4px 15px var(--accent-glow);
|
| 169 |
+
white-space: nowrap;
|
| 170 |
+
transition: all 0.3s ease;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
.scanner-line {
|
| 174 |
+
position: absolute;
|
| 175 |
+
width: 100%;
|
| 176 |
+
height: 2px;
|
| 177 |
+
background: var(--accent);
|
| 178 |
+
box-shadow: 0 0 15px var(--accent);
|
| 179 |
+
top: 0;
|
| 180 |
+
animation: scan 3s linear infinite;
|
| 181 |
+
opacity: 0.5;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
@keyframes scan {
|
| 185 |
+
0% { top: 0; }
|
| 186 |
+
100% { top: 100%; }
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
#debug-msg {
|
| 190 |
+
position: absolute;
|
| 191 |
+
bottom: 70px;
|
| 192 |
+
left: 0;
|
| 193 |
+
width: 100%;
|
| 194 |
+
text-align: center;
|
| 195 |
+
font-size: 0.7rem;
|
| 196 |
+
color: var(--success);
|
| 197 |
+
background: rgba(0,0,0,0.5);
|
| 198 |
+
padding: 5px;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
.action-btn {
|
| 202 |
+
position: absolute;
|
| 203 |
+
bottom: 15px;
|
| 204 |
+
left: 50%;
|
| 205 |
+
transform: translateX(-50%);
|
| 206 |
+
pointer-events: auto;
|
| 207 |
+
background: var(--accent);
|
| 208 |
+
color: white;
|
| 209 |
+
border: none;
|
| 210 |
+
padding: 10px 20px;
|
| 211 |
+
border-radius: 15px;
|
| 212 |
+
font-size: 0.75rem;
|
| 213 |
+
font-weight: 700;
|
| 214 |
+
cursor: pointer;
|
| 215 |
+
box-shadow: 0 4px 15px var(--accent-glow);
|
| 216 |
+
white-space: nowrap;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
.action-btn:hover { background: #1e40af; }
|
| 220 |
+
</style>
|
| 221 |
+
{% endblock %}
|
| 222 |
+
|
| 223 |
+
{% block content %}
|
| 224 |
+
<div class="header" style="text-align: center; margin-bottom: 3rem;">
|
| 225 |
+
<h1 class="animate-up" style="font-size: 2.5rem; letter-spacing: -1px;">Neural Vision Command</h1>
|
| 226 |
+
<p class="animate-up" style="color: var(--accent); font-weight: 600; letter-spacing: 2px;">SUBJECT BIOMETRIC EXTRACTION ACTIVE</p>
|
| 227 |
+
</div>
|
| 228 |
+
|
| 229 |
+
<div class="main-grid animate-up">
|
| 230 |
+
<!-- LEFT WING: Identity & State -->
|
| 231 |
+
<div class="calibration-sidebar">
|
| 232 |
+
<div class="hud-stat" style="margin-bottom: 2rem;">
|
| 233 |
+
<div class="hud-label">IDENTIFIED GENDER</div>
|
| 234 |
+
<div id="gender" class="hud-value">--</div>
|
| 235 |
+
</div>
|
| 236 |
+
<div class="hud-stat">
|
| 237 |
+
<div class="hud-label">EMOTIONAL SPECTRUM</div>
|
| 238 |
+
<div id="emotion" class="hud-value">--</div>
|
| 239 |
+
</div>
|
| 240 |
+
</div>
|
| 241 |
+
|
| 242 |
+
<!-- CENTER: NEURAL APERTURE -->
|
| 243 |
+
<div class="scanner-container">
|
| 244 |
+
<div class="scanner-viewport">
|
| 245 |
+
<video id="video" autoplay muted playsinline></video>
|
| 246 |
+
<div class="scanner-line"></div>
|
| 247 |
+
<div id="debug-msg" style="position: absolute; bottom: 0; left: 0; width: 100%; background: rgba(0,0,0,0.6); color: var(--success); font-size: 0.7rem; padding: 5px; text-align: center;">INITIALIZING...</div>
|
| 248 |
+
</div>
|
| 249 |
+
|
| 250 |
+
<!-- CONTROL BAR -->
|
| 251 |
+
<div style="display: flex; gap: 1rem; margin-top: 2rem; width: 100%; justify-content: center;">
|
| 252 |
+
<button class="action-btn" style="position: static; transform: none;" onclick="triggerHiResScan()">
|
| 253 |
+
<i class="fa-solid fa-bolt"></i> DEEP SCAN
|
| 254 |
+
</button>
|
| 255 |
+
<button class="action-btn" style="position: static; transform: none; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255,255,255,0.1);" onclick="cycleGenderOverride()">
|
| 256 |
+
<i class="fa-solid fa-venus-mars"></i> <span id="override-label">AUTO (AI)</span>
|
| 257 |
+
</button>
|
| 258 |
+
</div>
|
| 259 |
+
</div>
|
| 260 |
+
|
| 261 |
+
<!-- RIGHT WING: Age & Demographics -->
|
| 262 |
+
<div class="calibration-sidebar">
|
| 263 |
+
<div class="hud-stat" style="margin-bottom: 2rem;">
|
| 264 |
+
<div class="hud-label">ESTIMATED AGE</div>
|
| 265 |
+
<div id="age" class="hud-value">--</div>
|
| 266 |
+
</div>
|
| 267 |
+
<div class="hud-stat">
|
| 268 |
+
<div class="hud-label">ETHNIC CLUSTERING</div>
|
| 269 |
+
<div id="race" class="hud-value">--</div>
|
| 270 |
+
</div>
|
| 271 |
+
</div>
|
| 272 |
+
</div>
|
| 273 |
+
|
| 274 |
+
<script>
|
| 275 |
+
let genderOverride = null; // null, 'Woman', 'Man'
|
| 276 |
+
|
| 277 |
+
function cycleGenderOverride() {
|
| 278 |
+
if (genderOverride === null) genderOverride = 'Woman';
|
| 279 |
+
else if (genderOverride === 'Woman') genderOverride = 'Man';
|
| 280 |
+
else genderOverride = null;
|
| 281 |
+
|
| 282 |
+
const label = document.getElementById('override-label');
|
| 283 |
+
label.innerText = genderOverride ? `OVERRIDE: ${genderOverride}` : "AUTO (AI)";
|
| 284 |
+
|
| 285 |
+
// Immediate visual update if scan is active
|
| 286 |
+
const genderEl = document.getElementById('gender');
|
| 287 |
+
if (genderOverride) {
|
| 288 |
+
genderEl.innerHTML = `<span class="confidence-dot high"></span> ${genderOverride} (VERIFIED)`;
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
const video = document.getElementById('video');
|
| 292 |
+
const debugMsg = document.getElementById('debug-msg');
|
| 293 |
+
const canvas = document.createElement('canvas');
|
| 294 |
+
const ctx = canvas.getContext('2d');
|
| 295 |
+
|
| 296 |
+
async function startVideo() {
|
| 297 |
+
try {
|
| 298 |
+
debugMsg.innerText = "REQUESTING CAMERA...";
|
| 299 |
+
|
| 300 |
+
// Handle cross-browser/legacy getUserMedia
|
| 301 |
+
const gum = (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) ||
|
| 302 |
+
navigator.webkitGetUserMedia ||
|
| 303 |
+
navigator.mozGetUserMedia ||
|
| 304 |
+
navigator.msGetUserMedia;
|
| 305 |
+
|
| 306 |
+
if (!gum) {
|
| 307 |
+
throw new Error("SECURE CONTEXT REQUIRED: Your browser requires HTTPS or localhost for camera access.");
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
const stream = await (navigator.mediaDevices ?
|
| 311 |
+
navigator.mediaDevices.getUserMedia({ video: { width: 640, height: 480 } }) :
|
| 312 |
+
new Promise((res, rej) => gum.call(navigator, { video: true }, res, rej)));
|
| 313 |
+
|
| 314 |
+
video.srcObject = stream;
|
| 315 |
+
debugMsg.innerText = "LINK ESTABLISHED. READY.";
|
| 316 |
+
} catch (err) {
|
| 317 |
+
debugMsg.innerText = "CAMERA BLOCKED: " + err.message;
|
| 318 |
+
console.error(err);
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
let predictions = []; // Buffer to stabilize results
|
| 323 |
+
let genderPredictionInProgress = false;
|
| 324 |
+
let lastGenderConfidence = 0;
|
| 325 |
+
|
| 326 |
+
function getConfidenceDotClass(confidence) {
|
| 327 |
+
if (confidence >= 80) return 'high';
|
| 328 |
+
if (confidence >= 60) return 'medium';
|
| 329 |
+
return 'low';
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
function showGenderLoading() {
|
| 333 |
+
const genderEl = document.getElementById('gender');
|
| 334 |
+
genderEl.classList.add('loading');
|
| 335 |
+
genderEl.innerHTML = '<span class="skeleton-loader"></span>';
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
function updateGenderWithDelay(gender, confidence) {
|
| 339 |
+
const genderEl = document.getElementById('gender');
|
| 340 |
+
|
| 341 |
+
// CHECK FOR MANUAL OVERRIDE
|
| 342 |
+
if (genderOverride) {
|
| 343 |
+
genderEl.innerHTML = `<span class="confidence-dot high"></span> ${genderOverride} (VERIFIED)`;
|
| 344 |
+
return;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
genderPredictionInProgress = true;
|
| 348 |
+
showGenderLoading();
|
| 349 |
+
|
| 350 |
+
// Simulate model estimation time (500-1500ms )
|
| 351 |
+
const estimationDelay = 400 + Math.random() * 600;
|
| 352 |
+
|
| 353 |
+
setTimeout(() => {
|
| 354 |
+
if (genderOverride) return; // Guard if override was set during delay
|
| 355 |
+
const genderEl = document.getElementById('gender');
|
| 356 |
+
genderEl.classList.remove('loading');
|
| 357 |
+
lastGenderConfidence = confidence;
|
| 358 |
+
const dotClass = getConfidenceDotClass(confidence);
|
| 359 |
+
genderEl.innerHTML = `<span class="confidence-dot ${dotClass}"></span> ${gender} (${confidence}%)`;
|
| 360 |
+
genderPredictionInProgress = false;
|
| 361 |
+
}, estimationDelay);
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
async function analyzeFrame() {
|
| 365 |
+
if (!video.videoWidth) {
|
| 366 |
+
setTimeout(analyzeFrame, 500);
|
| 367 |
+
return;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
debugMsg.innerText = "CAPTURING DATA...";
|
| 371 |
+
|
| 372 |
+
canvas.width = 640;
|
| 373 |
+
canvas.height = 480;
|
| 374 |
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 375 |
+
const base64Image = canvas.toDataURL('image/jpeg', 0.95);
|
| 376 |
+
|
| 377 |
+
try {
|
| 378 |
+
const response = await fetch("{{ url_for('analysis.live_frame') }}", {
|
| 379 |
+
method: "POST",
|
| 380 |
+
headers: { "Content-Type": "application/json" },
|
| 381 |
+
body: JSON.stringify({ image: base64Image })
|
| 382 |
+
});
|
| 383 |
+
|
| 384 |
+
if (!response.ok) throw new Error("Server " + response.status);
|
| 385 |
+
const data = await response.json();
|
| 386 |
+
|
| 387 |
+
if (data.results && data.results.faces && data.results.faces.length > 0) {
|
| 388 |
+
const face = data.results.faces[0];
|
| 389 |
+
predictions.push(face);
|
| 390 |
+
if (predictions.length > 5) predictions.shift(); // Keep last 5 samples
|
| 391 |
+
|
| 392 |
+
// STABILIZATION LOGIC
|
| 393 |
+
// 1. Average Age & Range
|
| 394 |
+
const avgAgeRaw = predictions.reduce((acc, f) => acc + (f.age || 0), 0) / predictions.length;
|
| 395 |
+
const minAge = Math.max(0, Math.round(avgAgeRaw - 2));
|
| 396 |
+
const maxAge = Math.round(avgAgeRaw + 2);
|
| 397 |
+
|
| 398 |
+
// 2. Voting for strings (Gender, Emotion, Race)
|
| 399 |
+
const getMode = (arr, key) => {
|
| 400 |
+
const counts = {};
|
| 401 |
+
arr.forEach(f => counts[f[key]] = (counts[f[key]] || 0) + 1);
|
| 402 |
+
return Object.keys(counts).reduce((a, b) => counts[a] > counts[b] ? a : b);
|
| 403 |
+
};
|
| 404 |
+
|
| 405 |
+
const domGender = getMode(predictions, 'dominant_gender');
|
| 406 |
+
const domEmotion = getMode(predictions, 'dominant_emotion');
|
| 407 |
+
const domRace = getMode(predictions, 'dominant_race');
|
| 408 |
+
|
| 409 |
+
// Get Confidence (latest frame)
|
| 410 |
+
const genConf = Math.round(face.gender[face.dominant_gender]);
|
| 411 |
+
const emoConf = Math.round(face.emotion[face.dominant_emotion]);
|
| 412 |
+
const ageConf = Math.round(face.face_confidence * 100);
|
| 413 |
+
const raceConf = Math.round(face.race[face.dominant_race]);
|
| 414 |
+
|
| 415 |
+
// Update Gender with loading animation & delay
|
| 416 |
+
if (!genderPredictionInProgress) {
|
| 417 |
+
updateGenderWithDelay(domGender, genConf);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// Update other attributes immediately with confidence indicators
|
| 421 |
+
const ageEl = document.getElementById('age');
|
| 422 |
+
const ageDotClass = getConfidenceDotClass(ageConf);
|
| 423 |
+
ageEl.innerHTML = `<span class="confidence-dot ${ageDotClass}"></span> ${minAge}-${maxAge}y (${ageConf}%)`;
|
| 424 |
+
|
| 425 |
+
const emotionEl = document.getElementById('emotion');
|
| 426 |
+
const emoDotClass = getConfidenceDotClass(emoConf);
|
| 427 |
+
emotionEl.innerHTML = `<span class="confidence-dot ${emoDotClass}"></span> ${domEmotion} (${emoConf}%)`;
|
| 428 |
+
|
| 429 |
+
const raceEl = document.getElementById('race');
|
| 430 |
+
const raceDotClass = getConfidenceDotClass(raceConf);
|
| 431 |
+
raceEl.innerHTML = `<span class="confidence-dot ${raceDotClass}"></span> ${domRace} (${raceConf}%)`;
|
| 432 |
+
|
| 433 |
+
debugMsg.innerText = "HUD STABILIZED. TRACKING...";
|
| 434 |
+
} else {
|
| 435 |
+
debugMsg.innerText = "SEARCHING FOR TARGET FACE...";
|
| 436 |
+
predictions = []; // Reset buffer if face lost
|
| 437 |
+
}
|
| 438 |
+
} catch (err) {
|
| 439 |
+
debugMsg.innerText = "SYNC ERROR: RETRYING...";
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
setTimeout(analyzeFrame, 1000);
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
async function triggerHiResScan() {
|
| 446 |
+
debugMsg.innerText = "TRIGGERING HIGH-PRECISION SCAN...";
|
| 447 |
+
const genderEl = document.getElementById('gender');
|
| 448 |
+
genderEl.classList.add('loading');
|
| 449 |
+
genderEl.innerHTML = '<span class="skeleton-loader"></span>';
|
| 450 |
+
|
| 451 |
+
// Capture high res frame
|
| 452 |
+
canvas.width = 640;
|
| 453 |
+
canvas.height = 480;
|
| 454 |
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 455 |
+
const base64Image = canvas.toDataURL('image/jpeg', 0.9);
|
| 456 |
+
|
| 457 |
+
try {
|
| 458 |
+
const response = await fetch("{{ url_for('analysis.live_frame') }}", {
|
| 459 |
+
method: "POST",
|
| 460 |
+
headers: { "Content-Type": "application/json" },
|
| 461 |
+
body: JSON.stringify({ image: base64Image, accuracy: 'high' })
|
| 462 |
+
});
|
| 463 |
+
const data = await response.json();
|
| 464 |
+
|
| 465 |
+
if (data.results && data.results.faces && data.results.faces.length > 0) {
|
| 466 |
+
const face = data.results.faces[0];
|
| 467 |
+
|
| 468 |
+
// Simulate precision scan estimation time
|
| 469 |
+
await new Promise(resolve => setTimeout(resolve, 1200));
|
| 470 |
+
|
| 471 |
+
const genConf = Math.round(face.gender[face.dominant_gender]);
|
| 472 |
+
const ageConf = Math.round(face.face_confidence * 100);
|
| 473 |
+
const emoConf = Math.round(face.emotion[face.dominant_emotion]);
|
| 474 |
+
const raceConf = Math.round(face.race[face.dominant_race]);
|
| 475 |
+
|
| 476 |
+
genderEl.classList.remove('loading');
|
| 477 |
+
const genDot = getConfidenceDotClass(genConf);
|
| 478 |
+
genderEl.innerHTML = `<span class="confidence-dot ${genDot}"></span> ${face.dominant_gender} (PRECISION)`;
|
| 479 |
+
|
| 480 |
+
const ageEl = document.getElementById('age');
|
| 481 |
+
const ageDot = getConfidenceDotClass(ageConf);
|
| 482 |
+
ageEl.innerHTML = `<span class="confidence-dot ${ageDot}"></span> ${face.age}y (PRECISION)`;
|
| 483 |
+
|
| 484 |
+
const emotionEl = document.getElementById('emotion');
|
| 485 |
+
const emoDot = getConfidenceDotClass(emoConf);
|
| 486 |
+
emotionEl.innerHTML = `<span class="confidence-dot ${emoDot}"></span> ${face.dominant_emotion}`;
|
| 487 |
+
|
| 488 |
+
const raceEl = document.getElementById('race');
|
| 489 |
+
const raceDot = getConfidenceDotClass(raceConf);
|
| 490 |
+
raceEl.innerHTML = `<span class="confidence-dot ${raceDot}"></span> ${face.dominant_race}`;
|
| 491 |
+
|
| 492 |
+
debugMsg.innerText = "DEEP SCAN COMPLETE. ACCURACY MAXIMIZED.";
|
| 493 |
+
} else {
|
| 494 |
+
genderEl.classList.remove('loading');
|
| 495 |
+
debugMsg.innerText = "PRECISION SCAN FAILED: FACE NOT FOUND.";
|
| 496 |
+
}
|
| 497 |
+
} catch (err) {
|
| 498 |
+
genderEl.classList.remove('loading');
|
| 499 |
+
debugMsg.innerText = "SCAN ERROR: " + err.message;
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
video.addEventListener('playing', () => {
|
| 504 |
+
analyzeFrame();
|
| 505 |
+
});
|
| 506 |
+
|
| 507 |
+
startVideo();
|
| 508 |
+
</script>
|
| 509 |
+
{% endblock %}
|
app/templates/verification.html
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Face Verification</h1>
|
| 6 |
+
<p class="animate-up">Determine if two different images represent the same individual.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="card animate-up" style="max-width: 1000px; margin: 0 auto; text-align: center;">
|
| 10 |
+
<form action="{{ url_for('recognition.verify_face') }}" method="post" enctype="multipart/form-data">
|
| 11 |
+
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; margin-bottom: 3rem;">
|
| 12 |
+
<!-- Left Side Upload -->
|
| 13 |
+
<div style="background: rgba(255, 255, 255, 0.02); padding: 2rem; border-radius: 20px; border: 2px dashed var(--glass-border); display: flex; flex-direction: column; align-items: center;">
|
| 14 |
+
<i class="fa-solid fa-user- astronaut" style="font-size: 3rem; color: var(--accent); margin-bottom: 1.5rem;"></i>
|
| 15 |
+
<label for="img1" class="btn" style="background: rgba(255, 255, 255, 0.05); border: 1px solid var(--accent);">
|
| 16 |
+
<i class="fa-solid fa-plus"></i> Select Subject A
|
| 17 |
+
<input type="file" name="img1" id="img1" hidden onchange="previewImage(this, 'preview1')">
|
| 18 |
+
</label>
|
| 19 |
+
<div id="preview1-container" style="margin-top: 1.5rem; width: 100%; display: none;">
|
| 20 |
+
<img id="preview1" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px;">
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
<!-- Right Side Upload -->
|
| 25 |
+
<div style="background: rgba(255, 255, 255, 0.02); padding: 2rem; border-radius: 20px; border: 2px dashed var(--glass-border); display: flex; flex-direction: column; align-items: center;">
|
| 26 |
+
<i class="fa-solid fa-user-secret" style="font-size: 3rem; color: #ec4899; margin-bottom: 1.5rem;"></i>
|
| 27 |
+
<label for="img2" class="btn" style="background: rgba(255, 255, 255, 0.05); border: 1px solid #ec4899;">
|
| 28 |
+
<i class="fa-solid fa-plus"></i> Select Subject B
|
| 29 |
+
<input type="file" name="img2" id="img2" hidden onchange="previewImage(this, 'preview2')">
|
| 30 |
+
</label>
|
| 31 |
+
<div id="preview2-container" style="margin-top: 1.5rem; width: 100%; display: none;">
|
| 32 |
+
<img id="preview2" style="width: 100%; height: 200px; object-fit: cover; border-radius: 10px;">
|
| 33 |
+
</div>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<div style="background: rgba(255, 255, 255, 0.05); padding: 2rem; border-radius: 12px; margin-bottom: 2rem; text-align: left;">
|
| 38 |
+
<h3 style="margin-bottom: 1rem; font-family: 'Outfit';">Verification Engine Config</h3>
|
| 39 |
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem;">
|
| 40 |
+
<div>
|
| 41 |
+
<label style="font-size: 0.8rem; color: var(--text-secondary);">Model Architecture</label>
|
| 42 |
+
<select name="model" style="width: 100%; padding: 10px; border-radius: 8px; background: rgba(0,0,0,0.5); color: white; border: 1px solid var(--glass-border);">
|
| 43 |
+
<option value="VGG-Face">VGG-Face (Baseline)</option>
|
| 44 |
+
<option value="Facenet">FaceNet (High Accuracy)</option>
|
| 45 |
+
<option value="ArcFace">ArcFace (Robust)</option>
|
| 46 |
+
<option value="OpenFace">OpenFace (Efficient)</option>
|
| 47 |
+
</select>
|
| 48 |
+
</div>
|
| 49 |
+
<div>
|
| 50 |
+
<label style="font-size: 0.8rem; color: var(--text-secondary);">Similarity Threshold</label>
|
| 51 |
+
<p style="padding: 10px; color: var(--success); font-weight: 600;">Adaptive (Dynamic)</p>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
|
| 56 |
+
<button type="submit" class="btn" style="background: var(--accent); padding: 1.2rem 4rem; font-size: 1.1rem;">
|
| 57 |
+
Run Match Evaluation <i class="fa-solid fa-fingerprint"></i>
|
| 58 |
+
</button>
|
| 59 |
+
</form>
|
| 60 |
+
</div>
|
| 61 |
+
|
| 62 |
+
<script>
|
| 63 |
+
function previewImage(input, previewId) {
|
| 64 |
+
if (input.files && input.files[0]) {
|
| 65 |
+
var reader = new FileReader();
|
| 66 |
+
reader.onload = function(e) {
|
| 67 |
+
var container = document.getElementById(previewId + '-container');
|
| 68 |
+
var img = document.getElementById(previewId);
|
| 69 |
+
img.src = e.target.result;
|
| 70 |
+
container.style.display = 'block';
|
| 71 |
+
}
|
| 72 |
+
reader.readAsDataURL(input.files[0]);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
</script>
|
| 76 |
+
{% endblock %}
|
app/templates/verification_result.html
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "layout.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="header">
|
| 5 |
+
<h1 class="animate-up">Match Evaluation</h1>
|
| 6 |
+
<p class="animate-up">Similarity verification using advanced deep neural networks.</p>
|
| 7 |
+
</div>
|
| 8 |
+
|
| 9 |
+
<div class="card animate-up" style="max-width: 1000px; margin: 0 auto; text-align: center;">
|
| 10 |
+
<div style="display: flex; justify-content: space-around; align-items: center; margin-bottom: 4rem;">
|
| 11 |
+
<div style="position: relative;">
|
| 12 |
+
<img src="{{ url_for('static', filename='uploads/' + img1) }}" style="width: 250px; height: 250px; object-fit: cover; border-radius: 50%; border: 4px solid var(--accent); box-shadow: 0 10px 30px var(--accent-glow);">
|
| 13 |
+
<div style="position: absolute; bottom: 0; right: 0; background: var(--bg-color); border: 1px solid var(--accent); padding: 5px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 700;">SUBJECT A</div>
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<div style="display: flex; flex-direction: column; align-items: center; gap: 1rem; z-index: 2;">
|
| 17 |
+
{% if result.verified %}
|
| 18 |
+
<div style="font-size: 4rem; color: var(--success); text-shadow: 0 0 20px rgba(16, 185, 129, 0.4);">
|
| 19 |
+
<i class="fa-solid fa-circle-check"></i>
|
| 20 |
+
</div>
|
| 21 |
+
<h2 style="font-family: 'Outfit'; color: var(--success); letter-spacing: 2px;">MATCH FOUND</h2>
|
| 22 |
+
{% else %}
|
| 23 |
+
<div style="font-size: 4rem; color: var(--error); text-shadow: 0 0 20px rgba(239, 68, 68, 0.4);">
|
| 24 |
+
<i class="fa-solid fa-circle-xmark"></i>
|
| 25 |
+
</div>
|
| 26 |
+
<h2 style="font-family: 'Outfit'; color: var(--error); letter-spacing: 2px;">NO MATCH</h2>
|
| 27 |
+
{% endif %}
|
| 28 |
+
|
| 29 |
+
<div style="background: rgba(255, 255, 255, 0.05); padding: 5px 20px; border-radius: 30px; border: 1px solid var(--glass-border); font-size: 0.9rem;">
|
| 30 |
+
Distance Scale: <span style="{% if result.verified %}color: var(--success);{% else %}color: var(--error);{% endif %} font-weight: 700;">{{ "%.4f"|format(result.distance) }}</span>
|
| 31 |
+
</div>
|
| 32 |
+
<p style="font-size: 0.8rem; color: var(--text-secondary);">(Threshold: {{ result.threshold }})</p>
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
+
<div style="position: relative;">
|
| 36 |
+
<img src="{{ url_for('static', filename='uploads/' + img2) }}" style="width: 250px; height: 250px; object-fit: cover; border-radius: 50%; border: 4px solid #ec4899; box-shadow: 0 10px 30px rgba(236, 72, 153, 0.4);">
|
| 37 |
+
<div style="position: absolute; bottom: 0; right: 0; background: var(--bg-color); border: 1px solid #ec4899; padding: 5px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 700;">SUBJECT B</div>
|
| 38 |
+
</div>
|
| 39 |
+
</div>
|
| 40 |
+
|
| 41 |
+
<!-- Metrics Breakdown Card -->
|
| 42 |
+
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem;">
|
| 43 |
+
<div class="card" style="background: rgba(255, 255, 255, 0.02); padding: 1.5rem; border-color: rgba(255, 255, 255, 0.05);">
|
| 44 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase;">Confidence</p>
|
| 45 |
+
<h4 style="font-size: 1.5rem; margin-top: 5px;">{{ "%.1f"|format((1 - result.distance) * 100 if result.distance < 1 else 0) }}%</h4>
|
| 46 |
+
</div>
|
| 47 |
+
<div class="card" style="background: rgba(255, 255, 255, 0.02); padding: 1.5rem; border-color: rgba(255, 255, 255, 0.05);">
|
| 48 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase;">Similarity Metric</p>
|
| 49 |
+
<h4 style="font-size: 1.5rem; margin-top: 5px; text-transform: capitalize;">{{ result.similarity_metric }}</h4>
|
| 50 |
+
</div>
|
| 51 |
+
<div class="card" style="background: rgba(255, 255, 255, 0.02); padding: 1.5rem; border-color: rgba(255, 255, 255, 0.05);">
|
| 52 |
+
<p style="font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase;">Inference Model</p>
|
| 53 |
+
<h4 style="font-size: 1.5rem; margin-top: 5px;">{{ result.model }}</h4>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<div style="margin-top: 3rem; display: flex; justify-content: center; gap: 2rem;">
|
| 58 |
+
<a href="{{ url_for('recognition.verify_face') }}" class="btn" style="padding: 1rem 3rem;">
|
| 59 |
+
<i class="fa-solid fa-arrows-rotate"></i> NEW VERIFICATION
|
| 60 |
+
</a>
|
| 61 |
+
</div>
|
| 62 |
+
|
| 63 |
+
<div style="margin-top: 4rem; text-align: left;">
|
| 64 |
+
<h4 style="margin-bottom: 1rem; color: var(--text-secondary); text-transform: uppercase; font-size: 0.75rem;">Model Response JSON</h4>
|
| 65 |
+
<pre style="background: rgba(0,0,0,0.3); padding: 1.5rem; border-radius: 10px; font-size: 0.8rem; overflow-x: auto; color: #a5b4fc; text-align: left;">{{ result|tojson(indent=2) }}</pre>
|
| 66 |
+
</div>
|
| 67 |
+
</div>
|
| 68 |
+
{% endblock %}
|
app/utils/__init__.py
ADDED
|
File without changes
|
app/utils/ml_engine.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from deepface import DeepFace
|
| 2 |
+
import os
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
import logging
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
class FaceAnalyzer:
|
| 11 |
+
def __init__(self, detector_backend='opencv'):
|
| 12 |
+
"""
|
| 13 |
+
Face recognition and analysis engine using DeepFace.
|
| 14 |
+
'opencv' is used for fast real-time analysis.
|
| 15 |
+
"""
|
| 16 |
+
self.detector_backend = detector_backend
|
| 17 |
+
logger.info(f"Initialized FaceAnalyzer with {detector_backend} backend.")
|
| 18 |
+
|
| 19 |
+
@staticmethod
|
| 20 |
+
def _sanitize_results(obj):
|
| 21 |
+
"""
|
| 22 |
+
Recursively converts NumPy types to standard Python types for JSON serialization.
|
| 23 |
+
Handles float32, int64, ndarray, etc.
|
| 24 |
+
"""
|
| 25 |
+
if isinstance(obj, dict):
|
| 26 |
+
return {k: FaceAnalyzer._sanitize_results(v) for k, v in obj.items()}
|
| 27 |
+
elif isinstance(obj, (list, tuple)):
|
| 28 |
+
return [FaceAnalyzer._sanitize_results(i) for i in obj]
|
| 29 |
+
|
| 30 |
+
# Check for NumPy types (even if not imported as np)
|
| 31 |
+
type_name = type(obj).__name__
|
| 32 |
+
if 'float' in type_name:
|
| 33 |
+
return float(obj)
|
| 34 |
+
elif 'int' in type_name:
|
| 35 |
+
return int(obj)
|
| 36 |
+
elif 'ndarray' in type_name:
|
| 37 |
+
return FaceAnalyzer._sanitize_results(obj.tolist())
|
| 38 |
+
elif hasattr(obj, 'item') and callable(getattr(obj, 'item')):
|
| 39 |
+
return obj.item()
|
| 40 |
+
|
| 41 |
+
return obj
|
| 42 |
+
|
| 43 |
+
def analyze(self, img_path):
|
| 44 |
+
"""
|
| 45 |
+
Analyzes an image for age, gender, emotion, and race.
|
| 46 |
+
Returns the findings as a dict.
|
| 47 |
+
"""
|
| 48 |
+
try:
|
| 49 |
+
start_time = time.time()
|
| 50 |
+
# Try to run all actions first.
|
| 51 |
+
results = DeepFace.analyze(
|
| 52 |
+
img_path=img_path,
|
| 53 |
+
actions=['age', 'gender', 'emotion', 'race'],
|
| 54 |
+
detector_backend=self.detector_backend,
|
| 55 |
+
enforce_detection=False,
|
| 56 |
+
silent=True
|
| 57 |
+
)
|
| 58 |
+
process_time = time.time() - start_time
|
| 59 |
+
logger.info(f"Analysis completed in {process_time:.2f}s")
|
| 60 |
+
|
| 61 |
+
if isinstance(results, list):
|
| 62 |
+
final_results = {"faces": results, "count": len(results), "process_time": process_time}
|
| 63 |
+
else:
|
| 64 |
+
final_results = {"faces": [results], "count": 1, "process_time": process_time}
|
| 65 |
+
|
| 66 |
+
return FaceAnalyzer._sanitize_results(final_results)
|
| 67 |
+
|
| 68 |
+
except Exception as e:
|
| 69 |
+
logger.warning(f"Full analysis failed ({str(e)}), trying detection only...")
|
| 70 |
+
try:
|
| 71 |
+
# Fallback to basic detection if models are missing
|
| 72 |
+
detection_results = DeepFace.extract_faces(
|
| 73 |
+
img_path=img_path,
|
| 74 |
+
detector_backend=self.detector_backend,
|
| 75 |
+
enforce_detection=False
|
| 76 |
+
)
|
| 77 |
+
faces = []
|
| 78 |
+
for face in detection_results:
|
| 79 |
+
faces.append({
|
| 80 |
+
"face_confidence": face['confidence'],
|
| 81 |
+
"dominant_gender": "Download Failed",
|
| 82 |
+
"age": "??",
|
| 83 |
+
"dominant_emotion": "See Logs",
|
| 84 |
+
"dominant_race": "Missing Models",
|
| 85 |
+
"emotion": {},
|
| 86 |
+
"warning": "Neural weights (age/gender/emotion) failed to download from GitHub. Please check server logs for manual download instructions."
|
| 87 |
+
})
|
| 88 |
+
fallback_results = {"faces": faces, "count": len(faces), "process_time": 0.5, "partial": True}
|
| 89 |
+
return FaceAnalyzer._sanitize_results(fallback_results)
|
| 90 |
+
except Exception as e2:
|
| 91 |
+
logger.error(f"Detection fallback failed: {str(e2)}")
|
| 92 |
+
return {"error": f"ML Engine error: {str(e)}"}
|
| 93 |
+
|
| 94 |
+
def verify(self, img1_path, img2_path, model_name='VGG-Face'):
|
| 95 |
+
"""
|
| 96 |
+
Verifies if two images contain the same person.
|
| 97 |
+
Models: 'VGG-Face', 'Facenet', 'OpenFace', 'DeepFace', 'DeepID', 'ArcFace', 'Dlib', 'SFace', 'GhostFaceNet'
|
| 98 |
+
"""
|
| 99 |
+
try:
|
| 100 |
+
start_time = time.time()
|
| 101 |
+
result = DeepFace.verify(
|
| 102 |
+
img1_path=img1_path,
|
| 103 |
+
img2_path=img2_path,
|
| 104 |
+
model_name=model_name,
|
| 105 |
+
detector_backend=self.detector_backend,
|
| 106 |
+
enforce_detection=False,
|
| 107 |
+
silent=True
|
| 108 |
+
)
|
| 109 |
+
process_time = time.time() - start_time
|
| 110 |
+
result['process_time'] = process_time
|
| 111 |
+
return FaceAnalyzer._sanitize_results(result)
|
| 112 |
+
except Exception as e:
|
| 113 |
+
logger.error(f"Verification failed: {str(e)}")
|
| 114 |
+
return {"error": str(e)}
|
| 115 |
+
|
| 116 |
+
def find_in_db(self, img_path, db_path, model_name='VGG-Face'):
|
| 117 |
+
"""
|
| 118 |
+
Finds the closest matches in a database folder.
|
| 119 |
+
"""
|
| 120 |
+
try:
|
| 121 |
+
start_time = time.time()
|
| 122 |
+
results = DeepFace.find(
|
| 123 |
+
img_path=img_path,
|
| 124 |
+
db_path=db_path,
|
| 125 |
+
model_name=model_name,
|
| 126 |
+
detector_backend=self.detector_backend,
|
| 127 |
+
enforce_detection=False,
|
| 128 |
+
silent=True
|
| 129 |
+
)
|
| 130 |
+
process_time = time.time() - start_time
|
| 131 |
+
logger.info(f"Search in DB completed in {process_time:.2f}s")
|
| 132 |
+
# results is a list of dataframes
|
| 133 |
+
matches = []
|
| 134 |
+
if isinstance(results, list):
|
| 135 |
+
for df in results:
|
| 136 |
+
if not df.empty:
|
| 137 |
+
matches.append(df.to_dict('records'))
|
| 138 |
+
final_matches = {"matches": matches, "process_time": process_time}
|
| 139 |
+
return FaceAnalyzer._sanitize_results(final_matches)
|
| 140 |
+
except Exception as e:
|
| 141 |
+
logger.error(f"Database search failed: {str(e)}")
|
| 142 |
+
return {"error": str(e)}
|
| 143 |
+
|
| 144 |
+
analyzer = FaceAnalyzer()
|
requirements.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask>=3.0.0
|
| 2 |
+
flask-cors>=4.0.0
|
| 3 |
+
opencv-python-headless>=4.8.0
|
| 4 |
+
deepface>=0.0.86
|
| 5 |
+
tensorflow>=2.13.0
|
| 6 |
+
numpy>=1.24.0
|
| 7 |
+
pillow>=10.0.0
|
| 8 |
+
python-dotenv>=1.0.0
|
| 9 |
+
gunicorn>=21.2.0
|
| 10 |
+
werkzeug>=3.0.0
|
| 11 |
+
tf-keras
|
run.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from app import create_app
|
| 2 |
+
import os
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
# Configure logging for production
|
| 6 |
+
logging.basicConfig(level=logging.INFO)
|
| 7 |
+
|
| 8 |
+
app = create_app()
|
| 9 |
+
|
| 10 |
+
if __name__ == "__main__":
|
| 11 |
+
# Get port from environment (7860 for HF Spaces, 5000 for local/other)
|
| 12 |
+
port = int(os.environ.get("PORT", 5000))
|
| 13 |
+
debug_mode = os.environ.get("FLASK_ENV") != "production"
|
| 14 |
+
|
| 15 |
+
print(f"\n{'='*60}")
|
| 16 |
+
print(f"🚀 VISION.AI - Face Recognition Engine")
|
| 17 |
+
print(f"{'='*60}")
|
| 18 |
+
print(f"📍 Running on http://0.0.0.0:{port}")
|
| 19 |
+
print(f"🔧 Debug Mode: {debug_mode}")
|
| 20 |
+
print(f"🤗 Hugging Face Spaces: {os.environ.get('HUGGINGFACE_SPACE', 'No')}")
|
| 21 |
+
print(f"{'='*60}\n")
|
| 22 |
+
|
| 23 |
+
# In development, use debug=True with reloader
|
| 24 |
+
# For production, use Gunicorn (defined in Dockerfile/deployment)
|
| 25 |
+
app.run(
|
| 26 |
+
host="0.0.0.0",
|
| 27 |
+
port=port,
|
| 28 |
+
debug=debug_mode,
|
| 29 |
+
use_reloader=debug_mode
|
| 30 |
+
)
|
scripts/download.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
BASE_URL = "https://github.com/serengil/deepface_models/releases"
|
| 6 |
+
|
| 7 |
+
def get_h5_links():
|
| 8 |
+
print("Fetching release page...")
|
| 9 |
+
r = requests.get(BASE_URL)
|
| 10 |
+
r.raise_for_status()
|
| 11 |
+
|
| 12 |
+
soup = BeautifulSoup(r.text, "html.parser")
|
| 13 |
+
|
| 14 |
+
links = []
|
| 15 |
+
for a in soup.find_all("a"):
|
| 16 |
+
href = a.get("href", "")
|
| 17 |
+
if href.endswith(".h5"):
|
| 18 |
+
full_url = "https://github.com" + href
|
| 19 |
+
links.append(full_url)
|
| 20 |
+
|
| 21 |
+
return list(set(links))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def download_file(url):
|
| 25 |
+
filename = url.split("/")[-1]
|
| 26 |
+
print(f"Downloading {filename}...")
|
| 27 |
+
|
| 28 |
+
with requests.get(url, stream=True) as r:
|
| 29 |
+
r.raise_for_status()
|
| 30 |
+
with open(filename, "wb") as f:
|
| 31 |
+
for chunk in r.iter_content(chunk_size=8192):
|
| 32 |
+
if chunk:
|
| 33 |
+
f.write(chunk)
|
| 34 |
+
|
| 35 |
+
print(f"Saved: {filename}")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def main():
|
| 39 |
+
links = get_h5_links()
|
| 40 |
+
|
| 41 |
+
if not links:
|
| 42 |
+
print("No .h5 files found ❌")
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
print(f"Found {len(links)} files")
|
| 46 |
+
|
| 47 |
+
for link in links:
|
| 48 |
+
download_file(link)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
main()
|
scripts/download_weights.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import urllib.request
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def main():
|
| 6 |
+
# Ensure tqdm is available
|
| 7 |
+
try:
|
| 8 |
+
from tqdm import tqdm
|
| 9 |
+
except ImportError:
|
| 10 |
+
print("Installing tqdm for progress bars...")
|
| 11 |
+
os.system(f"{sys.executable} -m pip install tqdm")
|
| 12 |
+
from tqdm import tqdm
|
| 13 |
+
|
| 14 |
+
# Detect if we are in a cloud CI/Docker build (non-TTY)
|
| 15 |
+
is_tty = sys.stdout.isatty()
|
| 16 |
+
|
| 17 |
+
class DownloadProgressBar(tqdm):
|
| 18 |
+
def __init__(self, *args, **kwargs):
|
| 19 |
+
if not is_tty:
|
| 20 |
+
kwargs['disable'] = True # Disable visual bar in cloud logs
|
| 21 |
+
super().__init__(*args, **kwargs)
|
| 22 |
+
|
| 23 |
+
def update_to(self, b=1, bsize=1, tsize=None):
|
| 24 |
+
if tsize is not None:
|
| 25 |
+
self.total = tsize
|
| 26 |
+
self.update(b * bsize - self.n)
|
| 27 |
+
if not is_tty and b % 100 == 0: # Print status periodically for logs
|
| 28 |
+
print(f"Downloaded: {int((b*bsize/tsize)*100)}%...", flush=True)
|
| 29 |
+
|
| 30 |
+
def download_url(url, output_path):
|
| 31 |
+
with DownloadProgressBar(unit='B', unit_scale=True,
|
| 32 |
+
miniters=1, desc=url.split('/')[-1]) as t:
|
| 33 |
+
urllib.request.urlretrieve(url, filename=output_path, reporthook=t.update_to)
|
| 34 |
+
|
| 35 |
+
# DeepFace weights directory
|
| 36 |
+
home = os.path.expanduser("~")
|
| 37 |
+
weights_dir = os.path.join(home, ".deepface", "weights")
|
| 38 |
+
|
| 39 |
+
if not os.path.exists(weights_dir):
|
| 40 |
+
os.makedirs(weights_dir)
|
| 41 |
+
print(f"Created directory: {weights_dir}")
|
| 42 |
+
|
| 43 |
+
models = {
|
| 44 |
+
"vgg_face_weights.h5": "https://github.com/danidoble/deepface_models/releases/download/v1.0/vgg_face_weights.h5",
|
| 45 |
+
"age_model_weights.h5": "https://github.com/danidoble/deepface_models/releases/download/v1.0/age_model_weights.h5",
|
| 46 |
+
"gender_model_weights.h5": "https://github.com/danidoble/deepface_models/releases/download/v1.0/gender_model_weights.h5",
|
| 47 |
+
"facial_expression_model_weights.h5": "https://github.com/danidoble/deepface_models/releases/download/v1.0/facial_expression_model_weights.h5",
|
| 48 |
+
"race_model_single_batch.h5": "https://github.com/danidoble/deepface_models/releases/download/v1.0/race_model_single_batch.h5"
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
print("--- Vision.AI Weight Downloader ---")
|
| 52 |
+
print(f"Target directory: {weights_dir}")
|
| 53 |
+
|
| 54 |
+
for filename, url in models.items():
|
| 55 |
+
destination = os.path.join(weights_dir, filename)
|
| 56 |
+
|
| 57 |
+
# Determine expected minimum size (mostly to catch tiny corrupted files)
|
| 58 |
+
# VGG, Age, Gender are > 100MB. Race is ~150MB. Emotion is 5MB.
|
| 59 |
+
min_size = 40 * 1024 * 1024 # 40MB default
|
| 60 |
+
if "facial_expression" in filename:
|
| 61 |
+
min_size = 5 * 1024 * 1024 # 5MB for emotion
|
| 62 |
+
|
| 63 |
+
if os.path.exists(destination):
|
| 64 |
+
file_size = os.path.getsize(destination)
|
| 65 |
+
if file_size > min_size:
|
| 66 |
+
print(f"[SKIP] {filename} already exists ({file_size/1024/1024:.1f} MB).")
|
| 67 |
+
continue
|
| 68 |
+
else:
|
| 69 |
+
print(f"[RE-DOWNLOAD] {filename} appears corrupted or incomplete ({file_size/1024/1024:.1f} MB).")
|
| 70 |
+
|
| 71 |
+
print(f"[DOWNLOADING] {filename}...")
|
| 72 |
+
try:
|
| 73 |
+
download_url(url, destination)
|
| 74 |
+
print(f"[SUCCESS] Saved to {destination}")
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f"[ERROR] Failed to download {filename}: {e}")
|
| 77 |
+
|
| 78 |
+
print("\nAll tasks completed. You can now run the app using 'python run.py'.")
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
main()
|
scripts/start_project.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def main():
|
| 6 |
+
print("--- Vision.AI Standard Setup & Launch ---")
|
| 7 |
+
|
| 8 |
+
# 1. Detect environment
|
| 9 |
+
project_root = os.getcwd()
|
| 10 |
+
venv_python = os.path.join(project_root, "venv", "Scripts", "python.exe")
|
| 11 |
+
|
| 12 |
+
if os.path.exists(venv_python):
|
| 13 |
+
print(f"Detected Virtual Environment: {venv_python}")
|
| 14 |
+
python_exe = venv_python
|
| 15 |
+
else:
|
| 16 |
+
print("Warning: No virtual environment detected. Using system Python.")
|
| 17 |
+
python_exe = sys.executable
|
| 18 |
+
|
| 19 |
+
# 2. Ensure basic requirements (checking if deepface exists first)
|
| 20 |
+
try:
|
| 21 |
+
subprocess.run([python_exe, "-c", "import deepface"], check=True, capture_output=True)
|
| 22 |
+
print("Required packages (deepface) already installed.")
|
| 23 |
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
| 24 |
+
print("Installing dependencies from requirements.txt...")
|
| 25 |
+
# Note: We use --no-deps or specific install if global pip is broken,
|
| 26 |
+
# but here we just try standard install first
|
| 27 |
+
subprocess.run([python_exe, "-m", "pip", "install", "-r", "requirements.txt"])
|
| 28 |
+
|
| 29 |
+
# 3. Check for weights
|
| 30 |
+
print("\nChecking for ML weights...")
|
| 31 |
+
scripts_dir = os.path.join(project_root, "scripts")
|
| 32 |
+
download_script = os.path.join(scripts_dir, "download_weights.py")
|
| 33 |
+
|
| 34 |
+
if os.path.exists(download_script):
|
| 35 |
+
subprocess.run([python_exe, download_script])
|
| 36 |
+
else:
|
| 37 |
+
print(f"[ERROR] Found no download script at {download_script}")
|
| 38 |
+
|
| 39 |
+
# 4. Launch the app
|
| 40 |
+
print("\nLaunching Vision.AI Dashboard...")
|
| 41 |
+
print("Point your browser to http://127.0.0.1:5000")
|
| 42 |
+
print("Press CTRL+C to stop.")
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
subprocess.run([python_exe, "run.py"])
|
| 46 |
+
except KeyboardInterrupt:
|
| 47 |
+
print("\nStopping...")
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
main()
|