socd06 commited on
Commit
bf8d034
·
1 Parent(s): bc38e6b

Make adjustments for fastai learner

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
5
 
6
  repo_id = "artificeresearch/spiritvision"
7
  learner = from_pretrained_fastai(repo_id)
 
8
 
9
 
10
  def predict_fn(img):
@@ -13,9 +14,11 @@ def predict_fn(img):
13
  :return: prediction and probabilities
14
  """
15
  img = img.convert('RGB')
16
- prediction, _, probs = learner.predict(img)
17
  # print(f'{max(100 * probs):.2f}% {prediction} - {img}')
18
- return f'{max(100 * probs):.2f}% {prediction} - {img}'
 
19
 
20
 
21
- gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label').launch()
 
 
 
5
 
6
  repo_id = "artificeresearch/spiritvision"
7
  learner = from_pretrained_fastai(repo_id)
8
+ labels = learner.dls.vocab
9
 
10
 
11
  def predict_fn(img):
 
14
  :return: prediction and probabilities
15
  """
16
  img = img.convert('RGB')
 
17
  # print(f'{max(100 * probs):.2f}% {prediction} - {img}')
18
+ pred, pred_idx, probs = learner.predict(img)
19
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
20
 
21
 
22
+ gr.Interface(predict_fn,
23
+ gr.inputs.Image(type='pil', shape=(512, 512)),
24
+ outputs=gr.outputs.Label(num_top_classes=3)).launch()