yoloKYS commited on
Commit
2a0fb5d
·
verified ·
1 Parent(s): d391b9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -1,15 +1,12 @@
 
 
 
1
  import gradio as gr
2
  from ultralytics import YOLO
3
- from PIL import Image
4
- import numpy as np
5
- import os
6
 
7
  # --- Load YOLOv12 model ---
8
  model_path = "best.pt"
9
- if os.path.exists(model_path):
10
- model = YOLO(model_path)
11
- else:
12
- model = None
13
 
14
  # --- Inference function ---
15
  def detect_ear(image: Image.Image, conf: float = 0.25):
@@ -21,9 +18,8 @@ def detect_ear(image: Image.Image, conf: float = 0.25):
21
  return Image.fromarray(annotated)
22
  except Exception as e:
23
  print(f"Model inference failed: {e}")
24
-
25
  # --- Dummy fallback ---
26
- import PIL.ImageDraw as ImageDraw
27
  im = image.copy()
28
  draw = ImageDraw.Draw(im)
29
  w, h = im.size
@@ -41,7 +37,7 @@ iface = gr.Interface(
41
  ],
42
  outputs=gr.Image(type="pil", label="Detection Result"),
43
  title="Automated Ear Disease Detection",
44
- description="Detect ear conditions using YOLOv12",
45
  )
46
 
47
  # --- Launch App ---
 
1
+ import os
2
+ import numpy as np
3
+ from PIL import Image, ImageDraw
4
  import gradio as gr
5
  from ultralytics import YOLO
 
 
 
6
 
7
  # --- Load YOLOv12 model ---
8
  model_path = "best.pt"
9
+ model = YOLO(model_path) if os.path.exists(model_path) else None
 
 
 
10
 
11
  # --- Inference function ---
12
  def detect_ear(image: Image.Image, conf: float = 0.25):
 
18
  return Image.fromarray(annotated)
19
  except Exception as e:
20
  print(f"Model inference failed: {e}")
21
+
22
  # --- Dummy fallback ---
 
23
  im = image.copy()
24
  draw = ImageDraw.Draw(im)
25
  w, h = im.size
 
37
  ],
38
  outputs=gr.Image(type="pil", label="Detection Result"),
39
  title="Automated Ear Disease Detection",
40
+ description="Detect ear conditions using YOLOv12. If the model fails to load, a dummy detection will be shown."
41
  )
42
 
43
  # --- Launch App ---