yoloKYS commited on
Commit
944dab1
·
verified ·
1 Parent(s): 4129d0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -4,30 +4,32 @@ from PIL import Image
4
  import numpy as np
5
  import sys, os
6
 
7
- # ---- Add forked YOLOv12 code to Python path ----
8
  fork_ultra_path = os.path.join(os.path.dirname(__file__), "yolov12-main", "yolov12-main")
9
  sys.path.insert(0, fork_ultra_path)
10
 
11
- # ---- Now import YOLO from the fork, not from pip ----
12
  from ultralytics import YOLO
13
 
14
- # ---- Load the trained model ----
15
- model = YOLO("best.pt")
 
16
 
17
- # ---- Inference function ----
18
  def detect_objects(image):
19
  img = np.array(image)
20
  results = model(img)
21
  annotated = results[0].plot()
22
  return Image.fromarray(annotated)
23
 
24
- # ---- Gradio UI ----
25
- iface = gr.Interface(
26
  fn=detect_objects,
27
- inputs=gr.Image(type="pil"),
28
- outputs=gr.Image(type="pil"),
29
- title="Ear Condition Detection (YOLOv12 Fork)",
30
- description="Runs inference using the sunsmarterjie YOLOv12 fork."
31
  )
32
 
33
- iface.launch()
 
 
4
  import numpy as np
5
  import sys, os
6
 
7
+ # ---- Add YOLOv12 code to Python path ----
8
  fork_ultra_path = os.path.join(os.path.dirname(__file__), "yolov12-main", "yolov12-main")
9
  sys.path.insert(0, fork_ultra_path)
10
 
11
+ # ---- Import YOLO ----
12
  from ultralytics import YOLO
13
 
14
+ # ---- Load trained model ----
15
+ model_path = os.path.join(os.path.dirname(__file__), "best.pt")
16
+ model = YOLO(model_path)
17
 
18
+ # ---- Detection function ----
19
  def detect_objects(image):
20
  img = np.array(image)
21
  results = model(img)
22
  annotated = results[0].plot()
23
  return Image.fromarray(annotated)
24
 
25
+ # ---- Gradio Interface ----
26
+ demo = gr.Interface(
27
  fn=detect_objects,
28
+ inputs=gr.Image(type="pil", label="Upload an Ear Image"),
29
+ outputs=gr.Image(type="pil", label="Detection Result"),
30
+ title="Ear Condition Detection",
31
+ description="Upload an ear image to detect possible conditions using the trained YOLOv12 model."
32
  )
33
 
34
+ if __name__ == "__main__":
35
+ demo.launch(server_name="0.0.0.0", server_port=7860)