alibayram commited on
Commit
4af9a59
·
1 Parent(s): 0eadcb8

Add debug prints for predictions and class names; change ImageEditor to Sketchpad

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -34,10 +34,13 @@ def predict(data):
34
  # Model predictions
35
  preds = model.predict(img)[0]
36
 
 
 
37
  # Get top 3 classes
38
  top_3_classes = np.argsort(preds)[-3:][::-1]
39
  top_3_probs = preds[top_3_classes]
40
  class_names = [labels[i] for i in top_3_classes]
 
41
 
42
  # Return top 3 predictions as a dictionary
43
  return {class_names[i]: float(top_3_probs[i]) for i in range(3)}
@@ -60,12 +63,12 @@ with gr.Blocks(title=title) as demo:
60
 
61
  with gr.Row():
62
  # Using ImageEditor with type='numpy'
63
- im = gr.ImageEditor(type="numpy", label="Draw your digit here (use brush and eraser)")
64
 
65
  # Output label (top 3 predictions)
66
  label = gr.Label(num_top_classes=3, label="Predictions")
67
 
68
  # Trigger prediction whenever the image changes
69
- im.change(predict, inputs=im, outputs=label, show_progress="hidden")
70
 
71
  demo.launch(share=True)
 
34
  # Model predictions
35
  preds = model.predict(img)[0]
36
 
37
+ print(preds)
38
+
39
  # Get top 3 classes
40
  top_3_classes = np.argsort(preds)[-3:][::-1]
41
  top_3_probs = preds[top_3_classes]
42
  class_names = [labels[i] for i in top_3_classes]
43
+ print(class_names, top_3_probs, top_3_classes)
44
 
45
  # Return top 3 predictions as a dictionary
46
  return {class_names[i]: float(top_3_probs[i]) for i in range(3)}
 
63
 
64
  with gr.Row():
65
  # Using ImageEditor with type='numpy'
66
+ im = gr.Sketchpad(type="numpy", label="Draw your digit here (use brush and eraser)")
67
 
68
  # Output label (top 3 predictions)
69
  label = gr.Label(num_top_classes=3, label="Predictions")
70
 
71
  # Trigger prediction whenever the image changes
72
+ im.change(predict, inputs=im, outputs=label)
73
 
74
  demo.launch(share=True)