File size: 3,964 Bytes
0b2c1a2
5fe576f
0b2c1a2
5fe576f
 
13158ba
744b826
 
 
 
 
 
 
 
 
 
 
 
13158ba
744b826
43deb92
5fe576f
13158ba
 
 
 
 
 
 
 
5fe576f
 
 
 
0b2c1a2
e1ab2b1
1b79434
a3ed1cd
b5270a2
1b79434
b5270a2
13158ba
 
 
a3ed1cd
34f82b4
13158ba
 
744b826
13158ba
 
 
 
9416c43
e1ab2b1
1b79434
 
 
744b826
 
 
 
 
 
 
 
 
e1ab2b1
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
import requests

url = "https://api.newnative.ai/stable-diffusion?prompt="

def run(gender, height, weight, age, ethnicity, skin_color, hair_length, hair_color, eye_color, facial_hair, facial_hair_color):
    bmi = weight/(height/100)**2

    if bmi < 18.5:
        bodyShape = "slim"
    elif bmi < 25:
        bodyShape = "average" 
    elif bmi < 30:
        bodyShape = "overweight"
    else:
        bodyShape = "obese"

    prompt = f"""mugshot portrait, {age + " " if age else ""}{bodyShape} {skin_color} {ethnicity} {gender}{" with " + hair_length if hair_length else ""} {hair_color + " hair, " if hair_length and hair_color else ""}{eye_color + " eyes, " if eye_color else ""}{facial_hair_color + " " if facial_hair and facial_hair_color else ""}{facial_hair+ ", " if facial_hair else ""}canon EOS"""
    
    print (prompt.lower())
    return getImage(prompt.lower())

def getHeightInFeet(height):
    feet = height*0.0328084
    inches = (feet - int(feet))*0.393701
    return str(int(feet)) + "'" + str(int(inches)) + '"'

def getWeightInPounds(weight):
    return str(int(weight*2.20462)) + " lbs"
    
def getImage(prompt):
    r = requests.get(url + prompt)
    data = r.json()
    return(data["image_url"])

demo = gr.Interface(
    fn = run,
    article = "<p>For better accuracy, please enter all the information about the person you want to generate a portrait for.</p><h3>Biases and content acknowledgment</h3><p>Beware to the fact that this is a pre-trained model that may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the LAION-5B dataset, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes.</p><p>You can read more in the model card <a href=\"https://huggingface.co/CompVis/stable-diffusion-v1-4\" target=\"_blank\">HERE.</a></p>"
        ,
    inputs = [
        
        gr.Radio(["Male", "Female"], label="Gender" ),  #Gender
        gr.Slider(100,250,value=160, label="Height (cm)"), #Height
        gr.Slider(40,250,value=50, label="Weight (kg)"), #Weight
        gr.Radio(["Young", "Adult", "Middle-aged", "Old"], label="Age" ), #Age
        gr.Dropdown(sorted(["South Asian", "North Asian", "White", "African American", "American Indian", "Hispanic", "Latin"]), label="Race"), #Race
        gr.Dropdown(sorted(["Black", "Brown", "Yellow", "Peach","Tan","Beige", "White", "Grey"]), label="Skin color" ), #Skin color
        gr.Radio(sorted(["Short", "Long", "Bald", "Medium"]), label="Hair length" ), #Hair length
        gr.Dropdown(sorted(["Black","Dark Brown", "Light Brown", "Blond", "Red", "Grey"]), label="Hair color" ), #Hair color
        gr.Dropdown(sorted(["Black", "Dark Brown", "Light Brown", "Green", "Blue", "Hazel", "Amber", "Red", "Pink"]), label="Eye color" ), #Eye color
        gr.Radio(sorted(["Mustache", "Beard", "Unibrow"]), label="Facial hair" ), #Facial hair
        gr.Dropdown(sorted(["Ginger", "Black", "Brown", "Grey", "Yellow", "White"]), label="Facial hair color" ), #facial hair color
        # gr.CheckboxGroup(["Nose", "Ear", "Eyebrow", "Lips", "Cheeks"], label="Piercings"),
        #gr.Checkbox(label="Is it the morning?"),
    ],
    outputs = "image",
    title = "AI Portrait Generator",
    description = "Generate a portrait of a person with the given attributes",
    examples=[
        ["Male", 180, 80, "Adult", "White", "White", "Short", "Blond", "Blue", "Mustache", "Ginger"],
        ["Male", 160, 50, "Young", "Latin", "Brown", "Medium", "Dark Brown", "Dark Brown", "Beard", "Brown"],
        ["Female", 150, 70, "Old", "South Asian", "White", "Long", "Black", "Light Brown", "Unibrow", "Brown"],
        ["Female", 170, 60, "Middle-aged", "African american", "Black", "Medium", "Black", "Black", None, None],

    

    ],
)

if __name__ == "__main__":
    demo.launch()