Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
-
import
|
| 5 |
|
| 6 |
# Load the trained model
|
| 7 |
-
model =
|
| 8 |
|
|
|
|
| 9 |
class_names = ["Monkeypox", "Not Monkeypox"]
|
| 10 |
|
| 11 |
def predict(img):
|
|
@@ -14,15 +15,11 @@ def predict(img):
|
|
| 14 |
img = np.array(img) / 255.0 # normalize
|
| 15 |
img = np.expand_dims(img, axis=0)
|
| 16 |
|
|
|
|
| 17 |
preds = model.predict(img)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 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,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
+
from tensorflow.keras.models import load_model
|
| 5 |
|
| 6 |
# Load the trained model
|
| 7 |
+
model = load_model("model.h5")
|
| 8 |
|
| 9 |
+
# Define class labels
|
| 10 |
class_names = ["Monkeypox", "Not Monkeypox"]
|
| 11 |
|
| 12 |
def predict(img):
|
|
|
|
| 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 |
+
# Convert predictions to dictionary
|
| 22 |
+
return {class_names[i]: float(preds[0][i]) for i in range(len(class_names))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=predict,
|