AndriiPets commited on
Commit
d303376
1 Parent(s): 5e0e133

Add application file

Browse files
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. app.py +38 -0
  3. apple.jpg +0 -0
  4. lemon.jpg +0 -0
  5. model3.pk3 +3 -0
  6. requirements.txt +3 -0
  7. tomato.jpg +0 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ *.pk3 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+ from duckduckgo_search import ddg_images
4
+ from fastdownload import download_url
5
+
6
+
7
+ def find_image(img):
8
+ return L(ddg_images(img, max_results=1)).itemgot('image')
9
+
10
+
11
+ showcase_imgs = ["tomato", "apple", "lemon"]
12
+
13
+
14
+ def showcase(imgs):
15
+ for i in imgs:
16
+ url = find_image(i)
17
+ dest = f'./{i}.jpg'
18
+ download_url(url[0], dest, show_progress=False)
19
+
20
+
21
+ learner = load_learner("./model3.pk3")
22
+
23
+ labels = learner.dls.vocab
24
+
25
+
26
+ def predict(img):
27
+ img = PILImage.create(img)
28
+ pred, pred_idx, probs = learner.predict(img)
29
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
30
+
31
+
32
+ image = gr.inputs.Image(shape=(192, 192))
33
+ label = gr.outputs.Label()
34
+ examples = ['tomato.jpg', 'lemon.jpg', 'apple.jpg']
35
+
36
+ interface = gr.Interface(fn=predict, inputs=image,
37
+ outputs=label, examples=examples)
38
+ interface.launch(inline=False)
apple.jpg ADDED
lemon.jpg ADDED
model3.pk3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:27b2a78fcdb7258f270d58bebdda4834c59939b720cc39673a04596f29f42802
3
+ size 47062037
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastai
2
+ gradio
3
+ duckduckgo_search
tomato.jpg ADDED