Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
import spaces
|
|
|
|
| 4 |
|
| 5 |
# Load pre-trained YOLOv8 model
|
| 6 |
model = YOLO("yolov8x-doclaynet-epoch64-imgsz640-initiallr1e-4-finallr1e-5.pt")
|
|
@@ -8,8 +9,7 @@ model = YOLO("yolov8x-doclaynet-epoch64-imgsz640-initiallr1e-4-finallr1e-5.pt")
|
|
| 8 |
# Get class names from model
|
| 9 |
class_names = model.names
|
| 10 |
|
| 11 |
-
|
| 12 |
-
@spaces.GPU(duration=60)
|
| 13 |
def process_image(image):
|
| 14 |
try:
|
| 15 |
# Process the image
|
|
@@ -19,10 +19,10 @@ def process_image(image):
|
|
| 19 |
# Extract annotated image and labels with class names
|
| 20 |
annotated_image = result.plot()
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
detected_areas_labels = "\n".join(
|
| 24 |
-
|
| 25 |
-
)
|
| 26 |
|
| 27 |
return annotated_image, detected_areas_labels
|
| 28 |
except Exception as e:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
import spaces
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
# Load pre-trained YOLOv8 model
|
| 7 |
model = YOLO("yolov8x-doclaynet-epoch64-imgsz640-initiallr1e-4-finallr1e-5.pt")
|
|
|
|
| 9 |
# Get class names from model
|
| 10 |
class_names = model.names
|
| 11 |
|
| 12 |
+
@spaces.GPU(duration=60)
|
|
|
|
| 13 |
def process_image(image):
|
| 14 |
try:
|
| 15 |
# Process the image
|
|
|
|
| 19 |
# Extract annotated image and labels with class names
|
| 20 |
annotated_image = result.plot()
|
| 21 |
|
| 22 |
+
# Convert box.cls tensor to float before formatting
|
| 23 |
+
detected_areas_labels = "\n".join([
|
| 24 |
+
f"{class_names[int(box.cls.item())].upper()}: {box.conf:.2f}" for box in result.boxes
|
| 25 |
+
])
|
| 26 |
|
| 27 |
return annotated_image, detected_areas_labels
|
| 28 |
except Exception as e:
|