Fix Gradio and dependency compatibility

#1
.gitattributes CHANGED
@@ -1,27 +1,29 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ftz filter=lfs diff=lfs merge=lfs -text
6
- *.gz filter=lfs diff=lfs merge=lfs -text
7
- *.h5 filter=lfs diff=lfs merge=lfs -text
8
- *.joblib filter=lfs diff=lfs merge=lfs -text
9
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
- *.model filter=lfs diff=lfs merge=lfs -text
11
- *.msgpack filter=lfs diff=lfs merge=lfs -text
12
- *.onnx filter=lfs diff=lfs merge=lfs -text
13
- *.ot filter=lfs diff=lfs merge=lfs -text
14
- *.parquet filter=lfs diff=lfs merge=lfs -text
15
- *.pb filter=lfs diff=lfs merge=lfs -text
16
- *.pt filter=lfs diff=lfs merge=lfs -text
17
- *.pth filter=lfs diff=lfs merge=lfs -text
18
- *.rar filter=lfs diff=lfs merge=lfs -text
19
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
- *.tar.* filter=lfs diff=lfs merge=lfs -text
21
- *.tflite filter=lfs diff=lfs merge=lfs -text
22
- *.tgz filter=lfs diff=lfs merge=lfs -text
23
- *.wasm filter=lfs diff=lfs merge=lfs -text
24
- *.xz filter=lfs diff=lfs merge=lfs -text
25
- *.zip filter=lfs diff=lfs merge=lfs -text
26
- *.zstandard filter=lfs diff=lfs merge=lfs -text
27
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.onnx filter=lfs diff=lfs merge=lfs -text
13
+ *.ot filter=lfs diff=lfs merge=lfs -text
14
+ *.parquet filter=lfs diff=lfs merge=lfs -text
15
+ *.pb filter=lfs diff=lfs merge=lfs -text
16
+ *.pt filter=lfs diff=lfs merge=lfs -text
17
+ *.pth filter=lfs diff=lfs merge=lfs -text
18
+ *.rar filter=lfs diff=lfs merge=lfs -text
19
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
21
+ *.tflite filter=lfs diff=lfs merge=lfs -text
22
+ *.tgz filter=lfs diff=lfs merge=lfs -text
23
+ *.wasm filter=lfs diff=lfs merge=lfs -text
24
+ *.xz filter=lfs diff=lfs merge=lfs -text
25
+ *.zip filter=lfs diff=lfs merge=lfs -text
26
+ *.zstandard filter=lfs diff=lfs merge=lfs -text
27
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
28
+ examples/flowers0.jpg filter=lfs diff=lfs merge=lfs -text
29
+ examples/flowers2.jpg filter=lfs diff=lfs merge=lfs -text
LICENSE CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2022 Kurian Benoy
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
1
+ Copyright 2022 Kurian Benoy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.md CHANGED
@@ -1,13 +1,13 @@
1
- ---
2
- title: Identify Which Flower
3
- emoji: πŸ‘
4
- colorFrom: gray
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 3.0.22
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Identify Which Flower
3
+ emoji: πŸ‘
4
+ colorFrom: gray
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 5.29.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
__pycache__/app.cpython-312.pyc ADDED
Binary file (1.84 kB). View file
 
app.py CHANGED
@@ -1,39 +1,30 @@
 
 
1
  import gradio as gr
2
- from huggingface_hub import from_pretrained_fastai
3
  from fastai.vision.all import *
4
- repo_id = "hugginglearners/flowers_101_convnext_model"
5
 
 
6
  learn = from_pretrained_fastai(repo_id)
7
  labels = learn.dls.vocab
8
- EXAMPLES_PATH = Path('./examples')
9
 
10
 
11
  def predict(img):
12
  img = PILImage.create(img)
13
  _pred, _pred_w_idx, probs = learn.predict(img)
14
- # gradio doesn't support tensors, so converting to float
15
- labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
16
- return labels_probs
17
 
18
- interface_options = {
19
- "title": "Identify which flower it is?",
20
- "description": "I am terribly bad at remembering names of flowers and trees and it's often difficult to fathom how diverse our natural world is. There are over 5,000 species of mammals, 10,000 species of birds, 30,000 species of fish – and astonishingly, over 400,000 different types of flowers.\n Identify which flower variety it is by uploading your images.",
21
- "interpretation": "default",
22
- "layout": "horizontal",
23
- "allow_flagging": "never",
24
- "examples": [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()],
25
- }
26
 
27
  demo = gr.Interface(
28
  fn=predict,
29
- inputs=gr.inputs.Image(shape=(192, 192)),
30
- outputs=gr.outputs.Label(num_top_classes=3),
31
- **interface_options,
 
 
 
32
  )
33
-
34
- launch_options = {
35
- "enable_queue": True,
36
- "share": True,
37
- }
38
-
39
- demo.launch(**launch_options)
 
1
+ from pathlib import Path
2
+
3
  import gradio as gr
 
4
  from fastai.vision.all import *
5
+ from huggingface_hub import from_pretrained_fastai
6
 
7
+ repo_id = "hugginglearners/flowers_101_convnext_model"
8
  learn = from_pretrained_fastai(repo_id)
9
  labels = learn.dls.vocab
10
+ EXAMPLES_PATH = Path("./examples")
11
 
12
 
13
  def predict(img):
14
  img = PILImage.create(img)
15
  _pred, _pred_w_idx, probs = learn.predict(img)
16
+ return {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
17
+
 
18
 
19
+ examples = [str(path) for path in EXAMPLES_PATH.iterdir()] if EXAMPLES_PATH.exists() else None
 
 
 
 
 
 
 
20
 
21
  demo = gr.Interface(
22
  fn=predict,
23
+ inputs=gr.Image(type="pil", height=192, width=192),
24
+ outputs=gr.Label(num_top_classes=3),
25
+ title="Identify which flower it is?",
26
+ description="Identify which flower variety it is by uploading an image.",
27
+ examples=examples,
28
+ flagging_mode="never",
29
  )
30
+ demo.queue().launch(share=False)
 
 
 
 
 
 
examples/flowers0.jpg CHANGED

Git LFS Details

  • SHA256: 980bd2d71f35785158d0c9e407ceceb69553fee80a98e514514395ddab912ea4
  • Pointer size: 131 Bytes
  • Size of remote file: 205 kB
examples/flowers2.jpg CHANGED

Git LFS Details

  • SHA256: 1ba554e8c97e2ef06e3c09f8c8e7a0c9bd74f60f493f64ba23d84e101541b71a
  • Pointer size: 131 Bytes
  • Size of remote file: 197 kB
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- fastai==2.7.4
2
- huggingface_hub[fastai]
3
- fastcore>=1.3.27
4
- timm==0.6.2.dev0
 
1
+ fastai>=2.7.18,<3
2
+ huggingface_hub[fastai]>=0.23
3
+ timm==0.6.13