File size: 1,312 Bytes
244baf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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("图像保存成功!")