kurianbenoy commited on
Commit
5ab6ff3
1 Parent(s): cbcc912

Create application

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import from_pretrained_fastai
3
+ repo_id = "hugginglearners/flowers_101_convnext_model"
4
+
5
+ learn = from_pretrained_fastai(repo_id)
6
+ labels = learn.dls.vocab
7
+
8
+
9
+
10
+ def predict(img):
11
+ img = PILImage.create(img)
12
+ _pred, _pred_w_idx, probs = learn.predict(img)
13
+ # gradio doesn't support tensors, so converting to float
14
+ labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
15
+ return labels_probs
16
+
17
+ interface_options = {
18
+ "title": "Identify which flower it is?",
19
+ "description": "It’s difficult to fathom just how vast and 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 of flowers.",
20
+ "interpretation": "default",
21
+ "layout": "horizontal",
22
+ "allow_flagging": "never",
23
+ }
24
+
25
+ demo = gr.Interface(
26
+ fn=predict,
27
+ inputs=gr.inputs.Image(shape=(192, 192)),
28
+ outputs=gr.outputs.Label(num_top_classes=3),
29
+ **interface_options,
30
+ )
31
+
32
+ launch_options = {
33
+ "enable_queue": True,
34
+ "share": True,
35
+ }
36
+
37
+ demo.launch(**launch_options)