File size: 655 Bytes
1f7bd74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from fastbook import *
from fastai.vision.all import *
import gradio as gr

import re

def classify_gender(path):
    pattern = r"^man"
    match = re.search(pattern, Path(path).name)
    if match is not None and match.group() is not None:
        if "man" in match.group():
            return "man"
    return "woman"

learn = load_learner("model.pkl")

genders = ("man", "woman")

def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(genders, map(float, probs)))

image = gr.Image()
label = gr.Label()

intf = gr.Interface(fn = classify_image, inputs = image, outputs = label)
intf.launch(inline = False, share = True)