Commit
·
bc9faa1
1
Parent(s):
2c82204
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def label_func(fname):
|
5 |
+
if int(str(fname)[str(fname).index('_')+1]) == 0:
|
6 |
+
return "Male"
|
7 |
+
return "Female"
|
8 |
+
|
9 |
+
learn = load_learner('gender.pkl')
|
10 |
+
|
11 |
+
categories = ('Female', 'Male')
|
12 |
+
|
13 |
+
def classify_image(img):
|
14 |
+
pred, idx, probs = learn.predict(img)
|
15 |
+
return dict(zip(categories, map(float, probs)))
|
16 |
+
|
17 |
+
image = gr.inputs.Image(shape=(192,192))
|
18 |
+
label = gr.outputs.Label()
|
19 |
+
examples = ['Male.jpg', 'Female.jpg']
|
20 |
+
|
21 |
+
|
22 |
+
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
23 |
+
iface.launch()
|