Spaces:
Sleeping
Sleeping
Download app.py from mohaomar495/Gender-Classifier: direct link, hf CLI and curl.
- Browser
- Download file 655 Bytes
-
https://huggingface.co/spaces/mohaomar495/Gender-Classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/mohaomar495/Gender-Classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mohaomar495/Gender-Classifier/resolve/main/app.py
655 Bytes
| 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) | |