tts-voice-creator-clone-and.../scratch/test_openai.py

25 lines
834 B
Python

import requests
import json
API_KEY = "sk-proj-jVzNl_bM-oRpR_W1F-W5bLwXQ4e38nS3pQf4eY6k2M6tX-TZA9YmH4lF" # From settings.json wait, I don't know the full key. I'll read it from settings.json
with open("config/settings.json") as f:
settings = json.load(f)
api_key = settings.get("engine_api_keys", {}).get("openai_image")
url = "https://api.openai.com/v1/images/generations"
payload = {
"model": "dall-e-3",
"prompt": "A beautiful square headshot portrait of Karyla. Style: painterly game concept art.",
"n": 1,
"size": "1024x1024"
}
headers = {'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
if response.ok:
print("Success! OpenAI generated image.")
else:
print(response.text[:500])