Update app.py
Browse files
app.py
CHANGED
@@ -5,32 +5,32 @@ import numpy as np
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
-
|
9 |
def perform(image):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
def load_model(model_name:str = "yolo11n.pt"):
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
# loading the model
|
36 |
model = load_model()
|
@@ -47,12 +47,5 @@ demo = gr.Interface(
|
|
47 |
|
48 |
# Launch the app
|
49 |
if __name__ == "__main__":
|
50 |
-
|
51 |
-
|
52 |
-
print(username, " ",password)
|
53 |
-
demo.launch(share=True,
|
54 |
-
ssr_mode=False,
|
55 |
-
server_name="0.0.0.0",
|
56 |
-
server_port=7860,
|
57 |
-
auth=(username, password)
|
58 |
-
)
|
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
|
|
8 |
def perform(image):
|
9 |
+
"""Perform the task of detection"""
|
10 |
+
# Predict with the model
|
11 |
+
results = model(image, save=True) # predict on an image
|
12 |
+
# get the saved prediction
|
13 |
+
prediction_image = Image.open(os.path.join(results[0].save_dir, os.listdir(results[0].save_dir)[0]))
|
14 |
+
# initialize the output list to save the bbox
|
15 |
+
outputs = []
|
16 |
+
# Access the results
|
17 |
+
for result in results[0]:
|
18 |
+
xywh = result.boxes.xyxy[0].numpy().tolist() # top-left-x, top-left-y, bottom-right-x, bottom-right-y
|
19 |
+
name = result.names[result.boxes.cls.item()] # classes
|
20 |
+
confs = float(result.boxes.conf) # confidence score of each box
|
21 |
+
outputs.append({"xywh":xywh ,"conf":confs, "name":name})
|
22 |
+
# return the image and the bbox
|
23 |
+
return prediction_image, outputs
|
24 |
|
25 |
+
def load_model(model_name: str = "yolo11n.pt"):
|
26 |
+
"""Model loading"""
|
27 |
+
try:
|
28 |
+
print(f"Loading the model {model_name}")
|
29 |
+
model = YOLO(model_name)
|
30 |
+
except Exception as e:
|
31 |
+
print(f"Error loading the model {e}")
|
32 |
+
return None
|
33 |
+
return model
|
34 |
|
35 |
# loading the model
|
36 |
model = load_model()
|
|
|
47 |
|
48 |
# Launch the app
|
49 |
if __name__ == "__main__":
|
50 |
+
|
51 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|