This page describes how to interact with the Image Upscaling, Background Removal, Text-to-Speech, and Flux Style APIs. The following Python code samples demonstrate how to use these endpoints.
You can copy this code right into your program and test it out (but change the client id). The daily free quota applies to all requests. You can run this code as a notebook here.
Your client id is your secret identifier. Use a random client id to avoid collisions with other users!
!wget https://image-upscaling.net/assets/images/test_image.jpg
import requests
import json
serverurl = "https://image-upscaling.net"
client_id = "1234567890asdfghjklqwertzUIOPYXC"
cookies = { "client_id": client_id }
use_face_enhance = False
scale = 4
path = "test_image.jpg"
url = "/".join([serverurl, "upscaling_upload"])
data = {"scale": scale}
if use_face_enhance:
data["fx"] = ""
files = {"image": open(path, "rb")}
response = requests.post(url, data=data, files=files, cookies=cookies)
print(response.text)
url = "/".join([serverurl, "upscaling_get_status"])
response = requests.get(url, cookies=cookies)
print(response.json())
while True:
url = "/".join([serverurl, "upscaling_get_status"])
response = requests.get(url, cookies=cookies).json()
for url in response["processed"]:
filename = url.split("/")[-1]
params = {"delete_after_download": ""}
content = requests.get(url, cookies=cookies, params=params).content
with open(filename, "wb") as f:
f.write(content)
if not response["pending"] and not response["processing"] and not response["processed"]:
break
else:
import time
time.sleep(1)
url = "/".join([serverurl, "removebg_upload"])
files = {"image": open("test_image.jpg", "rb")}
response = requests.post(url, files=files, cookies=cookies)
print(response.text)
while True:
url = "/".join([serverurl, "removebg_get_status"])
response = requests.get(url, cookies=cookies).json()
for url in response["processed"]:
filename = url.split("/")[-1]
params = {"delete_after_download": ""}
content = requests.get(url, cookies=cookies, params=params).content
with open(filename, "wb") as f:
f.write(content)
if not response["pending"] and not response["processing"] and not response["processed"]:
break
else:
import time
time.sleep(1)
url = "/".join([serverurl, "tts_submit"])
data = {
"text": "This is the text to speech api",
"voice": "am_michael",
"speed": 1.1
}
response = requests.post(url, json=data, cookies=cookies)
print(response.text)
while True:
url = "/".join([serverurl, "tts_get_data"])
response = requests.get(url, cookies=cookies).json()
for element in response:
url = element["result"]
if url != "":
print(url)
params = {"delete_after_download": ""}
content = requests.get(url, params=params, cookies=cookies).content
with open(url.split("/")[-1] + ".mp3", "wb") as f:
f.write(content)
if not response:
break
else:
import time
time.sleep(1)
The Flux Editor API allows you to apply various styles to images. The process is divided into two main parts: first you generate or upload an image, then you submit a job to process the selected image.
Upload an image that will be automatically selected for processing.
path = "test_image.jpg"
url = "/".join([serverurl, "iedit_upload"])
files = {"image": open(path, "rb")}
response = requests.post(url, files=files, cookies=cookies)
print(response.text)
# Output: image uploaded
Check the status of your images and see which one is currently selected. The uploaded image will be selected automatically.
url = "/".join([serverurl, "iedit_get_status"])
response = requests.get(url, cookies=cookies).json()
print(response)
# Output example:
# {'entries': [{'req_id': 1755256007178,
# 'result': 'http://image-upscaling.net/iedit_download_data/1755256007178',
# 'status': 0,
# 'text': ''}],
# 'selected': 1755256007178}
To change which image is selected for processing, use the following endpoint. You can provide a request ID or -1 to clear the canvas.
req_id = "1755256007178" # or -1 to clear canvas
url = "/".join([serverurl, "iedit_set_selected"])
params = {"req_id": req_id}
response = requests.get(url, params=params, cookies=cookies)
print(response.text)
Submit a job to apply a style to the currently selected image.
url = "/".join([serverurl, "iedit_submit_job"])
data = {
"model": "style", # select style model
"selectedStyle": "Oil_Painting" # select the desired style
}
request_id = requests.post(url, data=data, cookies=cookies).text
print(request_id)
# Output example: 1755256008533
Check if your style processing job is complete. Status 0 means processed, status 1 means still processing.
url = "/".join([serverurl, "iedit_get_status"])
data = requests.get(url, cookies=cookies).json()
entries = data['entries']
for entry in entries:
if entry['req_id'] == int(request_id):
print(entry)
if entry['status'] == 0:
print("the image is processed")
else:
print("the image is processing")
# Output example:
# {'req_id': 1755256008533, 'result': 'http://image-upscaling.net/iedit_download_data/1755256008533?get_input_image=True', 'status': 1, 'text': 'Turn this image into the Oil Painting style.'}
# the image is processing
A helper function to wait for processing to complete and download the result.
import time
def wait_and_download(request_id, filename):
while True:
url = "/".join([serverurl, "iedit_get_status"])
data = requests.get(url, cookies=cookies).json()
entries = data['entries']
for entry in entries:
if entry['req_id'] == int(request_id):
if entry['status'] == 0:
print("the image is processed")
url = entry['result']
response = requests.get(url, cookies=cookies)
with open(filename, "wb") as f:
f.write(response.content)
return
time.sleep(1)
# Usage example
filename = "test_image_processed.jpg"
wait_and_download(request_id, filename)
# Output: the image is processed
If you're using this in a Jupyter notebook, you can display the result:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread(filename)
imgplot = plt.imshow(img)
plt.show()
url = "/".join([serverurl, "get_account_info"])
response = requests.get(url, cookies=cookies).json()
print(response)
# {'balance': 361.1489, 'client_id': 'af25d8e9971a747bf55c17195f39757a', 'email': 'marvineckhardt04092003@gmail.com', 'has_free_quota_left': False, 'ip': '35.221.153.79', 'quota_free': 0.2, 'quota_used': 0.3765}
/account?client_id=xxxxxwith a valid client id and it will make the browser switch to the given client id.