Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastbook import *
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
def classify_gender(path):
|
| 8 |
+
pattern = r"^man"
|
| 9 |
+
match = re.search(pattern, Path(path).name)
|
| 10 |
+
if match is not None and match.group() is not None:
|
| 11 |
+
if "man" in match.group():
|
| 12 |
+
return "man"
|
| 13 |
+
return "woman"
|
| 14 |
+
|
| 15 |
+
learn = load_learner("model.pkl")
|
| 16 |
+
|
| 17 |
+
genders = ("man", "woman")
|
| 18 |
+
|
| 19 |
+
def classify_image(img):
|
| 20 |
+
pred, idx, probs = learn.predict(img)
|
| 21 |
+
return dict(zip(genders, map(float, probs)))
|
| 22 |
+
|
| 23 |
+
image = gr.Image()
|
| 24 |
+
label = gr.Label()
|
| 25 |
+
|
| 26 |
+
intf = gr.Interface(fn = classify_image, inputs = image, outputs = label)
|
| 27 |
+
intf.launch(inline = False, share = True)
|