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()