File size: 1,144 Bytes
352413c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import cv2
import numpy as np
from modules import globals, face_analyser
import os

# Basic inference function
def process_webcam_frame(image):
    if image is None:
        return None

    # Save temp image
    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 None

    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 None

demo = gr.Interface(
    fn=process_webcam_frame,
    inputs=gr.Image(source="webcam", label="Webcam Input", type="pil"),
    outputs=gr.Image(label="Processed Face", type="numpy"),
    title="🦉 OwlCamPro – Live Face Detection & Swap",
    description="Real-time face processing using Deep-Live-Cam modules. Upload or use your webcam."
)

if __name__ == "__main__":
    demo.launch()