Spaces:
Runtime error
Runtime error
Commit
·
7c0bdb7
1
Parent(s):
54cd6e3
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This Python 3 environment comes with many helpful analytics libraries installed
|
| 2 |
+
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
|
| 3 |
+
# For example, here's several helpful packages to load
|
| 4 |
+
|
| 5 |
+
import numpy as np # linear algebra
|
| 6 |
+
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
|
| 7 |
+
|
| 8 |
+
# Input data files are available in the read-only "../input/" directory
|
| 9 |
+
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
for dirname, _, filenames in os.walk('/kaggle/input'):
|
| 13 |
+
for filename in filenames:
|
| 14 |
+
print(os.path.join(dirname, filename))
|
| 15 |
+
|
| 16 |
+
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
|
| 17 |
+
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
|
| 18 |
+
|
| 19 |
+
#|default_exp app
|
| 20 |
+
|
| 21 |
+
#|export
|
| 22 |
+
#!pip install fastbook
|
| 23 |
+
import fastbook
|
| 24 |
+
from fastbook import *
|
| 25 |
+
#!pip install fastai
|
| 26 |
+
from fastai.vision.widgets import *
|
| 27 |
+
#!pip install gradio
|
| 28 |
+
import gradio as gr
|
| 29 |
+
|
| 30 |
+
import IPython
|
| 31 |
+
from IPython.display import display
|
| 32 |
+
from PIL import Image
|
| 33 |
+
|
| 34 |
+
import pathlib
|
| 35 |
+
temp = pathlib.PosixPath
|
| 36 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 37 |
+
|
| 38 |
+
def search_images(term, max_images=50):
|
| 39 |
+
print(f"Searching for '{term}'")
|
| 40 |
+
return search_images_ddg(term, max_images)
|
| 41 |
+
|
| 42 |
+
learn = load_learner('model.pkl')
|
| 43 |
+
|
| 44 |
+
breeds = ('Labrador Retrievers','German Shepherds','Golden Retrievers','French Bulldogs','Bulldogs','Beagles','Poodles','Rottweilers','Chihuahua')
|
| 45 |
+
|
| 46 |
+
def classify_image(img):
|
| 47 |
+
pred,idx,probs = learn.predict(img)
|
| 48 |
+
#return dict(zip(breeds, map(float,probs)))
|
| 49 |
+
return "This is " + pred
|
| 50 |
+
|
| 51 |
+
image = gr.components.Image()
|
| 52 |
+
label = gr.components.Label()
|
| 53 |
+
|
| 54 |
+
examples = ['dog.jpg','labrador.jpeg','dunno.jpg']
|
| 55 |
+
|
| 56 |
+
for x in examples:
|
| 57 |
+
Image.open(x)
|
| 58 |
+
|
| 59 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 60 |
+
intf.launch(inline=False,share = True)
|