Spaces:
Runtime error
Runtime error
tykimos
commited on
Commit
ยท
6e740d7
1
Parent(s):
32cd363
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""Untitled200.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1XlVHPlSeue0mvagDZOzdk_wHjLmNlWM1
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
#!pip install ultralytics
|
| 11 |
+
#!pip install requests
|
| 12 |
+
#!pip install pillow
|
| 13 |
+
|
| 14 |
+
from ultralytics import YOLO
|
| 15 |
+
|
| 16 |
+
# ๋ชจ๋ธ ๋ก๋
|
| 17 |
+
model = YOLO("ship.pt") # ํ์ต๋ ๋ชจ๋ธ ํ์ผ์ ๋ก๋
|
| 18 |
+
|
| 19 |
+
# ์ด๋ฏธ์ง ์ถ๋ก
|
| 20 |
+
results = model("images.jpeg") # ์ด๋ฏธ์ง ํ์ผ๋ก ์ถ๋ก ์ํ
|
| 21 |
+
|
| 22 |
+
# ๊ฒฐ๊ณผ ์๊ฐํ
|
| 23 |
+
results[0].show() # ์ฒซ ๋ฒ์งธ ๊ฒฐ๊ณผ๋ฅผ ์๊ฐ์ ์ผ๋ก ํ์
|
| 24 |
+
|
| 25 |
+
#!pip install gradio
|
| 26 |
+
|
| 27 |
+
import gradio as gr
|
| 28 |
+
from ultralytics import YOLO
|
| 29 |
+
|
| 30 |
+
# 1. ๋ชจ๋ธ ์ด๊ธฐํ
|
| 31 |
+
model = YOLO("ship.pt")
|
| 32 |
+
|
| 33 |
+
# 2. ์ถ๋ก ํจ์
|
| 34 |
+
def detect_ship(input_image: str):
|
| 35 |
+
results = model(input_image)
|
| 36 |
+
return results[0].plot()[:, :, ::-1] # BGR to RGB ๋ณํ
|
| 37 |
+
|
| 38 |
+
# 3. Gradio UI
|
| 39 |
+
with gr.Blocks() as demo:
|
| 40 |
+
with gr.Row():
|
| 41 |
+
gr.Markdown("## Ship Detection")
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
input_image = gr.Image(label="Input Image", type="filepath")
|
| 45 |
+
output_image = gr.Image(label="Output", type="numpy")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
inference_btn = gr.Button("Inference")
|
| 49 |
+
|
| 50 |
+
inference_btn.click(fn=detect_ship, inputs=input_image, outputs=output_image)
|
| 51 |
+
|
| 52 |
+
# 4. Gradio ์คํ
|
| 53 |
+
demo.launch(inline=False)
|
| 54 |
+
|
| 55 |
+
# 5. Gradio ์ข
๋ฃ
|
| 56 |
+
demo.close()
|
| 57 |
+
|