File size: 778 Bytes
4f7f7d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
import cv2

# Download and load the model
repo_id = "truthdotphd/vessel-detection"
model_path = hf_hub_download(repo_id=repo_id, filename="model.pt")
model = YOLO(model_path)

def detect_vessels(image):
    # Run inference
    results = model(image)

    # Plot results
    annotated_image = results[0].plot()
    return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)

# Create Gradio interface
demo = gr.Interface(
    fn=detect_vessels,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Image(),
    title="Maritime Vessel Detection",
    description="Upload an image to detect vessels",
    examples=[["vessels.jpg"]],
    theme=gr.themes.Soft()
)

# Launch the app
demo.launch()