| 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 |
|
|
| |
| torch.serialization.add_safe_globals([DetectionModel, nn.Sequential, Conv]) |
|
|
| |
| model = YOLO("res.pt") |
|
|
| |
| def predict(image): |
| |
| results = model.predict(source=image, conf=0.25) |
| |
| result_image = results[0].plot() |
| |
| return cv2.cvtColor(result_image, cv2.COLOR_BGR2RGB) |
|
|
| |
| 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() |
|
|