Skip to content

Instantly share code, notes, and snippets.

@willezgo
Last active August 9, 2023 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willezgo/2c30e77cd45ac86179d7011999843a0d to your computer and use it in GitHub Desktop.
Save willezgo/2c30e77cd45ac86179d7011999843a0d to your computer and use it in GitHub Desktop.
import requests
import os
import base64
import json
# Convert image to base64 encoded string
with open('input.png', 'rb') as image_file:
base64_image = base64.b64encode(image_file.read()).decode('utf-8')
# Prepare JSON post data
url = "https://dezgo.p.rapidapi.com/image2image"
headers = {
'X-RapidAPI-Key': os.environ.get('API_KEY'),
'X-RapidAPI-Host': 'dezgo.p.rapidapi.com',
'Content-Type': 'application/json'
}
data = {
'prompt': "Stunning portrait of a young woman, snowy background, digital art, highly-detailed masterpiece trending HQ",
'init_image': base64_image,
'strength': 0.97
}
# Make the POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Handle response
if response.status_code == 200:
print("Success! Writing output file...")
with open('output.png', 'wb') as f:
f.write(response.content)
else:
print(f"There was an error: {response.status_code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment