Update app.py
Browse files
app.py
CHANGED
|
@@ -6,20 +6,23 @@ import joblib
|
|
| 6 |
# Load the trained model
|
| 7 |
model = joblib.load("model.pkl")
|
| 8 |
|
| 9 |
-
# Define class labels
|
| 10 |
class_names = ["Monkeypox", "Not Monkeypox"]
|
| 11 |
|
| 12 |
def predict(img):
|
| 13 |
# Resize image to match model input size
|
| 14 |
-
img = img.resize((224,224))
|
| 15 |
img = np.array(img) / 255.0 # normalize
|
| 16 |
img = np.expand_dims(img, axis=0)
|
| 17 |
|
| 18 |
-
# Predict
|
| 19 |
preds = model.predict(img)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=predict,
|
|
|
|
| 6 |
# Load the trained model
|
| 7 |
model = joblib.load("model.pkl")
|
| 8 |
|
|
|
|
| 9 |
class_names = ["Monkeypox", "Not Monkeypox"]
|
| 10 |
|
| 11 |
def predict(img):
|
| 12 |
# Resize image to match model input size
|
| 13 |
+
img = img.resize((224, 224))
|
| 14 |
img = np.array(img) / 255.0 # normalize
|
| 15 |
img = np.expand_dims(img, axis=0)
|
| 16 |
|
|
|
|
| 17 |
preds = model.predict(img)
|
| 18 |
|
| 19 |
+
probs = preds[0]
|
| 20 |
+
result = {class_names[i]: float(probs[i]) for i in range(len(class_names))}
|
| 21 |
+
|
| 22 |
+
pred_idx = np.argmax(probs)
|
| 23 |
+
pred_label = class_names[pred_idx]
|
| 24 |
+
|
| 25 |
+
return result
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=predict,
|