Last active
August 9, 2023 09:18
-
-
Save willezgo/2c30e77cd45ac86179d7011999843a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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