File size: 708 Bytes
920df70
9fb0182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920df70
 
9fb0182
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
import cv2

# Load your trained model
model = tf.keras.models.load_model("model_244.h5")

def predict_image(image):
    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})"

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