Tejeshwar commited on
Commit
81e9e78
·
verified ·
1 Parent(s): d333e06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,20 +1,21 @@
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)
16
- is_damaged = False
17
 
 
18
  for result in results:
19
  for box in result.boxes:
20
  class_id = int(box.cls[0])
@@ -31,7 +32,7 @@ demo = gr.Interface(
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()
 
1
  import gradio as gr
2
  from PIL import Image
3
+ import os
4
  import sys
5
 
6
+ # Make yolov12 folder importable
7
+ sys.path.append(os.path.abspath("yolov12"))
8
 
9
+ # Import your YOLO class
10
+ from yolo import YOLO # Now from yolov12/yolo.py
11
 
12
+ # Load your custom YOLOv12 model
13
+ model = YOLO("yolov12/best.pt")
14
 
15
  def detect_damage(image: Image.Image):
16
  results = model(image)
 
17
 
18
+ is_damaged = False
19
  for result in results:
20
  for box in result.boxes:
21
  class_id = int(box.cls[0])
 
32
  inputs=gr.Image(type="pil"),
33
  outputs=gr.JSON(label="Detection Result"),
34
  title="🍎 Apple Damage Detector (YOLOv12)",
35
+ description="Upload an image of an apple to detect if it's damaged."
36
  )
37
 
38
  demo.launch()