Views
No views yet
1import requests
2import base64
3
4# Load your image
5with open("person.jpg", "rb") as f:
6 id_image_b64 = base64.b64encode(f.read()).decode()
7
8# Call endpoint
9response = requests.post(
10 "https://YOUR-ENDPOINT.endpoints.huggingface.cloud",
11 headers={"Authorization": "Bearer YOUR_HF_TOKEN"},
12 json={
13 "inputs": {
14 "prompt": "A sophisticated gentleman in a business suit",
15 "id_image": f"data:image/jpeg;base64,{id_image_b64}",
16 "seed": 42,
17 "width": 864,
18 "height": 1152,
19 "guidance_scale": 3.5,
20 "num_steps": 30,
21 "enable_realism": True,
22 "enable_anti_blur": False,
23 "model_version": "aes_stage2"
24 }
25 }
26)
27
28# Get the generated image
29if response.status_code == 200:
30 result = response.json()
31 if result.get("success"):
32 # Decode base64 image
33 import base64
34 from PIL import Image
35 import io
36
37 image_data = base64.b64decode(result["image"])
38 image = Image.open(io.BytesIO(image_data))
39 image.save("generated_image.png")
40 print("Image saved as generated_image.png")
41 else:
42 print(f"Error: {result.get('error')}")
43else:
44 print(f"Request failed with status {response.status_code}")prompt (required): Text description of the desired imageid_image (required): Base64-encoded image of the person whose identity to preserveseed (optional): Random seed for reproducible results (default: 0 for random)width (optional): Output image width (default: 864)height (optional): Output image height (default: 1152)guidance_scale (optional): Guidance scale for generation (default: 3.5)num_steps (optional): Number of inference steps (default: 30)enable_realism (optional): Enable realism LoRA (default: True)enable_anti_blur (optional): Enable anti-blur LoRA (default: False)model_version (optional): Model version to use - "sim_stage1" or "aes_stage2" (default: "aes_stage2")download_models.py locally to download all required modelsgit lfs installdownload_models.py: