Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!pip install gradio
|
| 2 |
+
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
#im1 = PILImage.create('/kaggle/input/flowersdata/balsamroot/02d06c11-5738-47f0-bfaf-af79eb1d4405.jpg')
|
| 7 |
+
#im2 = PILImage.create('/kaggle/input/flowersdata/brittlebrush/ed0dc07f-49b3-48f0-9663-aefee1d3096b.jpg')
|
| 8 |
+
|
| 9 |
+
learn = load_learner('/kaggle/input/save-your-neural-network-as-a-pkl-file/export.pkl')
|
| 10 |
+
|
| 11 |
+
pred_class,pred_idx,probabilities = learn.predict(im1)
|
| 12 |
+
pred_class, pred_idx, probabilities
|
| 13 |
+
|
| 14 |
+
pred_class,pred_idx,probabilities = learn.predict(im2)
|
| 15 |
+
pred_class, pred_idx, probabilities
|
| 16 |
+
|
| 17 |
+
categories = ('balsamroot', 'bladderpod', 'blazing star', 'bristlecone pine flowers', 'brittlebrush')
|
| 18 |
+
def classify_image(img):
|
| 19 |
+
pred, idx, probs = learn.predict(img)
|
| 20 |
+
return dict(zip(categories, map(float, probs)))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
classify_image(im1), classify_image(im2)
|
| 24 |
+
|
| 25 |
+
image=gr.Image(height = 192, width = 192)
|
| 26 |
+
label = gr.Label()
|
| 27 |
+
#examples = ['/kaggle/input/example-images/Ronan_Grizzly_Bear_1.jpg','/kaggle/input/example-images/blackbear.jpg',
|
| 28 |
+
'/kaggle/input/example-images/blackbear2.jpg','/kaggle/input/example-images/brownbear.jpg',
|
| 29 |
+
'/kaggle/input/example-images/polar.jpg']
|
| 30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 31 |
+
intf.launch(inline=False)
|
| 32 |
+
|