Owlcamswap / app.py
Deadcam's picture
Update app.py
ad7ee3d verified
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
# Convert from PIL to OpenCV (RGB β†’ BGR)
cv2_img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
# Save temporary image file
temp_path = "input.jpg"
cv2.imwrite(temp_path, cv2_img)
globals.target_path = temp_path
# Reset mapping before each run
globals.source_target_map = []
try:
face_analyser.get_unique_faces_from_target_image()
except Exception as e:
return f"Face detection error: {e}"
# Return first cropped face (if available)
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()