Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,34 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
|
4 |
+
# Load the trained model
|
5 |
+
learn = load_learner('clocker.pkl')
|
6 |
|
7 |
+
def guess_if_she_is_trans(img):
|
8 |
+
# Predict if the woman is transgender
|
9 |
+
pred, _, probs = learn.predict(img)
|
10 |
+
|
11 |
+
# Create definitions for gender probability
|
12 |
+
transgender_probs = {learn.dls.vocab[i]: float(probs[i]) for i in range(len(learn.dls.vocab))}
|
13 |
+
|
14 |
+
# Return the predicted gender and probabilities
|
15 |
+
return pred, transgender_probs
|
16 |
+
|
17 |
+
# Create the Gradio interface
|
18 |
+
demo = gr.Interface(
|
19 |
+
fn=guess_if_she_is_trans,
|
20 |
+
inputs=gr.Image(type="pil"),
|
21 |
+
outputs=[
|
22 |
+
gr.Label(num_top_classes=1, label="My guess..."),
|
23 |
+
gr.Label(num_top_classes=5, label="Transfem probability")
|
24 |
+
],
|
25 |
+
examples=[
|
26 |
+
["average_woman.jpg"],
|
27 |
+
["transgender_woman.jpg"]
|
28 |
+
],
|
29 |
+
title="Transfem Clocker",
|
30 |
+
description="Upload a photo of a woman and this will guess if she's trans."
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the interface
|
34 |
demo.launch()
|