devudilip commited on
Commit
6ed6ec2
·
1 Parent(s): c4e3b39

error handle

Browse files
Files changed (4) hide show
  1. .DS_Store +0 -0
  2. app.py +37 -30
  3. model.pkl → modeltest.pkl +2 -2
  4. requirements.txt +1 -3
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -1,33 +1,40 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from fastai.vision.all import *
2
+ import gradio as gr
3
+
4
+ def is_cat(x): return x[0].isupper()
5
+
6
+ learn = load_learner('modeltest.pkl')
7
+
8
+ categories = ('Dog', 'Cat')
9
+
10
+ def classify_image(img):
11
+ pred, idx, probs = learn.predict(img)
12
+ return dict(zip(categories, map(float, probs)))
13
+
14
+ image = gr.inputs.Image(shape=(192, 192))
15
+ label = gr.outputs.Label()
16
+
 
 
 
 
 
17
  examples = ['siamese.png']
18
 
19
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
20
+ intf.launch(inline=False)
21
+
22
+
23
+ # labels = learn.dls.vocab
24
+
25
+
26
+
27
+ # title = "Pet Breed Classifier"
28
+ # description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
29
+ # article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
30
+
31
+
32
+ # gr.Interface(
33
+ # fn=predict,
34
+ # inputs=gr.Image(shape=(512, 512)), # Updated to newer Gradio syntax
35
+ # outputs=gr.Label(num_top_classes=3), # Updated to newer Gradio syntax
36
+ # title=title,
37
+ # description=description,
38
+ # article=article,
39
+ # examples=examples
40
+ # ).launch()
model.pkl → modeltest.pkl RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d84472b1140392587f3894cacd29dc0feb9ea948f4092deba42ad90da83c6dd6
3
- size 47060011
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
3
+ size 47059947
requirements.txt CHANGED
@@ -1,3 +1 @@
1
- fastai
2
- gradio
3
- fasttransform
 
1
+ fastai