File size: 796 Bytes
ddc7f6c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()