28 lines
2.0 KiB
Python
28 lines
2.0 KiB
Python
import requests
|
||
import urllib.parse
|
||
|
||
prompt = "创作一幅超照片级的亚洲美女单人自拍肖像,仿若用高端智能手机(如iPhone 16 Pro或同等设备)拍摄。她具有[光泽柔顺的黑色波浪长发、杏仁状深棕色眼睛带细致虹膜纹理、光滑瓷白皮肤带微妙自然瑕疵、自信迷人的微笑]。自拍在[时尚的城市屋顶夜景灯光]中拍摄。她穿着[修身丝质连衣裙带微妙领口],散发优雅且微妙的性感气质。构图模仿自然自拍角度,面部略微偏离中心,持相机角度自然讨巧,姿势优雅放松,凸显魅力。皮肤、头发和眼睛的纹理超现实,包含细致细节如单根发丝、微小皮肤毛孔和眼中真实反射。光线自然动态,带有柔和阴影和高光,模仿现实世界条件(如黄金时段阳光或室内环境光),突出她的特征。表情自信迷人,带有随性、栩栩如生的氛围。背景清晰但自然模糊(浅景深效果,f/1.8光圈)。完全避免油画感、艺术化风格、笔触、卡通化元素,不要呈现文字或任何数字瑕疵。输出为高分辨率,超详细,与真实高分辨率照片无异。"
|
||
params = {
|
||
"width": 1080,
|
||
"height": 1920,
|
||
"seed": 44,
|
||
"model": "flux",
|
||
"nologo": "true", # Optional
|
||
# "transparent": "true", # Optional - generates transparent background (gptimage model only)
|
||
# "referrer": "MyPythonApp" # Optional
|
||
}
|
||
encoded_prompt = urllib.parse.quote(prompt)
|
||
url = f"https://image.pollinations.ai/prompt/{encoded_prompt}"
|
||
|
||
try:
|
||
response = requests.get(url, params=params, timeout=300) # Increased timeout for image generation
|
||
response.raise_for_status() # Raise an exception for bad status codes
|
||
|
||
with open('generated_image.jpg', 'wb') as f:
|
||
f.write(response.content)
|
||
print("Image saved as generated_image.jpg")
|
||
|
||
except requests.exceptions.RequestException as e:
|
||
print(f"Error fetching image: {e}")
|
||
# Consider checking response.text for error messages from the API
|
||
# if response is not None: print(response.text) |