Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- .gitattributes +1 -0
- app.py +30 -0
- model.pkl +3 -0
- parrot.jpeg +0 -0
- polar bear.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
polar[[:space:]]bear.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Load the exported fastai Learner
|
| 6 |
+
learn = load_learner('model.pkl')
|
| 7 |
+
labels = learn.dls.vocab # ['bear', 'parrot']
|
| 8 |
+
|
| 9 |
+
# Prediction function
|
| 10 |
+
def predict(img):
|
| 11 |
+
pred, pred_idx, probs = learn.predict(img)
|
| 12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 13 |
+
|
| 14 |
+
# Interface metadata
|
| 15 |
+
title = "Polar Bear vs Parrot Classifier"
|
| 16 |
+
description = "A simple image classifier that distinguishes between polar bears and parrots using fastai and Gradio."
|
| 17 |
+
|
| 18 |
+
# Optional: Example images must exist in the same directory
|
| 19 |
+
examples = ['polar bear.jpg', 'parrot.jpeg']
|
| 20 |
+
|
| 21 |
+
# Launch the Gradio interface
|
| 22 |
+
gr.Interface(
|
| 23 |
+
fn=predict,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Label(num_top_classes=2),
|
| 26 |
+
title=title,
|
| 27 |
+
description=description,
|
| 28 |
+
examples=examples,
|
| 29 |
+
allow_flagging='never'
|
| 30 |
+
).launch()
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8992eb9bb3f0b5b44e19effdff8a4dbd93c6e6c0af3e1b3ae3459c3bc5b7928d
|
| 3 |
+
size 46967280
|
parrot.jpeg
ADDED
|
polar bear.jpg
ADDED
|
Git LFS Details
|