Song commited on
Commit
7b3f280
·
1 Parent(s): 1e7b2ff
Files changed (2) hide show
  1. app.py +19 -8
  2. best0709.pt → best0715.pt +2 -2
app.py CHANGED
@@ -1,12 +1,23 @@
1
- import torch
2
- from ultralytics import YOLO
3
  import gradio as gr
 
 
 
 
4
 
5
- model = YOLO("best0709.pt") # 或者是從 hf_hub_download 取得
 
 
 
 
 
 
6
 
7
- def detect(image):
8
- results = model(image)
9
- return results[0].plot() # 回傳帶框圖像
 
 
 
 
10
 
11
- iface = gr.Interface(fn=detect, inputs="image", outputs="image")
12
- iface.launch(show_api=True)
 
 
 
1
  import gradio as gr
2
+ from ultralytics import YOLO
3
+ import torch
4
+
5
+ model = YOLO("best0715.pt")
6
 
7
+ def detect(image, conf_threshold=0.3):
8
+ results = model(image, conf=conf_threshold)
9
+ if len(results) == 0 or results[0].boxes is None or len(results[0].boxes) == 0:
10
+ return image, "No bear detected."
11
+ plotted = results[0].plot()
12
+ conf = results[0].boxes.conf[0].item()
13
+ return plotted, f"Detected bear with confidence {conf:.2f}"
14
 
15
+ iface = gr.Interface(
16
+ fn=detect,
17
+ inputs=[gr.Image(type="pil"), gr.Slider(0.1, 0.9, value=0.3, label="Confidence Threshold")],
18
+ outputs=[gr.Image(), gr.Textbox()],
19
+ title="Taiwanese Black Bear Detector",
20
+ description="Upload an image for detection."
21
+ )
22
 
23
+ iface.launch(share=True)
 
best0709.pt → best0715.pt RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1fb10d8bcd3c4556db7ccd050d39fceaea9fd8f56ec988ca2471bd27354633aa
3
- size 22525539
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06e2747470091835b8bfd96a083be14c5f6d9edea180fddb68a65563f39d50ef
3
+ size 22513955