samschimek commited on
Commit
dd874b7
1 Parent(s): e41ed17

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +26 -0
  2. model.pkl +3 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import load_learner, PILImage
3
+
4
+ # Load the trained model
5
+ learn = load_learner('model.pkl')
6
+
7
+ # Define the prediction function
8
+ labels = learn.dls.vocab
9
+
10
+ def predict(img):
11
+ img = PILImage.create(img)
12
+ pred, pred_idx, probs = learn.predict(img)
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
14
+
15
+ # Create Gradio interface
16
+ interface = gr.Interface(
17
+ fn=predict,
18
+ inputs=gr.Image(type="pil"),
19
+ outputs=gr.Label(num_top_classes=3),
20
+ title="Pet Breed Classifier",
21
+ description="A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces.",
22
+ examples=["example1.jpg", "example2.jpg", "example3.jpg"] # Replace with actual filenames
23
+ )
24
+
25
+ # Launch the interface
26
+ interface.launch()
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a3aa1a7266adeda9675fab1c94f1e61be40822674bb14f47db464a28aafb926
3
+ size 103057644
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastai
2
+ gradio