shivakumar4147 commited on
Commit
0a58ccb
·
verified ·
1 Parent(s): b5f28cc

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +40 -0
  2. final_model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # ---------- Load your trained model ----------
7
+ model = tf.keras.models.load_model("final_model.h5")
8
+
9
+ # ---------- Prediction function ----------
10
+ def predict(image):
11
+ # Resize the input image to the size your model expects (update if different)
12
+ img = image.resize((224, 224)) # change size if your model was trained differently
13
+ img_array = np.array(img) / 255.0 # normalize
14
+
15
+ # Expand dimensions for batch
16
+ img_array = np.expand_dims(img_array, axis=0)
17
+
18
+ # Predict
19
+ prediction = model.predict(img_array)[0][0] # assumes binary classification
20
+
21
+ # Convert probability to label
22
+ if prediction > 0.5:
23
+ result = f"🟥 Malignant (Cancer Detected) with {prediction*100:.2f}% confidence"
24
+ else:
25
+ result = f"🟩 Benign (No Cancer) with {(1-prediction)*100:.2f}% confidence"
26
+
27
+ return result
28
+
29
+ # ---------- Define Gradio UI ----------
30
+ demo = gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.Image(type="pil", label="Upload Skin Lesion Image"),
33
+ outputs=gr.Textbox(label="Prediction"),
34
+ title="🧬 Skin Cancer Detection",
35
+ description="Upload a skin lesion image and the model will predict whether it is Benign or Malignant."
36
+ )
37
+
38
+ # ---------- Launch ----------
39
+ if __name__ == "__main__":
40
+ demo.launch()
final_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ff8ac00211462b4b533154bae22362e5501838219a1dfb9eecf3bd8121ca533
3
+ size 24526712
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ opencv-python
3
+ numpy
4
+ gradio