Upload 3 files
Browse files- CModel.h5 +3 -0
- app.py +53 -0
- requirements (1).txt +4 -0
CModel.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:618cb495f0a92837c9d5c3a8be8982e2801195d57c065bfb82726f1568d70f12
|
| 3 |
+
size 8411264
|
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import numpy as np
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# ----------------------------
|
| 7 |
+
# LOAD MODEL (LOCAL FILE)
|
| 8 |
+
# ----------------------------
|
| 9 |
+
model = tf.keras.models.load_model("CModel.h5")
|
| 10 |
+
|
| 11 |
+
IMG_SIZE = (224, 224)
|
| 12 |
+
|
| 13 |
+
CLASS_NAMES = [
|
| 14 |
+
"Normal",
|
| 15 |
+
"Monkeypox"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
# ----------------------------
|
| 19 |
+
# PREDICTION FUNCTION
|
| 20 |
+
# ----------------------------
|
| 21 |
+
def predict_image(image):
|
| 22 |
+
image = image.convert("RGB")
|
| 23 |
+
image = image.resize(IMG_SIZE)
|
| 24 |
+
|
| 25 |
+
img_array = np.array(image) / 255.0
|
| 26 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 27 |
+
|
| 28 |
+
pred = model.predict(img_array)
|
| 29 |
+
|
| 30 |
+
if pred.shape[1] == 1:
|
| 31 |
+
confidence = float(pred[0][0])
|
| 32 |
+
label = CLASS_NAMES[1] if confidence > 0.5 else CLASS_NAMES[0]
|
| 33 |
+
return label, confidence
|
| 34 |
+
else:
|
| 35 |
+
class_index = int(np.argmax(pred))
|
| 36 |
+
confidence = float(pred[0][class_index])
|
| 37 |
+
return CLASS_NAMES[class_index], confidence
|
| 38 |
+
|
| 39 |
+
# ----------------------------
|
| 40 |
+
# GRADIO UI
|
| 41 |
+
# ----------------------------
|
| 42 |
+
interface = gr.Interface(
|
| 43 |
+
fn=predict_image,
|
| 44 |
+
inputs=gr.Image(type="pil"),
|
| 45 |
+
outputs=[
|
| 46 |
+
gr.Label(label="Prediction"),
|
| 47 |
+
gr.Number(label="Confidence")
|
| 48 |
+
],
|
| 49 |
+
title="Monkeypox Classification using CNN",
|
| 50 |
+
description="Upload a skin image to classify Monkeypox using a CNN model."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
interface.launch()
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
pillow
|
| 4 |
+
gradio
|