devudilip commited on
Commit
c4e3b39
·
1 Parent(s): 83ab089
Files changed (2) hide show
  1. app.py +19 -4
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,18 +1,33 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
 
 
3
 
 
 
 
 
 
4
 
5
  learn = load_learner('model.pkl')
6
-
7
  labels = learn.dls.vocab
 
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
  title = "Pet Breed Classifier"
14
  description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
15
- article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
16
  examples = ['siamese.png']
17
 
18
- gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
+ import sys
4
+ import subprocess
5
 
6
+ # Install fasttransform for model compatibility
7
+ try:
8
+ import fasttransform # This makes the Pipeline class available for unpickling
9
+ except ImportError:
10
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "fasttransform"])
11
 
12
  learn = load_learner('model.pkl')
 
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
  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
+ article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
23
  examples = ['siamese.png']
24
 
25
+ gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.Image(shape=(512, 512)), # Updated to newer Gradio syntax
28
+ outputs=gr.Label(num_top_classes=3), # Updated to newer Gradio syntax
29
+ title=title,
30
+ description=description,
31
+ article=article,
32
+ examples=examples
33
+ ).launch()
requirements.txt CHANGED
@@ -1 +1,3 @@
1
  fastai
 
 
 
1
  fastai
2
+ gradio
3
+ fasttransform