Spaces:
Running
Running
vessel detection app
Browse files- app.py +31 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import cv2
|
| 5 |
+
|
| 6 |
+
# Download and load the model
|
| 7 |
+
repo_id = "truthdotphd/vessel-detection"
|
| 8 |
+
model_path = hf_hub_download(repo_id=repo_id, filename="model.pt")
|
| 9 |
+
model = YOLO(model_path)
|
| 10 |
+
|
| 11 |
+
def detect_vessels(image):
|
| 12 |
+
# Run inference
|
| 13 |
+
results = model(image)
|
| 14 |
+
|
| 15 |
+
# Plot results
|
| 16 |
+
annotated_image = results[0].plot()
|
| 17 |
+
return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
| 18 |
+
|
| 19 |
+
# Create Gradio interface
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=detect_vessels,
|
| 22 |
+
inputs=gr.Image(type="numpy"),
|
| 23 |
+
outputs=gr.Image(),
|
| 24 |
+
title="Maritime Vessel Detection",
|
| 25 |
+
description="Upload an image to detect vessels",
|
| 26 |
+
examples=[["vessels.jpg"]],
|
| 27 |
+
theme=gr.themes.Soft()
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Launch the app
|
| 31 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
ultralytics
|
| 3 |
+
huggingface_hub
|
| 4 |
+
opencv-python
|