async def generate_t2i_image(prompt: str) -> str:
"""
Generates an image from a text prompt using Truepix AI.
"""
api_url = "https://api.truepix.ai" # Coming SOON
headers = {"Authorization": "Bearer YOUR_API_KEY"}
payload = {"prompt": prompt}
try:
async with aiohttp.ClientSession() as session:
# Start image generation
async with session.post(api_url, json=payload, headers=headers) as response:
if response.status != 200:
return f"Error: Status {response.status}"
data = await response.json()
task_id = data.get("task_id")
if not task_id:
return "Error: No task ID"
# Check progress every 10 seconds
while True:
poll_url = f"https://api.truepix.ai" # Coming SOON
async with session.get(poll_url, headers=headers) as poll_response:
if poll_response.status != 200:
return f"Error: Status {poll_response.status}"
result = await poll_response.json()
if result.get("status") == "success":
return result.get("result_url", "Error: No URL")
await asyncio.sleep(10)
except Exception as e:
return f"Error: {str(e)}"
No comments:
Post a Comment