DanielV commited on
Commit
70feaf9
·
1 Parent(s): ccfdd57

trained model, examples & app

Browse files
Files changed (5) hide show
  1. app.py +32 -7
  2. examples/kairi.jpg +0 -0
  3. examples/riku.jpg +0 -0
  4. examples/sora.jpg +0 -0
  5. model.pkl +3 -0
app.py CHANGED
@@ -1,7 +1,32 @@
1
- import gradio as gr
2
-
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
-
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision import *
2
+ from fastai.learner import load_learner
3
+ from PIL import Image
4
+ import gradio as gr
5
+
6
+ image = Image.open("examples/riku.jpg")
7
+ image.thumbnail((512,512))
8
+ image
9
+
10
+ learn = load_learner("model.pkl")
11
+ categories = list(learn.dls.vocab)
12
+
13
+
14
+ result,_,probs = learn.predict(image)
15
+ print(f"This is a: {result}")
16
+ print(f"Probability it's a {result}: {probs[categories.index(result)] * 100:.02f}%")
17
+
18
+ def classify_image(img):
19
+ pred, ix, probs = learn.predict(img)
20
+ return dict(zip(categories, map(float, probs)))
21
+
22
+ print(classify_image(image))
23
+
24
+ # Whats the gradio input type? Image
25
+ image = gr.inputs.Image(shape=(192,192))
26
+ # Whats the gradio output type? Label
27
+ label = gr.outputs.Label()
28
+ # Set up some examples
29
+ examples = ["examples/kairi.jpg", "examples/riku.jpg", "examples/sora.jpg"]
30
+
31
+ intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
32
+ intf.launch(inline=False)
examples/kairi.jpg ADDED
examples/riku.jpg ADDED
examples/sora.jpg ADDED
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:114d2aedff2138e929a95274626586f15e8691460a67acd82f89bd71c4749f7f
3
+ size 46971417