Erick Garcia Espinosa commited on
Commit
7b4760b
·
1 Parent(s): 010feb3

improvements

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -6,6 +6,7 @@ from PIL import Image
6
  from timm import create_model
7
  import matplotlib.pyplot as plt
8
 
 
9
  class_to_idx = {'Monkeypox': 0, 'Measles': 1, 'Chickenpox': 2, 'Herpes': 3, 'Melanoma': 4}
10
  idx_to_class = {v: k for k, v in class_to_idx.items()}
11
 
@@ -56,15 +57,18 @@ def predict_image(image_path):
56
  plt.savefig('result.png')
57
  plt.close(fig)
58
 
59
- return results, 'result.png'
 
 
 
60
 
61
  # Create the Gradio interface
62
  iface = gr.Interface(
63
  fn=predict_image,
64
  inputs=gr.Image(type="filepath", label="Upload an image"),
65
- outputs=[gr.Label(label="Prediction"), gr.Image(label="Prediction Probabilities")],
66
  title="Skin Lesion Image Classification",
67
- description="Upload an image of a skin lesion to get a prediction . Check out the dataset and paper at: [Link to Example 1](#), [Link to Example 2](#)",
68
  theme="huggingface",
69
  live=True
70
  )
 
6
  from timm import create_model
7
  import matplotlib.pyplot as plt
8
 
9
+ # Class to index and index to class mappings
10
  class_to_idx = {'Monkeypox': 0, 'Measles': 1, 'Chickenpox': 2, 'Herpes': 3, 'Melanoma': 4}
11
  idx_to_class = {v: k for k, v in class_to_idx.items()}
12
 
 
57
  plt.savefig('result.png')
58
  plt.close(fig)
59
 
60
+ # Return the top prediction as well
61
+ top_prediction = max(results, key=results.get)
62
+
63
+ return top_prediction, 'result.png'
64
 
65
  # Create the Gradio interface
66
  iface = gr.Interface(
67
  fn=predict_image,
68
  inputs=gr.Image(type="filepath", label="Upload an image"),
69
+ outputs=[gr.Textbox(label="Prediction"), gr.Image(label="Prediction Probabilities")],
70
  title="Skin Lesion Image Classification",
71
+ description="Upload an image of a skin lesion to get a prediction. This tool helps to classify images of skin lesions into the following categories: Measles, Chickenpox, Herpes, Melanomas, and Monkeypox. Check out the dataset and paper at: [Link to Example 1](#), [Link to Example 2](#)",
72
  theme="huggingface",
73
  live=True
74
  )