File size: 620 Bytes
4e03723
 
e4f0042
 
4e03723
e4f0042
4e03723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
import cv2
from PIL import Image
import gradio as gr

def detect_objects(img):
    # Download the model
    path = hf_hub_download("Bingsu/adetailer", "face_yolov8n.pt")
    model = YOLO(path)

    # Run the model
    output = model(img)
    pred = output[0].plot()
    pred = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
    pred = Image.fromarray(pred)

    # Return the output
    return pred

# Define a Gradio interface for the function
iface = gr.Interface(fn=detect_objects, inputs="image", outputs="image")

# Launch the interface
iface.launch()