Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai import *
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import skimage
|
| 5 |
+
learn = load_learner('export.pkl')
|
| 6 |
+
## function to use with gradio
|
| 7 |
+
## we need this to make prediction on future images
|
| 8 |
+
labels = learn.dls.vocab ## retrives labels
|
| 9 |
+
def predict(img):
|
| 10 |
+
img = PILImage.create(img) # read images
|
| 11 |
+
pred,pred_idx,probs = learn.predict(img) ### get pred , pred_index and prob for a a given image
|
| 12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 13 |
+
title = " Car type Classifier"
|
| 14 |
+
description = "A car classifier trained using <a href='https://www.kaggle.com/datasets/jutrera/stanford-car-dataset-by-classes-folder'> the Oxford car dataset </a> with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
| 15 |
+
article="<p style='text-align: center'><a href='https://aniba' target='_blank'> github code</a></p>"
|
| 16 |
+
examples=["2009_bugatti_veyron_grand_sport_10.jpg", "07-x5-bmw.jpg"]
|
| 17 |
+
interpretation='default'
|
| 18 |
+
enable_queue=True
|
| 19 |
+
gr.Interface(fn=predict,
|
| 20 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
| 21 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
| 22 |
+
examples=examples,
|
| 23 |
+
title=title,
|
| 24 |
+
description=description,
|
| 25 |
+
article=article,
|
| 26 |
+
enable_queue= enable_queue,
|
| 27 |
+
interpretation=interpretation).launch(share=True)
|
| 28 |
+
|
| 29 |
+
|