Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920212223242526import gradio as grfrom ultralytics import YOLOimport cv2import torchtorch.serialization.add_safe_globals([DetectionModel])# Load your YOLOv8 modelmodel = YOLO("best.pt")# Prediction functiondef detect_fracture(image):results = model.predict(source=image, save=False) # Run inferenceannotated_img = results[0].plot() # Draw detectionsreturn annotated_img# Gradio interfacedemo = gr.Interface(fn=detect_fracture,inputs=gr.Image(type="numpy", 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 types of human bone fractures using YOLOv8.")if __name__ == "__main__":12345678910111213141516171819202122232425262728293031323334353637383940import torchfrom ultralytics import YOLOfrom ultralytics.nn.tasks import DetectionModel # ✅ Correct import for PyTorch 2.6 fiximport gradio as gr# Fix for PyTorch 2.6 safe loadingtorch.serialization.add_safe_globals([DetectionModel])# Load YOLOv8 modelmodel = YOLO("best.pt")# Detection functiondef detect_fracture(image):# Run detectionresults = model.predict(source=image, save=False)annotated_img = results[0].plot() # Annotated image with bounding boxes# Extract labels & confidence scoresdetections = []for box in results[0].boxes:cls_id = int(box.cls[0])label = model.names[cls_id]conf = float(box.conf[0])detections.append(f"{label}: {conf:.2f}")return annotated_img, "\n".join(detections) if detections else "No fracture detected"# Gradio appdemo = gr.Interface(fn=detect_fracture,inputs=gr.Image(type="numpy", label="Upload Bone X-ray"),outputs=[gr.Image(type="numpy", label="Detection Result"),gr.Textbox(label="Detected Fractures & Confidence Scores")],title="Human Bone Fracture Detection",description="Upload an X-ray image to detect types of human bone fractures using a YOLOv8 model.")if __name__ == "__main__":
app.py+25-11