Spaces:
Runtime error
Runtime error
import gradio as gr | |
import cv2 | |
from insightface.app import FaceAnalysis | |
import torch | |
app = FaceAnalysis(name="buffalo_l", providers=['CUDAExecutionProvider', 'CPUExecutionProvider']) | |
app.prepare(ctx_id=0, det_size=(640, 640)) | |
def calculate(photo): | |
image = cv2.imread(photo) | |
faces = app.get(image) | |
faceid_embeds = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0) | |
return faceid_embeds | |
with gr.Blocks() as demo: | |
face_photo = gr.Image(label="Photo", type="filepath") | |
output = gr.JSON() | |
greet_btn = gr.Button("Calculate") | |
greet_btn.click(fn=calculate, inputs=face_photo, outputs=output, api_name="calculate_face_embedding") | |
if __name__ == "__main__": | |
demo.launch() |