tyler cross commited on
Commit
2567e9f
1 Parent(s): f0e2e89

Added correct file pathing

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +16 -4
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -2,17 +2,29 @@ import gradio as gr
2
  from fastai.vision.all import load_learner
3
  from PIL import Image
4
 
5
- model = load_learner('./export.pkl')
6
 
7
  def classify_image(img):
 
 
 
 
 
 
 
 
8
  # Convert the image to a format the model expects
9
  img = Image.fromarray(img.astype('uint8'), 'RGB')
10
  # Make a prediction
11
- pred, idx, probs = model.predict(img)
12
  # Return the result
13
  return {model.dls.vocab[i]: float(probs[i]) for i in range(len(model.dls.vocab))}
14
 
15
- demo = gr.Interface(fn=classify_image, inputs=gr.Image(label = 'Upload an image of a dung beetle, a dolphin, or an elephant!'), outputs="label")
 
 
 
 
16
 
17
  if __name__ == "__main__":
18
- demo.launch()
 
2
  from fastai.vision.all import load_learner
3
  from PIL import Image
4
 
5
+ model = load_learner('export.pkl')
6
 
7
  def classify_image(img):
8
+ """Classifies an image according to three categories: dung beetle, elephant, or dolphin.
9
+
10
+ Args:
11
+ img (any): Any image will be converted to expected type.
12
+
13
+ Returns:
14
+ _type_: Probabilies according to the three types.
15
+ """
16
  # Convert the image to a format the model expects
17
  img = Image.fromarray(img.astype('uint8'), 'RGB')
18
  # Make a prediction
19
+ probs = model.predict(img)
20
  # Return the result
21
  return {model.dls.vocab[i]: float(probs[i]) for i in range(len(model.dls.vocab))}
22
 
23
+ demo = gr.Interface(
24
+ fn=classify_image,
25
+ inputs = gr.Image(
26
+ label = 'Upload an image of a dung beetle, a dolphin, or an elephant!'),
27
+ outputs="label")
28
 
29
  if __name__ == "__main__":
30
+ demo.launch()