tegana commited on
Commit
d0df7d3
·
verified ·
1 Parent(s): 8664119

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
- import joblib
5
 
6
  # Load the trained model
7
- model = joblib.load("model.pkl")
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
- 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,
 
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,