import random

# Feature lists and weights
weight_categories = ["lightweight", "average weight", "overweight", "obese"]

# Facial feature characteristics by weight
face_shapes = {
    "lightweight": ["oval face", "angular face", "long face"],
    "average weight": ["oval face", "round face", "heart-shaped face"],
    "overweight": ["round face", "square face", "soft oval face"],
    "obese": ["round face", "wide face", "full face"],
}

jawline_effects = {
    "lightweight": ["a sharp jawline", "a defined jawline", "a slightly pointed jawline"],
    "average weight": ["a balanced jawline", "a gently defined jawline", "a rounded jawline"],
    "overweight": ["a soft jawline", "a subtly defined jawline", "a slightly wide jawline"],
    "obese": ["a rounded jawline", "a double chin", "a soft, wide jawline"],
}

cheek_effects = {
    "lightweight": ["hollow cheeks", "prominent cheekbones"],
    "average weight": ["slightly prominent cheekbones", "balanced cheeks"],
    "overweight": ["full cheeks", "subtle cheekbones"],
    "obese": ["very full cheeks", "rounded cheeks", "no visible cheekbones"],
}

chin_effects = {
    "lightweight": ["a pointed chin", "a narrow chin"],
    "average weight": ["a rounded chin", "a slightly square chin"],
    "overweight": ["a rounded chin", "a slightly wide chin"],
    "obese": ["a very wide chin", "a soft, rounded chin"],
}

# Adjust existing features
facial_marks_by_weight = {
    "lightweight": ["no visible marks", "a faint scar"],
    "average weight": ["a small mole", "a faint scar", "a birthmark"],
    "overweight": ["a faint scar", "a small mole"],
    "obese": ["a birthmark", "no visible marks", "a small mole"],
}

wrinkles_by_weight = {
    "lightweight": 0.3,  # Higher likelihood due to more angular skin
    "average weight": 0.2,
    "overweight": 0.1,
    "obese": 0.05,
}

# Additional Features
hijab_probability = {
    "Middle Eastern": 0.8,  # High probability
    "African": 0.1,
    "Asian": 0.1,
    "Hispanic": 0.05,
    "Caucasian": 0.0,
}

# Disabilities and Uncommon Features
disability_features = ["no left eyebrow", "no right eyebrow", "no eyelashes", "blind in one eye", "missing eye", "facial paralysis"]
tattoo_positions = ["left temple", "left cheek", "jawline", "behind the ear"]

# Feature selection system
def select_features_with_weight():
    gender = random.choices(["male", "female"], weights=[50, 50], k=1)[0]
    ethnicity = random.choice(["Caucasian", "African", "Asian", "Hispanic", "Middle Eastern"])
    weight = random.choices(weight_categories, weights=[20, 40, 25, 15], k=1)[0]

    # Hijab logic for females
    wearing_hijab = gender == "female" and random.random() < hijab_probability[ethnicity]
   
    # Basic skin tone, hair, and other ethnicity-specific features
    skin_tone = random.choice(["fair", "medium", "tan", "dark", "olive"])
    hair_color, hair_length, hair_style = "", "", ""
    if not wearing_hijab:
        hair_color = random.choice(["black", "brown", "blonde", "red", "auburn"])
        hair_length = random.choices(
            ["short", "medium-length", "long", "shoulder-length", "buzzed"],
            weights=[20, 30, 30, 15, 5] if gender == "female" else [40, 30, 15, 10, 5],
        )[0]
        hair_style = random.choice(["straight", "wavy", "curly", "braided", "kinky"])

    # Eyes and Eyebrows
    if random.random() < 0.05:  # 5% chance to wear sunglasses, no eye feature
        eyes = "wearing sunglasses"
        eyebrows = ""
    else:
        eye_color = random.choice(["brown", "blue", "green", "gray", "hazel"])
        eye_shape = random.choice(["almond-shaped", "round", "monolid", "upturned", "downturned"])
        eyes = f"{eye_color} eyes that are {eye_shape}"
        eyebrows_thickness = random.choice(["thick", "thin", "medium", "bushy", "sparse", "feathery"])
        eyebrows_arch = random.choice(["arched", "straight", "rounded", "angled", "flat", "curved"])
        eyebrows = f"{eyebrows_thickness} eyebrows that are {eyebrows_arch}"

    # Nose, Mouth, and Disabilities
    nose_shape = random.choice(["small nose", "wide nose", "medium nose"])
    mouth = random.choice(["thin lips", "full lips", "bow-shaped lips", "pouty lips"])
    disability = random.choice(disability_features) if random.random() < 0.1 else ""

    # Facial Marks, Tattoos, Wrinkles
    facial_mark = random.choice(facial_marks_by_weight[weight])
    tattoo = random.choice(tattoo_positions) if random.random() < 0.05 else ""
    wrinkles = random.random() < wrinkles_by_weight[weight]

    # Wrinkle logic based on age, ethnicity, and weight
    if wrinkles:
        wrinkles = True
    else:
        wrinkles = False
   
    # Weight-based features: face shape, jawline, chin, cheeks
    face_shape = random.choice(face_shapes[weight])
    jawline = random.choice(jawline_effects[weight])
    cheeks = random.choice(cheek_effects[weight])
    chin = random.choice(chin_effects[weight])

    # Build prompt
    prompt = f"A {random.randint(18, 75)}-year-old {gender} of {ethnicity} ethnicity with {skin_tone} skin. "
   
    if wearing_hijab:
        prompt += f"Wearing a hijab. "
    else:
        prompt += f"{hair_length} {hair_color} {hair_style} hair. "
   
    prompt += f"{eyes}, {eyebrows}, a {nose_shape} nose, {mouth}. "
    prompt += f"{face_shape}, {jawline}, {cheeks}, {chin}. "

    if disability:
        prompt += f"Has a disability: {disability}. "
    if facial_mark:
        prompt += f"They have {facial_mark}. "
    if tattoo:
        prompt += f"Has a tattoo on {tattoo}. "
    if wrinkles:
        prompt += "They have visible wrinkles. "

    return prompt.strip()

# Generate detailed prompts
detailed_prompts = [select_features_with_weight() for _ in range(50000)]

# Save to a file
file_path = "improved_facial_description_prompts.txt"
with open(file_path, "w") as f:
    for prompt in detailed_prompts:
        f.write(prompt + "\n")

print(f"Prompts saved to {file_path}")