forked from andrzejdambski/colorizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorize_local.py
More file actions
37 lines (29 loc) · 1.13 KB
/
Copy pathcolorize_local.py
File metadata and controls
37 lines (29 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
import io
import sys
import requests
from PIL import Image
BASE_URL = "https://colorizer-api-847420607839.europe-west1.run.app"
def colorize_image(input_path: str, output_path: str):
# 1. Lire l'image en binaire
with open(input_path, "rb") as f:
files = {"file": (input_path, f, "image/jpeg")} # ou image/png, peu importe
# 2. Envoyer la requête POST /colorize
url = f"{BASE_URL}/colorize"
response = requests.post(url, files=files)
# 3. Vérifier la réponse
if response.status_code != 200:
print("Erreur de l'API :", response.status_code, response.text)
return
# 4. Convertir le contenu binaire en image PIL
image_bytes = io.BytesIO(response.content)
img = Image.open(image_bytes).convert("RGB")
# 5. Sauvegarder le résultat
img.save(output_path)
print(f"Image colorisée sauvegardée dans : {output_path}")
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage : python colorize_local.py input.jpg output.png")
sys.exit(1)
input_path = sys.argv[1]
output_path = sys.argv[2]
colorize_image(input_path, output_path)