Spaces:
Sleeping
Sleeping
File size: 1,089 Bytes
eb6c18c |
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 |
import gradio as gr
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
from utils.preprocessing import preprocess_image
model = load_model("model/tumor_classifier.h5")
def predict_tumor(image, report):
if image is None and not report.strip():
return "β Please upload an image or enter a report."
response = ""
if image:
img_array = preprocess_image(image)
prediction = model.predict(img_array)[0][0]
response += "π§ Tumor detected." if prediction > 0.5 else "β
No tumor detected."
if report.strip():
response += f"\n\nπ Notes:\n{report.strip()}"
return response
iface = gr.Interface(
fn=predict_tumor,
inputs=[
gr.Image(type="pil", label="Upload MRI/CT Scan"),
gr.Textbox(lines=3, label="Optional Medical Report")
],
outputs="text",
title="π§ Brain Tumor Detection Assistant",
description="Upload a scan and/or enter a report to detect brain tumor."
)
if __name__ == "__main__":
iface.launch()
|