Skip to content

Halip26/photo_enhancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Badge Linkedin Badge Medium Badge

Image UpScaling using cutout.pro API

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.

Installation

To install the required packages, run the following command in your terminal:

$pip install requests

$pip install tqdm

How to Use

To run locally, run this command on your git bash:

Linux, Windows and macOS:

sudo git clone https://github.com/Halip26/photo_enhancer.git
cd photo_enhancer

Windows:

git clone https://github.com/Halip26/photo_enhancer.git
cd photo_enhancer

Run on terminal:

$python.exe .\main.py

Photo Enhancer API requests

A Python API wrapper for Enhance your pictures using cutout.pro's API.

Usage

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")

Features

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.


🛠  Languages and Tools

Python 

VSCode 


Contact

  • 📫 How to reach me:   Linkedin Badge

This project is licensed under the MIT License - see the LICENSE file for details.

About

Image UpScaling using cutout.pro API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages