Files
abot/utils/ai/pollinations_ai.py
2025-06-06 17:46:10 +08:00

28 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)