shewster commited on
Commit
af62eda
1 Parent(s): 34a5be1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,19 +1,33 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
3
- import skimage
4
 
 
5
  learn = load_learner('export.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 = "Cashew Classifier"
14
- description = "Cashewwwwwwwwwwwww."
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
- interpretation='default'
17
- enable_queue=True
 
 
18
 
19
- 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,interpretation=interpretation,enable_queue=enable_queue).launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
+ import PIL.Image
4
 
5
+ # Load the learner
6
  learn = load_learner('export.pkl')
7
 
8
+ # Get the labels from the learner's vocabulary
9
  labels = learn.dls.vocab
10
+
11
+ # Define the prediction function
12
  def predict(img):
13
  img = PILImage.create(img)
14
+ pred, pred_idx, probs = learn.predict(img)
15
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
+ # Define the title, description, and article for the interface
18
  title = "Cashew Classifier"
19
+ description = "Classify images of cashews."
20
+ article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
21
+
22
+ # Define the interpretation mode (if applicable) and enable the queue
23
+ interpretation = None # Set to None if 'default' is not applicable or not desired
24
+ enable_queue = True
25
 
26
+ # Create and launch the Gradio interface
27
+ gr.Interface(fn=predict,
28
+ inputs=gr.inputs.Image(shape=(512, 512)),
29
+ outputs=gr.outputs.Label(num_top_classes=3),
30
+ title=title,
31
+ description=description,
32
+ article=article,
33
+ enable_queue=enable_queue).launch()