File size: 1,511 Bytes
9bb097c
 
 
16dd9ce
 
 
f034348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16dd9ce
f034348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
# Temporary fix to install other requirements requirements here
# Pip needs to be ugraded on Hugging Face spaces before installing the library
import os 
os.system("pip install --upgrade pip")
os.system("pip install umap-learn bechdelai==0.0.1a2")

import gradio as gr
import os

from bechdelai.image.face_detection import FacesDetector
from bechdelai.image.gender_detection import GenderDetector
from bechdelai.image.vilt import ViLT
from bechdelai.image.img import Img

fd = FacesDetector()
gd = GenderDetector()

examples_path = "static/examples"
examples_images = [os.path.join(examples_path,x) for x in os.listdir(examples_path)]

def analyze_genders(img):
    rois,faces = fd.detect(img,method = "retinaface",padding = 20)
    probas = gd.predict(faces)
    results,metrics = gd.analyze_probas(probas)
    img_with_faces = fd.show_faces_on_image(img,rois,width = 3,genders = probas["gender"])

    new_metrics = {"Space occupied by women":metrics["women_area"],"Space occupied by men":metrics["men_area"]}

    return new_metrics, img_with_faces


demo = gr.Interface(
    fn = analyze_genders, 
    inputs = gr.Image(), 
    outputs = [
        gr.outputs.Label(num_top_classes=3),
        "image",
    ],
    examples=examples_images,
    title="BechdelAI Tool - Image Analysis",
    description="BechdelAI automates the Bechdel test and study of women under-representation in cinema and media with AI",
    article="For more information visit https://github.com/dataforgoodfr/bechdelai"
)
demo.launch()