robinsk8a commited on
Commit
7bbaaf6
·
1 Parent(s): a4883dd

one more...

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -1,15 +1,21 @@
 
 
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- pipeline = pipeline(task="image-classification", model="robinsk8a/exotic_cars_classifier")
 
5
 
6
- def predict(image):
7
- predictions = pipeline(image)
8
- return {p["label"]: p["score"] for p in predictions}
9
 
10
- gr.Interface(
11
- predict,
12
- inputs=gr.inputs.Image(label="Upload the car you want to guess", type="filepath"),
13
- outputs=gr.outputs.Label(num_top_classes=3),
14
- title="Exotic car classifier",
15
- ).launch()
 
 
 
 
 
 
 
 
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()