|
|
import gradio as gr |
|
|
import cv2 |
|
|
import numpy as np |
|
|
import os |
|
|
|
|
|
from modules import face_analyser, globals |
|
|
|
|
|
def detect_faces(image): |
|
|
if image is None: |
|
|
return None |
|
|
|
|
|
|
|
|
cv2_img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) |
|
|
|
|
|
|
|
|
temp_path = "input.jpg" |
|
|
cv2.imwrite(temp_path, cv2_img) |
|
|
globals.target_path = temp_path |
|
|
|
|
|
|
|
|
globals.source_target_map = [] |
|
|
|
|
|
try: |
|
|
face_analyser.get_unique_faces_from_target_image() |
|
|
except Exception as e: |
|
|
return f"Face detection error: {e}" |
|
|
|
|
|
|
|
|
if globals.source_target_map and "target" in globals.source_target_map[0]: |
|
|
crop = globals.source_target_map[0]["target"]["cv2"] |
|
|
return cv2.cvtColor(crop, cv2.COLOR_BGR2RGB) |
|
|
|
|
|
return "No faces found." |
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=detect_faces, |
|
|
inputs=gr.Image(type="pil", label="Upload your image"), |
|
|
outputs="image", |
|
|
title="π¦ OwlCamPro β Face Detection Preview", |
|
|
description="Upload an image to detect and extract the most prominent face. Powered by InsightFace and Deep-Live-Cam 2.0." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|