yoloKYS commited on
Commit
6590ce7
·
verified ·
1 Parent(s): 3797ab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -28
app.py CHANGED
@@ -1,37 +1,24 @@
1
- import gradio as gr
2
  from ultralytics import YOLO
3
- from PIL import Image, ImageDraw
4
- import numpy as np
5
- import torch
6
 
7
- # Load your existing YOLOv12 model
8
- model = YOLO("best.pt")
9
- model.to('cpu') # force CPU
10
 
11
- # Inference function
12
- def detect_ear(image: Image.Image, conf: float = 0.25):
13
- try:
14
- img_array = np.array(image)
15
- results = model(img_array, conf=conf, verbose=False)
16
- annotated = results[0].plot()
17
- return Image.fromarray(annotated)
18
- except Exception as e:
19
- # Show error text on image
20
- im = image.copy()
21
- draw = ImageDraw.Draw(im)
22
- draw.text((10, 10), f"Error: {e}", fill="red")
23
- return im
24
 
25
  # Gradio interface
26
  iface = gr.Interface(
27
- fn=detect_ear,
28
- inputs=[
29
- gr.Image(type="pil", label="Upload Otoscopic Image"),
30
- gr.Slider(0.0, 1.0, value=0.25, step=0.01, label="Confidence Threshold")
31
- ],
32
- outputs=gr.Image(type="pil", label="Detection Result"),
33
- title="Automated Ear Disease Detection",
34
- description="Detect ear conditions using YOLOv12 (CPU only)"
35
  )
36
 
 
37
  iface.launch()
 
 
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"),
18
+ outputs=gr.Image(type="pil"),
19
+ title="Ear Condition Detection",
20
+ description="Upload an otoscopic image and get predictions from the trained YOLOv12 model."
 
 
 
21
  )
22
 
23
+ # Launch the app
24
  iface.launch()