Jeffgold commited on
Commit
4e03723
1 Parent(s): 3f20423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -1,9 +1,25 @@
 
 
1
  import cv2
2
  from PIL import Image
 
3
 
4
- img = "https://farm5.staticflickr.com/4139/4887614566_6b57ec4422_z.jpg"
5
- output = model(img)
6
- pred = output[0].plot()
7
- pred = cv2.cvtColor(pred, cv2.COLOR_BGR2RGB)
8
- pred = Image.fromarray(pred)
9
- pred
 
 
 
 
 
 
 
 
 
 
 
 
 
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()