Example 1: create a yearbook photo for anyone
Required inputs:
To generate the desired image, it requires two API calls: 1) create the task 2) fetch the result.
Step 1: calling endpoint /GenerateAvatar to start the generation.
Choose python code as example by replacing the promptPositive field with your own prompt and controlSource pointing to your reference image. Please insert YOUR-OWN-API-KEY as well:
url = "https://realm-generation.p.rapidapi.com/generation"
payload = {
"promptPositive": "@character model student high quality hd, a single yearbook photograph, dark-blue cloudy backdrop, full portrait style",
"cfgScale": 7.5,
"samlplingSteps": 30,
"controlType": "FACE_FEATURE",
"controlSource": "https://d28hgpri8am2if.cloudfront.net/book_images/onix/cvr9781982181284/elon-musk-9781982181284_lg.jpg"
}
headers = {
"content-type": "application/json",
"X-RapidAPI-Key": "YOUR-OWN-API-KEY",
"X-RapidAPI-Host": "realm-generation.p.rapidapi.com"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
This will return the corresponding task id:
{ "promptID": "AOnRQMk1dpkhAsQ4cnZY" }
Step 2: fetch the generated image using returned prompt ID (recommended: every 10 seconds, with timeout 2 minutes)
import requests
import time
url = "https://realm-generation.p.rapidapi.com/generation/AOnRQMk1dpkhAsQ4cnZY"
headers = {
"X-RapidAPI-Key": "YOUR-OWN-API-KEY",
"X-RapidAPI-Host": "realm-generation.p.rapidapi.com"
}
start_time = time.time() # Record the start time
timeout = 120 # Timeout in seconds (2 minutes)
while True:
response = requests.get(url, headers=headers)
print(response.json())
# Check if 2 minutes have passed
if time.time() - start_time > timeout:
print("Timeout reached. Exiting.")
break
# Wait for 10 seconds before the next check
time.sleep(10)