Saim8250 commited on
Commit
7f0b6ea
·
1 Parent(s): 0fc0313

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -19
app.py CHANGED
@@ -1,24 +1,34 @@
1
-
2
- import fastai
3
- from fastai.vision.all import*
4
  import gradio as gr
5
- import gradio.components as components
6
- from gradio import media_data, processing_utils, utils
7
- from gradio import encryptor, utils
8
-
9
 
10
- def is_cat(x):returnx[0].isupper()
 
 
 
 
11
 
12
- learn=load_learner('resnett.pkl')
 
 
 
 
 
 
 
13
 
14
- categories=learn.dls.vocab
 
 
 
15
 
16
- def classify_img(img):
17
- pred,idx,probs=learn.predict(img)
18
- return dict(zip(categories,map(float,probs)))
19
-
20
- image =gr.inputs.Image(shape=(192,192))
21
- label =gr.outputs.Label()
22
- example=['mel.jpg','akiec.jpg','vasc.jpg']
23
- intf=gr.Interface(fn=classify_img,inputs=image,outputs=label,examples=example)
24
- intf.launch(inline=False,share=False)
 
 
 
 
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)