shivakumar4147's picture
Update app.py
ddc7f6c verified
raw
history blame contribute delete
796 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
import cv2
# Load model (make sure final_model.h5 is in the same folder)
model = tf.keras.models.load_model("final_model.h5")
def predict_image(image):
# Resize to 244x244
img = cv2.resize(image, (244, 244))
img = img.astype(np.float32) / 255.0
img = np.expand_dims(img, axis=0)
p = model.predict(img)[0][0]
risk = "High" if p > 0.7 else "Medium" if p > 0.4 else "Low"
return f"Risk: {risk} (Probability: {p:.3f})"
# Create Gradio interface
iface = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="numpy"),
outputs="text",
title="Cancer Risk Detector (244×244)",
description="Upload an image to get a cancer risk prediction."
)
if __name__ == "__main__":
iface.launch()