美女一键即可生成,你也可以,开源的,拿去随便玩!
https://download.csdn.net/download/u013177034/90487548
# 首先,确保安装好了以下依赖(建议用 Colab 或虚拟环境跑)
# pip install diffusers transformers accelerate safetensors torch torchvision
from diffusers import StableDiffusionPipeline
import torch
import os
from PIL import Image
from datetime import datetime
# Step 1: 加载预训练模型(HuggingFace上的高质量AI美女模型)
model_id = "Linaqruf/anything-v5" # or try chilloutmix/NaiDiffusion/majicMIX
pipe = StableDiffusionPipeline.from_pretrained(
model_id,
torch_dtype=torch.float16,
revision="fp16",
safety_checker=None, # ❗去掉NSFW屏蔽器(否则啥都生成不了)
requires_safety_checker=False
).to("cuda")
# Step 2: 写一个美女关键词Prompt(核心提示词,直接决定图的质量)
prompt = (
"masterpiece, best quality, ultra-detailed, 1girl, solo, "
"beautiful face, long hair, white skin, large eyes, "
"smile, soft lighting, photorealistic, looking at viewer, "
"ultra-HD, symmetrical face, depth of field"
)
# Step 3: 添加负面提示词(避免AI画出奇怪的脸、六根手指)
negative_prompt = (
"lowres, bad anatomy, bad hands, cropped, worst quality, "
"low quality, blurry, mutated, extra fingers, deformed face"
)
# Step 4: 生成图片(可以循环批量生成)
image = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=7.5,
num_inference_steps=30,
).images[0]
# Step 5: 保存图像(自动保存为当前时间命名的jpg图)
os.makedirs("outputs", exist_ok=True)
filename = datetime.now().strftime("ai_beauty_%Y%m%d_%H%M%S.jpg")
save_path = os.path.join("outputs", filename)
image.save(save_path)
print(f"✅ 美女图已生成并保存在:{save_path}")
# ✅ 到此,AI美女图一键搞定!
类型 | 正向提示词(Prompt) | 负向提示词(Negative Prompt) |
---|---|---|
清纯少女风 | 1girl, school uniform, soft light | blurry, ugly, extra limbs |
性感御姐风 | mature, red lips, cleavage, seductive pose | loli, childish, bad anatomy |
写实风格 | photorealistic, sharp detail, ultra hd | cartoonish, sketch, out of focus |
二次元动漫风 | anime style, big eyes, glowing hair | low quality, 3D style, ugly fingers |