Dane Summers commited on
Commit
325c700
·
1 Parent(s): acf24a0

Adds title, description, and examples.

Browse files
Files changed (4) hide show
  1. app.py +29 -5
  2. black.jpeg +0 -0
  3. brown.jpeg +0 -0
  4. teddy.jpeg +0 -0
app.py CHANGED
@@ -3,15 +3,39 @@ from fastai.learner import load_learner
3
  from fastai.vision.core import PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
- learner = load_learner(hf_hub_download("pinkpekoe/lesson2-bear-classifier", "export.pkl"))
 
 
7
 
8
 
9
- learner = load_learner('export.pkl')
 
10
 
11
  def predict_bear_type(img_path):
12
  img = PILImage.create(img_path)
13
  pred, pred_idx, probs = learner.predict(img)
14
- return f"Prediction: {pred}; Probability: {probs[pred_idx]:.02f}"
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- iface = gr.Interface(fn=predict_bear_type, inputs="image", outputs="text")
17
- iface.launch()
 
 
 
 
 
 
 
 
 
 
3
  from fastai.vision.core import PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
+ learner = load_learner(
7
+ hf_hub_download("pinkpekoe/lesson2-bear-classifier", "export.pkl")
8
+ )
9
 
10
 
11
+ learner = load_learner("export.pkl")
12
+
13
 
14
  def predict_bear_type(img_path):
15
  img = PILImage.create(img_path)
16
  pred, pred_idx, probs = learner.predict(img)
17
+ probabilities = [
18
+ f"{probs[i]:.02f}*" if i == pred_idx else f"{probs[i]:.02f}"
19
+ for i in range(len(probs))
20
+ ]
21
+ return f"Prediction: {pred}; Probabilities: " + ", ".join(probabilities)
22
+
23
+
24
+ title = "Pet Breed Classifier"
25
+ description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
26
+ article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
27
+ examples = ["black.jpeg", "brown.jpeg", "teddy.jpeg"]
28
+ interpretation = "default"
29
+ enable_queue = True
30
 
31
+ iface = gr.Interface(
32
+ fn=predict_bear_type,
33
+ inputs="image",
34
+ outputs="text",
35
+ title=title,
36
+ description=description,
37
+ article=article,
38
+ examples=examples,
39
+ interpretation=interpretation,
40
+ )
41
+ iface.launch(enable_queue=enable_queue)
black.jpeg ADDED
brown.jpeg ADDED
teddy.jpeg ADDED