-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (32 loc) · 1.13 KB
/
Copy pathmain.py
File metadata and controls
43 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
from key import API_TOKEN_KEY
import sys
from datetime import datetime
# taqaddum, which means 'progress'.
from tqdm import tqdm
def upScaling(img):
response = requests.post(
"https://www.cutout.pro/api/v1/photoEnhance",
files={"file": open(img, "rb")},
headers={"APIKEY": API_TOKEN_KEY},
stream=True, # Enable streaming response content
)
# get response content length in bytes
total_length = int(response.headers.get("content-length", 0))
# create progress bar
progress_bar = tqdm(total=total_length, unit="iB")
if response.status_code == requests.codes.ok:
with open(
"output/result-%s.png" % datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), "wb"
) as out:
for i in response.iter_content(chunk_size=1024):
if i:
# update progress bar
progress_bar.update(len(i))
out.write(i)
else:
print("Error:", response.status_code, response.text)
# close progress bar after download
progress_bar.close()
image_path = sys.argv[1]
upScaling(image_path)