Spaces:
Runtime error
Runtime error
Tushar Gaurav commited on
Commit ·
9dcf78b
1
Parent(s): 1800c38
add file
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
|
| 4 |
+
learn = load_learner('model.pkl')
|
| 5 |
+
|
| 6 |
+
title = "Pet Classifier"
|
| 7 |
+
description = "A simple pet classifier that can classify images of pets into different categories."
|
| 8 |
+
|
| 9 |
+
labels = learn.dls.vocab
|
| 10 |
+
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = PILImage.create(img)
|
| 13 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 14 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=3))
|
| 17 |
+
demo.launch()
|