# -*- 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) # 5. Gradio 종료 demo.close()