bfd-rg / README.md
3dredstone's picture
Update README.md
037bfd7 verified

A newer version of the Gradio SDK is available: 5.42.0

Upgrade
metadata
title: bfd-rg
sdk: gradio
emoji: πŸƒ
colorFrom: green
colorTo: yellow
pinned: false

Add a heading.png

Bone-Fracture-Detection

Bone-Fracture-Detection is a binary image classification model based on google/siglip2-base-patch16-224, trained to detect fractures in bone X-ray images. It is designed for use in medical diagnostics, clinical triage, and radiology assistance systems.

Classification Report:
               precision    recall  f1-score   support

    Fractured     0.8633    0.7893    0.8246      4480
Not Fractured     0.8020    0.8722    0.8356      4383

     accuracy                         0.8303      8863
    macro avg     0.8326    0.8308    0.8301      8863
 weighted avg     0.8330    0.8303    0.8301      8863

download.png


Label Classes

The model distinguishes between the following bone conditions:

0: Fractured  
1: Not Fractured

Installation

pip install transformers torch pillow gradio

Example Inference Code

import gradio as gr
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import torch

# Load model and processor from the Hugging Face Hub
model_name = "prithivMLmods/Bone-Fracture-Detection"
model = AutoModelForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)

def detect_fracture(image):
    """
    Takes a NumPy image array, processes it, and returns the model's prediction.
    """
    # Convert NumPy array to a PIL Image
    image = Image.fromarray(image).convert("RGB")
    
    # Process the image and prepare it as input for the model
    inputs = processor(images=image, return_tensors="pt")

    # Perform inference without calculating gradients
    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        
        # Apply softmax to get probabilities and convert to a list
        probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()

    # Create a dictionary of labels and their corresponding probabilities
    # This now correctly uses the labels from the model's configuration
    prediction = {model.config.id2label[i]: round(probs[i], 3) for i in range(len(probs))}
    
    return prediction

# Create the Gradio Interface
iface = gr.Interface(
    fn=detect_fracture,
    inputs=gr.Image(type="numpy", label="Upload Bone X-ray"),
    outputs=gr.Label(num_top_classes=2, label="Detection Result"),
    title="πŸ”¬ Bone Fracture Detection",
    description="Upload a bone X-ray image to detect if there is a fracture. The model will return the probability for 'Fractured' and 'Not Fractured'.",
    examples=[
        ["fractured_example.png"],
        ["not_fractured_example.png"]
    ] # Note: You would need to have these image files in the same directory for the examples to work.
)

# Launch the app
if __name__ == "__main__":
    iface.launch()

Applications

  • Orthopedic Diagnostic Support
  • Emergency Room Triage
  • Automated Radiology Review
  • Clinical Research in Bone Health