| | import requests |
| | from PIL import Image |
| | import io |
| |
|
| | def generate_image(api_url, positive_prompt, negative_prompt=""): |
| | payload = { |
| | "positive_prompt": positive_prompt, |
| | "negative_prompt": negative_prompt, |
| | } |
| | |
| | try: |
| | response = requests.post( |
| | f"{api_url}/generate", |
| | json=payload, |
| | timeout=30 |
| | ) |
| | |
| | if response.status_code == 200: |
| | return Image.open(io.BytesIO(response.content)) |
| | else: |
| | error_info = response.json().get("detail", "Unknown error") |
| | print(f"生成失败 ({response.status_code}): {error_info}") |
| | |
| | except Exception as e: |
| | print(f"API调用异常: {str(e)}") |
| |
|
| | |
| | api_endpoint = "http://192.168.20.104:7888" |
| | image = generate_image( |
| | api_endpoint, |
| | positive_prompt="masterpiece, best quality, 1girl, (colorful),(delicate eyes and face), volumatic light, ray tracing, bust shot ,extremely detailed CG unity 8k wallpaper,solo,smile,intricate skirt,((flying petal)),(Flowery meadow) sky, cloudy_sky, moonlight, moon, night, (dark theme:1.3), light, fantasy, windy, magic sparks, dark castle,white hair", |
| | negative_prompt="blurry, low quality, text" |
| | ) |
| |
|
| | if image: |
| | image.save("generated_image.png") |
| | print("图像保存成功!") |
| |
|