Spaces:
Sleeping
Sleeping
khu commited on
Commit ·
8784356
1
Parent(s): dc397ac
first commit-> push bear classifier model
Browse files- app.py +22 -0
- export.pkl +3 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
|
| 4 |
+
# Load the model
|
| 5 |
+
learn = load_learner('export.pkl')
|
| 6 |
+
labels = learn.dls.vocab
|
| 7 |
+
|
| 8 |
+
def predict(img):
|
| 9 |
+
img = PILImage.create(img)
|
| 10 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 12 |
+
|
| 13 |
+
# Define the Gradio interface
|
| 14 |
+
interface = gr.Interface(
|
| 15 |
+
fn=predict,
|
| 16 |
+
inputs=gr.Image(type="pil"),
|
| 17 |
+
outputs=gr.Label(num_top_classes=3),
|
| 18 |
+
title="Bear Classifier",
|
| 19 |
+
description="Upload an image to see if it's a Grizzly, Black, or Teddy bear!"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
interface.launch()
|
export.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b38ed91103fcdcd31f50c338d5fde42a4978d697ba153ce1d4736ea8d714a04
|
| 3 |
+
size 46964571
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
gradio
|
| 3 |
+
torch
|