Spaces:
Runtime error
Runtime error
| # -*- 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) |