Spaces:
Sleeping
Sleeping
File size: 1,069 Bytes
4755bf8 |
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 |
import gradio as gr
from ultralytics import YOLO
import cv2
import numpy as np
# Load the YOLOv8 model
model = YOLO("yolov8n.pt") # Replace with your trained brain tumor model
def predict(image_path):
# Run YOLOv8 inference
results = model(image_path)
# Get annotated image
annotated_frame = results[0].plot()
# Convert BGR to RGB
annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
# Check if a tumor is detected
tumor_detected = len(results[0].boxes) > 0
detection_message = "Tumor Detected!" if tumor_detected else "No Tumor Detected."
return annotated_frame_rgb, detection_message
# Create Gradio interface
interface = gr.Interface(
fn=predict,
inputs=gr.Image(type="filepath", label="Upload MRI Image"),
outputs=[
gr.Image(label="Detection Result"),
gr.Textbox(label="Diagnosis")
],
title="Brain Tumor Detection with YOLOv8",
description="Upload an MRI scan to detect brain tumors using AI.",
allow_flagging="never"
)
interface.launch() |