shivakumar4147 commited on
Commit
ddc7f6c
·
verified ·
1 Parent(s): a43c12c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
app.py CHANGED
@@ -1,28 +1,29 @@
1
- import gradio as gr
2
- import tensorflow as tf
3
- import numpy as np
4
- import cv2
5
-
6
- # Load model
7
- model = tf.keras.models.load_model("model_244.h5")
8
-
9
- def predict_image(image):
10
- # Resize to 244x244
11
- img = cv2.resize(image, (244, 244))
12
- img = img.astype(np.float32) / 255.0
13
- img = np.expand_dims(img, axis=0)
14
- p = model.predict(img)[0][0]
15
- risk = "High" if p > 0.7 else "Medium" if p > 0.4 else "Low"
16
- return f"Risk: {risk} (Probability: {p:.3f})"
17
-
18
- # Gradio interface
19
- iface = gr.Interface(
20
- fn=predict_image,
21
- inputs=gr.Image(type="numpy"),
22
- outputs="text",
23
- title="Cancer Risk Detector (244×244)",
24
- description="Upload an image to get a cancer risk prediction."
25
- )
26
-
27
- if __name__ == "__main__":
28
- iface.launch()
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import cv2
5
+
6
+ # Load model (make sure final_model.h5 is in the same folder)
7
+ model = tf.keras.models.load_model("final_model.h5")
8
+
9
+ def predict_image(image):
10
+ # Resize to 244x244
11
+ img = cv2.resize(image, (244, 244))
12
+ img = img.astype(np.float32) / 255.0
13
+ img = np.expand_dims(img, axis=0)
14
+ p = model.predict(img)[0][0]
15
+ risk = "High" if p > 0.7 else "Medium" if p > 0.4 else "Low"
16
+ return f"Risk: {risk} (Probability: {p:.3f})"
17
+
18
+ # Create Gradio interface
19
+ iface = gr.Interface(
20
+ fn=predict_image,
21
+ inputs=gr.Image(type="numpy"),
22
+ outputs="text",
23
+ title="Cancer Risk Detector (244×244)",
24
+ description="Upload an image to get a cancer risk prediction."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()
29
+