robinsk8a commited on
Commit
7eaaa24
·
1 Parent(s): 723f24d

The last try of the day

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,21 +1,21 @@
1
  from fastai.vision.all import *
2
- from huggingface_hub import push_to_hub_fastai, from_pretrained_fastai
3
  import gradio as gr
4
 
5
- repo_id = "robinsk8a/exotic_cars_classifier"
6
- learn = from_pretrained_fastai(repo_id)
7
 
8
 
9
- categories = ('Dog', 'Cat''ferrari','lamborghini','mclaren','aston martin','koenigsegg','porsche','pagani')
10
 
11
- def classify_image(img):
12
- pred,idx,probs = learn.predict(img)
13
- return dict(zip(categories, map(float,probs)))
 
14
 
15
 
16
- image = gr.inputs.Image(shape=(192, 192))
17
- label = gr.outputs.Label()
18
- examples=['bmw.jpg', 'lamborghini.jpg', 'koenigsegg.jpg'],
 
 
19
 
20
- intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
21
- intf.launch()
 
1
  from fastai.vision.all import *
 
2
  import gradio as gr
3
 
4
+ learn = load_learner('export.pkl')
 
5
 
6
 
7
+ labels = learn.dls.vocab
8
 
9
+ def predict(img):
10
+ img = PILImage.create(img)
11
+ pred,pred_idx,probs = learn.predict(img)
12
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
13
 
14
 
15
+ title = "Car classifier"
16
+ description = "A car classifier in which I've being spending so much time to make a working prototype online"
17
+ examples = ['lamborghini.jpg', 'koenigsegg.jpg', '']
18
+ interpretation='default'
19
+ enable_queue=True
20
 
21
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()