Tejeshwar commited on
Commit
b456065
Β·
verified Β·
1 Parent(s): d1735aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import gradio as gr
2
  from PIL import Image
3
  import sys
4
- import os
5
 
6
- # πŸ‘‡ Add your custom YOLOv12 path to Python path
7
  sys.path.append("yolov12")
8
 
9
- # πŸ‘‡ Import your custom model loader
10
- from models.yolo import YOLO # adjust based on your repo
11
 
12
- model = YOLO("yolov12/best.pt")
 
13
 
14
  def detect_damage(image: Image.Image):
15
  results = model(image)
@@ -26,10 +26,12 @@ def detect_damage(image: Image.Image):
26
 
27
  return {"is_damaged": is_damaged}
28
 
29
- demo = gr.Interface(fn=detect_damage,
30
- inputs=gr.Image(type="pil"),
31
- outputs=gr.JSON(label="Detection Result"),
32
- title="🍎 Apple Damage Detector (YOLOv12)",
33
- description="Upload an image of an apple to check if it's damaged.")
 
 
34
 
35
  demo.launch()
 
1
  import gradio as gr
2
  from PIL import Image
3
  import sys
 
4
 
5
+ # Add yolov12 to Python path
6
  sys.path.append("yolov12")
7
 
8
+ # Correct import from yolov12 repo
9
+ from yolov12.models.yolo import YOLO
10
 
11
+ # βœ… Correct path to the actual weights file
12
+ model = YOLO("yolov12/runs/detect/train7/weights/best.pt")
13
 
14
  def detect_damage(image: Image.Image):
15
  results = model(image)
 
26
 
27
  return {"is_damaged": is_damaged}
28
 
29
+ demo = gr.Interface(
30
+ fn=detect_damage,
31
+ inputs=gr.Image(type="pil"),
32
+ outputs=gr.JSON(label="Detection Result"),
33
+ title="🍎 Apple Damage Detector (YOLOv12)",
34
+ description="Upload an image of an apple to check if it's damaged using your custom YOLOv12 model."
35
+ )
36
 
37
  demo.launch()