Mark Henry commited on
Commit
7b3a7b6
·
0 Parent(s):

hello huggingface world

Browse files
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load the model from gluten.py
2
+ # Create a gradio interface for the model
3
+ # Run the model on the interface
4
+
5
+ from fastai.vision.all import *
6
+ import gradio as gr
7
+
8
+
9
+ # This method is required for unpickling
10
+ def label_for_path(path):
11
+ return {
12
+ 'bread': 'glutenful',
13
+ 'gluten_free': 'glutenfree',
14
+ 'man-made': 'glutenfree',
15
+ 'fruit': 'glutenfree',
16
+ 'malt_beverage': 'glutenful',
17
+ 'meat': 'glutenfree',
18
+ 'soy_sauce': 'glutenful',
19
+ 'tamari': 'glutenfree'
20
+ }[str(list(path.parts)[1])]
21
+
22
+
23
+ learn_inf = load_learner(Path() / 'gluten.pkl')
24
+
25
+ categories = ('glutenful', 'gluten-free')
26
+
27
+
28
+ def classify_image(img):
29
+ img = PILImage.create(img)
30
+ pred, pred_idx, probs = learn_inf.predict(img)
31
+ return {categories[i]: float(probs[i]) for i in range(len(categories))}
32
+
33
+
34
+ image = gr.inputs.Image()
35
+ label = gr.outputs.Label()
36
+ # examples = all files in the /examples folder
37
+ examples = [f"examples/{i}" for i in os.listdir("examples")]
38
+
39
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
40
+ intf.launch(inline=False)
examples/bread.jpg ADDED

Git LFS Details

  • SHA256: 2f45ba9a5790a13a988b1966eb6dd6198c8b7156fbaf0f64f600e94d0b54c233
  • Pointer size: 132 Bytes
  • Size of remote file: 4.04 MB
examples/capitol.jpg ADDED

Git LFS Details

  • SHA256: 57402ba209840695b9a7f27304804d8773c498925bb5d9b6130de1941c0a7b6e
  • Pointer size: 131 Bytes
  • Size of remote file: 213 kB
examples/fruit.JPG ADDED

Git LFS Details

  • SHA256: 0f9b0d68498660ce2d31193dc1542a52e94566b7072c37b9818230443c86892a
  • Pointer size: 131 Bytes
  • Size of remote file: 606 kB
examples/soysauce.jpg ADDED

Git LFS Details

  • SHA256: 91235e7f7b7904a1cf320bc61688a5ca4e57325668236a1a27f337bb46001d4c
  • Pointer size: 130 Bytes
  • Size of remote file: 99.5 kB
examples/tamari.jpeg ADDED