Spaces:
Sleeping
Sleeping
File size: 1,449 Bytes
2110d28 a783876 2ffb4ff b8737c1 55802c4 a783876 4f65fb5 5838ad2 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 086042c 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 72d8d64 4f65fb5 044c5e1 72d8d64 4f65fb5 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import torch
import yaml
import numpy as np
from PIL import Image
from roboflow import Roboflow
from ultralytics import YOLO
# Initialize Roboflow
rf = Roboflow(api_key="K1TXQnJq7EE7yoCf1g3C")
project = rf.workspace().project("bone-fracture-detection-rkuqr")
model = project.version("3").model
def load_model():
# Load the model from Roboflow
yolov8_model = model.deploy()
return yolov8_model
def predict_fracture(image_path):
# Load the model
yolov8_model = load_model()
# Open the image
image = Image.open(image_path)
# Perform inference
results = yolov8_model.predict(image_path, confidence=40, overlap=30)
# Display the results on the image
img_with_boxes = image.copy()
for box in results["objects"]:
label = box["class"]
score = box["score"]
if label == "fracture":
color = "red"
xmin, ymin, xmax, ymax = box["bbox"]
img_with_boxes.rectangle([xmin, ymin, xmax, ymax], outline=color, width=2)
img_with_boxes.text((xmin, ymin), f"Fracture: {score:.2f}", font_size=12, color=color)
return img_with_boxes
# Gradio Interface
iface = gr.Interface(
predict_fracture,
inputs=gr.Image(),
outputs=gr.Image(),
live=True,
#capture_session=True,
title="Bone Fracture Detection",
description="Upload an X-ray image to detect bone fractures using YOLOv8.",
)
iface.launch()
|