kbarnard commited on
Commit
f86c51f
·
1 Parent(s): 1042523

add initial app

Browse files
Files changed (3) hide show
  1. README.md +1 -3
  2. app.py +54 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Community Fish Detector
3
- emoji: 😻
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
@@ -10,5 +10,3 @@ pinned: false
10
  license: agpl-3.0
11
  short_description: WildHackers Community Fish Detector (CFD)
12
  ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Community Fish Detector
3
+ emoji: 🐟
4
  colorFrom: blue
5
  colorTo: gray
6
  sdk: gradio
 
10
  license: agpl-3.0
11
  short_description: WildHackers Community Fish Detector (CFD)
12
  ---
 
 
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from ultralytics import YOLO
4
+ import os
5
+
6
+ REPO_URL = "https://github.com/WildHackers/community-fish-detector"
7
+ MODEL_URL = REPO_URL + "/releases/download/cfd-1.00-yolov12x/cfd-yolov12x-1.00.pt"
8
+
9
+ # Download model once
10
+ MODEL_PATH = os.path.basename(MODEL_URL)
11
+ if not os.path.exists(MODEL_PATH):
12
+ torch.hub.download_url_to_file(MODEL_URL, MODEL_PATH)
13
+
14
+ # Load YOLOv12x model
15
+ model = YOLO(MODEL_PATH)
16
+
17
+ def run_detection(input_image, conf_threshold=0.60, iou_threshold=0.45, imgsz=640):
18
+ """
19
+ Runs YOLOv12x inference on an image.
20
+ Returns annotated image result.
21
+ """
22
+ if input_image is None:
23
+ return None
24
+
25
+ results = model.predict(
26
+ source=input_image,
27
+ conf=conf_threshold,
28
+ iou=iou_threshold,
29
+ imgsz=imgsz,
30
+ save=False,
31
+ verbose=False
32
+ )
33
+
34
+ return results[0].plot()
35
+
36
+ # Gradio interface
37
+ demo = gr.Interface(
38
+ fn=run_detection,
39
+ inputs=[
40
+ gr.Image(type="numpy", label="Input Image"),
41
+ gr.Slider(0, 1, value=0.60, step=0.01, label="Confidence Threshold"),
42
+ gr.Slider(0, 1, value=0.45, step=0.01, label="IoU Threshold"),
43
+ gr.Slider(320, 1280, value=640, step=32, label="Image Size"),
44
+ ],
45
+ outputs=gr.Image(type="numpy", label="Detected Output"),
46
+ title="Community Fish Detector (YOLOv12x)",
47
+ description=(
48
+ f"Upload an image or video to detect fish using the [Community Fish Detector]({REPO_URL})."
49
+ ),
50
+ flagging_mode="never",
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ ultralytics>=8.3.0
2
+ torch