huntrezz commited on
Commit
b4bf09d
·
verified ·
1 Parent(s): f2ec343

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -1,34 +1,26 @@
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()
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
 
4
+ # Load the exported model
5
  learn = load_learner('clocker.pkl')
6
 
7
+ def classify_image(img):
8
+ # Make a prediction
9
+ pred, idx, probs = learn.predict(img)
10
+ return {
11
+ "average woman": float(probs[0]),
12
+ "transgender woman": float(probs[1])
13
+ }
 
 
14
 
15
  # Create the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=classify_image,
18
+ inputs=gr.Image(),
19
+ outputs=gr.Label(num_top_classes=2),
20
+ title="Woman Type Classifier",
21
+ description="Upload an image to classify whether it's an average woman or a transgender woman.",
22
+ examples=["average_woman.jpg"]
 
 
 
 
 
 
23
  )
24
 
25
  # Launch the interface
26
+ iface.launch()