sks01dev commited on
Commit
9d5cab1
·
1 Parent(s): 9dcf6c8

Initial deploy: added fastai model, app.py, and examples

Browse files
Files changed (5) hide show
  1. app.py +37 -0
  2. birman.jpg +0 -0
  3. british.jpg +0 -0
  4. pomerian.jpg +0 -0
  5. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from fastai.vision.all import *
4
+ import os
5
+
6
+ # --- Model Loading (Assumes model.pkl exists in the root) ---
7
+ try:
8
+ learn = load_learner('export.pkl')
9
+ except Exception:
10
+ print("Error loading export.pkl. Check file path/existence.")
11
+ raise
12
+
13
+ labels = learn.dls.vocab
14
+
15
+ def predict(img):
16
+ img = PILImage.create(img)
17
+ pred, pred_idx, probs = learn.predict(img)
18
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
19
+
20
+ # --- Interface Setup ---
21
+ examples = ["birman.jpg", "pomerian.jpg", "british.jpg"]
22
+ title = "Pet Breed Classifier"
23
+ description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
24
+ article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
25
+
26
+ demo = gr.Interface(
27
+ fn=predict,
28
+ inputs=gr.Image(type="pil"),
29
+ outputs=gr.Label(num_top_classes=3),
30
+ title=title,
31
+ description=description,
32
+ article=article,
33
+ examples=examples
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ demo.launch()
birman.jpg ADDED
british.jpg ADDED
pomerian.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ fastai
3
+ scikit-image
4
+ gradio
5
+ torch