yoloKYS commited on
Commit
1a47aa3
·
verified ·
1 Parent(s): 00d949a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -1,20 +1,17 @@
1
  import gradio as gr
2
  import torch
3
- from ultralytics import YOLO
4
  from PIL import Image
5
  import numpy as np
6
  import sys, os
7
 
8
- # ---- Add yolov12 fork folder to path ----
9
- sys.path.append(os.path.join(os.path.dirname(__file__), "yolov12-main"))
10
 
11
- # ---- Import forked Attn and patch YOLO ----
12
- from yolov12.models.modules.attn import Attn # inside yolov12-main
13
- import ultralytics.nn.modules.block as block
14
- block.AAttn = Attn # replace original AAttn
15
 
16
- # ---- Load model ----
17
- model = YOLO("best.pt") # make sure best.pt is in same folder
18
 
19
  # ---- Inference function ----
20
  def detect_objects(image):
@@ -23,13 +20,13 @@ def detect_objects(image):
23
  annotated = results[0].plot()
24
  return Image.fromarray(annotated)
25
 
26
- # ---- Gradio interface ----
27
  iface = gr.Interface(
28
  fn=detect_objects,
29
  inputs=gr.Image(type="pil"),
30
  outputs=gr.Image(type="pil"),
31
  title="Ear Condition Detection (YOLOv12 Fork)",
32
- description="Uses forked YOLOv12 model to detect ear conditions."
33
  )
34
 
35
  iface.launch()
 
1
  import gradio as gr
2
  import torch
 
3
  from PIL import Image
4
  import numpy as np
5
  import sys, os
6
 
7
+ # ---- Add forked YOLOv12 code to Python path ----
8
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "yolov12-main"))
9
 
10
+ # ---- Now import YOLO from the fork, not from pip ----
11
+ from ultralytics import YOLO
 
 
12
 
13
+ # ---- Load the trained model ----
14
+ model = YOLO("best.pt")
15
 
16
  # ---- Inference function ----
17
  def detect_objects(image):
 
20
  annotated = results[0].plot()
21
  return Image.fromarray(annotated)
22
 
23
+ # ---- Gradio UI ----
24
  iface = gr.Interface(
25
  fn=detect_objects,
26
  inputs=gr.Image(type="pil"),
27
  outputs=gr.Image(type="pil"),
28
  title="Ear Condition Detection (YOLOv12 Fork)",
29
+ description="Runs inference using the sunsmarterjie YOLOv12 fork."
30
  )
31
 
32
  iface.launch()