ship_detection / app.py
tykimos's picture
Update app.py
5ea63cd verified
# -*- coding: utf-8 -*-
"""Untitled200.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1XlVHPlSeue0mvagDZOzdk_wHjLmNlWM1
"""
#!pip install ultralytics
#!pip install requests
#!pip install pillow
from ultralytics import YOLO
# ๋ชจ๋ธ ๋กœ๋“œ
model = YOLO("ship.pt") # ํ•™์Šต๋œ ๋ชจ๋ธ ํŒŒ์ผ์„ ๋กœ๋“œ
# ์ด๋ฏธ์ง€ ์ถ”๋ก 
results = model("images.jpeg") # ์ด๋ฏธ์ง€ ํŒŒ์ผ๋กœ ์ถ”๋ก  ์ˆ˜ํ–‰
# ๊ฒฐ๊ณผ ์‹œ๊ฐํ™”
results[0].show() # ์ฒซ ๋ฒˆ์งธ ๊ฒฐ๊ณผ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œ์‹œ
#!pip install gradio
import gradio as gr
from ultralytics import YOLO
# 1. ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
model = YOLO("ship.pt")
# 2. ์ถ”๋ก  ํ•จ์ˆ˜
def detect_ship(input_image: str):
results = model(input_image)
return results[0].plot()[:, :, ::-1] # BGR to RGB ๋ณ€ํ™˜
# 3. Gradio UI
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown("## Ship Detection")
with gr.Row():
input_image = gr.Image(label="Input Image", type="filepath")
output_image = gr.Image(label="Output", type="numpy")
with gr.Row():
inference_btn = gr.Button("Inference")
inference_btn.click(fn=detect_ship, inputs=input_image, outputs=output_image)
# 4. Gradio ์‹คํ–‰
demo.launch(inline=False)