Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ultralytics import YOLO
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the YOLOv8 model
|
7 |
+
model = YOLO("yolov8n.pt") # Replace with your trained brain tumor model
|
8 |
+
|
9 |
+
def predict(image_path):
|
10 |
+
# Run YOLOv8 inference
|
11 |
+
results = model(image_path)
|
12 |
+
|
13 |
+
# Get annotated image
|
14 |
+
annotated_frame = results[0].plot()
|
15 |
+
|
16 |
+
# Convert BGR to RGB
|
17 |
+
annotated_frame_rgb = cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)
|
18 |
+
|
19 |
+
# Check if a tumor is detected
|
20 |
+
tumor_detected = len(results[0].boxes) > 0
|
21 |
+
detection_message = "Tumor Detected!" if tumor_detected else "No Tumor Detected."
|
22 |
+
|
23 |
+
return annotated_frame_rgb, detection_message
|
24 |
+
|
25 |
+
# Create Gradio interface
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=gr.Image(type="filepath", label="Upload MRI Image"),
|
29 |
+
outputs=[
|
30 |
+
gr.Image(label="Detection Result"),
|
31 |
+
gr.Textbox(label="Diagnosis")
|
32 |
+
],
|
33 |
+
title="Brain Tumor Detection with YOLOv8",
|
34 |
+
description="Upload an MRI scan to detect brain tumors using AI.",
|
35 |
+
allow_flagging="never"
|
36 |
+
)
|
37 |
+
|
38 |
+
interface.launch()
|