import cv2 import gradio as gr from deepface import DeepFace def analyze_fn(img_path): # Load the image only once for better performance img = cv2.imread(img_path) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) objs = DeepFace.analyze(img_path=img_path, actions=['age', 'gender', 'race', 'emotion']) obj = objs[0] age = obj["age"] gender = obj["dominant_gender"] race = obj["dominant_race"] emotion = obj["dominant_emotion"] region = obj["region"] x, y, w, h = region["x"], region["y"], region["w"], region["h"] # Draw the rectangle on the image cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) return [img, age, gender, race, emotion] with gr.Blocks() as demo: title = """