File size: 969 Bytes
a72ba2e
2228f87
a72ba2e
a88b46b
 
a72ba2e
a88b46b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a72ba2e
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
29
30
31
32
33
34
import gradio as gr
from fastai.vision.all import *

# Load the trained model
learn = load_learner('clocker.pkl')

def guess_if_she_is_trans(img):
    # Predict if the woman is transgender
    pred, _, probs = learn.predict(img)
    
    # Create definitions for gender probability
    transgender_probs = {learn.dls.vocab[i]: float(probs[i]) for i in range(len(learn.dls.vocab))}
    
    # Return the predicted gender and probabilities
    return pred, transgender_probs

# Create the Gradio interface
demo = gr.Interface(
    fn=guess_if_she_is_trans,
    inputs=gr.Image(type="pil"),
    outputs=[
        gr.Label(num_top_classes=1, label="My guess..."),
        gr.Label(num_top_classes=5, label="Transfem probability")
    ],
    examples=[
        ["average_woman.jpg"],
        ["transgender_woman.jpg"]
    ],
    title="Transfem Clocker",
    description="Upload a photo of a woman and this will guess if she's trans."
)

# Launch the interface
demo.launch()