Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,25 @@
|
|
|
|
|
|
1 |
import cv2
|
2 |
from PIL import Image
|
|
|
3 |
|
4 |
-
img
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import hf_hub_download
|
2 |
+
from ultralytics import YOLO
|
3 |
import cv2
|
4 |
from PIL import Image
|
5 |
+
import gradio as gr
|
6 |
|
7 |
+
def detect_objects(img):
|
8 |
+
# Download the model
|
9 |
+
path = hf_hub_download("Bingsu/adetailer", "face_yolov8n.pt")
|
10 |
+
model = YOLO(path)
|
11 |
+
|
12 |
+
# Run the model
|
13 |
+
output = model(img)
|
14 |
+
pred = output[0].plot()
|
15 |
+
pred = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
|
16 |
+
pred = Image.fromarray(pred)
|
17 |
+
|
18 |
+
# Return the output
|
19 |
+
return pred
|
20 |
+
|
21 |
+
# Define a Gradio interface for the function
|
22 |
+
iface = gr.Interface(fn=detect_objects, inputs="image", outputs="image")
|
23 |
+
|
24 |
+
# Launch the interface
|
25 |
+
iface.launch()
|