Spaces:
Build error
Build error
Aviral Kaintura
commited on
Commit
·
cacdfcd
1
Parent(s):
5690164
Initial commit
Browse files- .gitattributes +1 -0
- README copy.md +12 -0
- app.py +90 -0
- img1.jpg +3 -0
- img2.jpg +3 -0
- img3.jpg +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
README copy.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Skinlesion
|
| 3 |
+
emoji: 🌍
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.29.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.learner import *
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
learn = load_learner("export.pkl")
|
| 6 |
+
labels = learn.dls.vocab
|
| 7 |
+
|
| 8 |
+
def predict(img):
|
| 9 |
+
# Ensure img is a PILImage object; if it's already PIL, create won't harm it.
|
| 10 |
+
# If it's a numpy array (e.g. from Gradio's Image component with type="numpy"),
|
| 11 |
+
# PILImage.create will convert it.
|
| 12 |
+
img = PILImage.create(img)
|
| 13 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 14 |
+
# Ensure probs are float for JSON serialization if necessary
|
| 15 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 16 |
+
|
| 17 |
+
title = "Skin Lesion Classifier [RESNET 50]"
|
| 18 |
+
description = "A skin lesion classifier trained on the ISIC2019 dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 19 |
+
article = "<p style='text-align: center'><a href='https://challenge.isic-archive.com/data/' target='_blank'>Link to ISIC Dataset</a></p>"
|
| 20 |
+
examples = ['img1.jpg', 'img2.jpg', 'img3.jpg']
|
| 21 |
+
|
| 22 |
+
# Updated Gradio Interface
|
| 23 |
+
# gr.inputs.Image becomes gr.Image
|
| 24 |
+
# gr.outputs.Label becomes gr.Label
|
| 25 |
+
# 'shape' parameter for gr.Image is deprecated. Image size is handled by the component or by resizing in the predict function if needed.
|
| 26 |
+
# 'type="pil"' ensures the input to predict() is a PIL Image, aligning with PILImage.create().
|
| 27 |
+
# 'num_top_classes' is a valid parameter for gr.Label.
|
| 28 |
+
# 'interpretation' parameter is deprecated and removed.
|
| 29 |
+
# 'enable_queue' is True by default, so explicit setting is often not needed but kept for clarity.
|
| 30 |
+
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=predict,
|
| 33 |
+
inputs=gr.Image(type="pil", label="Upload Skin Lesion Image"),
|
| 34 |
+
outputs=gr.Label(num_top_classes=3, label="Classification Results"),
|
| 35 |
+
title=title,
|
| 36 |
+
description=description,
|
| 37 |
+
article=article,
|
| 38 |
+
examples=examples,
|
| 39 |
+
# interpretation='default', # Removed
|
| 40 |
+
enable_queue=True
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == '__main__':
|
| 44 |
+
iface.launch()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# import gradio as gr
|
| 63 |
+
# from fastai.vision.all import *
|
| 64 |
+
# import skimage
|
| 65 |
+
# #Importing necessary libraries
|
| 66 |
+
# import gradio as gr
|
| 67 |
+
# #import scikit-learn as sklearn
|
| 68 |
+
# from fastai.vision.all import *
|
| 69 |
+
# from sklearn.metrics import roc_auc_score
|
| 70 |
+
|
| 71 |
+
# learn = load_learner('export.pkl')
|
| 72 |
+
|
| 73 |
+
# labels = learn.dls.vocab
|
| 74 |
+
# def predict(img):
|
| 75 |
+
# img = PILImage.create(img)
|
| 76 |
+
# pred,pred_idx,probs = learn.predict(img)
|
| 77 |
+
# return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
# examples = ['img1.jpg','img2.jpg','img3.jpg']
|
| 81 |
+
|
| 82 |
+
# #Launching the gradio application
|
| 83 |
+
# gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),
|
| 84 |
+
# outputs=gr.outputs.Label(num_top_classes=1),
|
| 85 |
+
# title=title,
|
| 86 |
+
# description=description,article=article,
|
| 87 |
+
# examples=examples,
|
| 88 |
+
# enable_queue=enable_queue).launch(inline=False)
|
| 89 |
+
|
| 90 |
+
# #gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(224, 224)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
|
img1.jpg
ADDED
|
Git LFS Details
|
img2.jpg
ADDED
|
Git LFS Details
|
img3.jpg
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai~=2.7.10
|
| 2 |
+
gradio~=4.0
|
| 3 |
+
scikit-image
|
| 4 |
+
Werkzeug
|