yoloKYS commited on
Commit
db7b04a
·
verified ·
1 Parent(s): 88ce75c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,17 +1,23 @@
1
  from ultralytics import YOLO
2
  import gradio as gr
3
  from PIL import Image
 
4
 
5
- # Load your trained YOLOv12 model from the repo
6
- model = YOLO("best.pt") # just the file name if it's in the same folder as app.py
7
 
8
- # Define prediction function
9
  def predict(image):
10
- results = model.predict(image) # Run inference
11
- annotated_img = results[0].plot() # Draw boxes on image
 
 
 
 
 
 
 
12
  return annotated_img
13
 
14
- # Gradio interface
15
  iface = gr.Interface(
16
  fn=predict,
17
  inputs=gr.Image(type="pil"),
@@ -20,5 +26,4 @@ iface = gr.Interface(
20
  description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
21
  )
22
 
23
- # Launch the app
24
  iface.launch()
 
1
  from ultralytics import YOLO
2
  import gradio as gr
3
  from PIL import Image
4
+ import numpy as np
5
 
6
+ # Load YOLOv12 model
7
+ model = YOLO("best.pt") # model in repo
8
 
 
9
  def predict(image):
10
+ # Ensure RGB and convert to NumPy array
11
+ image = image.convert("RGB")
12
+ img_array = np.array(image)
13
+
14
+ # Run inference
15
+ results = model.predict(img_array)
16
+
17
+ # Annotate and return
18
+ annotated_img = results[0].plot()
19
  return annotated_img
20
 
 
21
  iface = gr.Interface(
22
  fn=predict,
23
  inputs=gr.Image(type="pil"),
 
26
  description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
27
  )
28
 
 
29
  iface.launch()