Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,34 @@
|
|
1 |
-
|
2 |
-
import fastai
|
3 |
-
from fastai.vision.all import*
|
4 |
import gradio as gr
|
5 |
-
import
|
6 |
-
from
|
7 |
-
from
|
8 |
-
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from huggingface_hub import from_pretrained_fastai
|
4 |
+
from pathlib import Path
|
|
|
5 |
|
6 |
+
examples = ["akiec.jpg",
|
7 |
+
"mel.jpg",]
|
8 |
+
|
9 |
+
repo_id = "https://huggingface.co/Saim8250/Skin-Diseases-Classification/tree/main"
|
10 |
+
path = Path("./")
|
11 |
|
12 |
+
def get_y(r):
|
13 |
+
return r["label"]
|
14 |
+
|
15 |
+
def get_x(r):
|
16 |
+
return path/r["fname"]
|
17 |
+
|
18 |
+
learner = from_pretrained_fastai(repo_id)
|
19 |
+
labels = learner.dls.vocab
|
20 |
|
21 |
+
def inference(image):
|
22 |
+
label_predict,_,probs = learner.predict(image)
|
23 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
24 |
+
return labels_probs
|
25 |
|
26 |
+
gr.Interface(
|
27 |
+
fn=inference,
|
28 |
+
title="Skin Diseases classification",
|
29 |
+
description = "Predict which type of skin disease",
|
30 |
+
inputs="image",
|
31 |
+
examples=examples,
|
32 |
+
outputs=gr.outputs.Label(num_top_classes=5, label='Prediction'),
|
33 |
+
cache_examples=False,
|
34 |
+
).launch(debug=True, enable_queue=True)
|