File size: 1,308 Bytes
c248fdd
f92619f
0cf817c
a0a6970
02a005d
a0a6970
f92619f
0cf817c
980e3d0
f92619f
02a005d
980e3d0
f92619f
1d1682a
980e3d0
f92619f
 
 
 
 
 
 
 
0cf817c
f92619f
 
 
 
 
980e3d0
6fa32dd
 
 
8082eee
 
6fa32dd
980e3d0
 
6fa32dd
f92619f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import torch
import ultralytics
from ultralytics import YOLO
from ultralytics.nn.tasks import DetectionModel
from ultralytics.nn.modules.conv import Conv
import torch.nn as nn
import cv2
import gradio as gr

# ---- FIX for PyTorch 2.6+ ----
torch.serialization.add_safe_globals([DetectionModel, nn.Sequential, Conv])

# ---- Load trained YOLO model ----
model = YOLO("res.pt")  # Ensure your model file is in the same folder

# ---- Prediction function ----
def predict(image):
    # Run inference
    results = model.predict(source=image, conf=0.25)
    # Draw boxes on the image
    result_image = results[0].plot()
    # Convert BGR → RGB for Gradio
    return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB)

# ---- Gradio Interface ----
iface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="filepath", label="Upload Bone X-ray"),
    outputs=gr.Image(type="numpy", label="Detection Result"),
    title="Human Bone Fracture Detection",
    description=(
        "Upload an X-ray image to detect human bone fractures using YOLOv8.<br><br>"
        "📸 **Dataset Source:** "
        "<a href='https://www.kaggle.com/datasets/jockeroika/human-bone-fractures-image-dataset' target='_blank'>"
        "Human Bone Fractures Image Dataset</a>"
    )
)

if __name__ == '__main__':
    iface.launch()