This code helps to upscale the image using the cutout.pro API. You need to install the tqdm and requests packages before running the code. The API_TOKEN_KEY is stored in the key.py file.
To install the required packages, run the following command in your terminal:
$pip install requests
$pip install tqdm
To run locally, run this command on your git bash:
Linux, Windows and macOS:
sudo git clone https://github.com/Halip26/photo_enhancer.gitcd photo_enhancerWindows:
git clone https://github.com/Halip26/photo_enhancer.gitcd photo_enhancerRun on terminal:
$python.exe .\main.pyA Python API wrapper for Enhance your pictures using cutout.pro's API.
Before running the code, make sure you have the API_TOKEN_KEY stored in the key.py file. Then, provide the path of the image file that you want to upscale in the upScaling function.
from tqdm import tqdm
import requests
from datetime import datetime
from key import API_TOKEN_KEY
def upScaling(img):
response = requests.post(
"https://www.cutout.pro/api/v1/matting2?mattingType=18",
files={"file": open(img, "rb")},
headers={"APIKEY": API_TOKEN_KEY},
stream=True,
)
total_length = int(response.headers.get("content-length", 0))
progress_bar = tqdm(total=total_length, unit="iB", unit_scale=True)
with open(
"output/hasilnya-%s.png" % datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), "wb"
) as out:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
progress_bar.update(len(chunk))
out.write(chunk)
progress_bar.close()
# Provide the path of the image to upscale
upScaling(img="img/me.jpg")This code provides a function called upScaling to upscale an image using the cutout.pro API. It uses the requests package to make a POST request to the API with the image file as input and the API token key stored in a key.py file. The code also uses the tqdm package to show a progress bar while the image is being upscaled. The output image is saved in the output folder with a timestamp appended to the filename. The code offers a usage example calling the upScaling function with an image file path.
This project is licensed under the MIT License - see the LICENSE file for details.
