Spaces:
Sleeping
Sleeping
Varun
commited on
Commit
·
c3d5a86
1
Parent(s):
63bef64
Update app.py to download YOLOv8 model using Hugging Face token and adjust description text. Clean up requirements.txt by removing unnecessary dependencies.
Browse files- app.py +11 -6
- requirements.txt +1 -3
app.py
CHANGED
@@ -1,16 +1,21 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from ultralytics import YOLO
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
7 |
)
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
def detect_objects(image):
|
11 |
results = model(image)
|
12 |
-
|
13 |
-
return annotated_image
|
14 |
|
15 |
|
16 |
demo = gr.Interface(
|
@@ -18,7 +23,7 @@ demo = gr.Interface(
|
|
18 |
inputs=gr.Image(type="pil"),
|
19 |
outputs=gr.Image(type="numpy"),
|
20 |
title="Object Detection",
|
21 |
-
description="Upload an image
|
22 |
)
|
23 |
|
24 |
if __name__ == "__main__":
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
from ultralytics import YOLO
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
|
6 |
+
# Download private model using HF token from secret
|
7 |
+
hf_token = os.environ.get("HF_TOKEN")
|
8 |
+
model_path = hf_hub_download(
|
9 |
+
repo_id="Lookingsoft-team/object_detection", filename="yolov8n.pt", token=hf_token
|
10 |
)
|
11 |
|
12 |
+
# Load model
|
13 |
+
model = YOLO(model_path)
|
14 |
+
|
15 |
|
16 |
def detect_objects(image):
|
17 |
results = model(image)
|
18 |
+
return results[0].plot()
|
|
|
19 |
|
20 |
|
21 |
demo = gr.Interface(
|
|
|
23 |
inputs=gr.Image(type="pil"),
|
24 |
outputs=gr.Image(type="numpy"),
|
25 |
title="Object Detection",
|
26 |
+
description="Upload an image to detect objects.",
|
27 |
)
|
28 |
|
29 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
gradio>=5.32.1
|
2 |
ultralytics
|
3 |
-
|
4 |
-
numpy
|
5 |
-
Pillow
|
|
|
1 |
gradio>=5.32.1
|
2 |
ultralytics
|
3 |
+
huggingface_hub
|
|
|
|