tykimos commited on
Commit
6e740d7
โ€ข
1 Parent(s): 32cd363

Add application file

Browse files
Files changed (1) hide show
  1. app.py +57 -0
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
+