File size: 1,870 Bytes
4ba40aa
 
637eff3
4ba40aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637eff3
4ba40aa
 
 
 
 
 
 
637eff3
4ba40aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os

import numpy as np
import requests
import base64
from PIL import Image
import io

# URL del endpoint proporcionado por Hugging Face
# ENDPOINT_URL = "https://qh7glc3xj9iw4tk2.eu-west-1.aws.endpoints.huggingface.cloud"
ENDPOINT_URL = os.environ.get("ENDPOINT_URL", "")
# Token de API de Hugging Face
# API_TOKEN = "hf_..."
API_TOKEN = os.environ.get("API_TOKEN", "")
headers = {
    "Authorization": f"Bearer {API_TOKEN}",
    "Content-Type": "application/json"
}

# Cargar y codificar una imagen
# image = Image.open("mine.jpeg")
# buffered = io.BytesIO()
# image.save(buffered, format="JPEG")
# img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")

# Preparar los datos para la solicitud
# payload = {
#     "inputs"       : {
#
#     },
#     "file"         : img_str,
#     "visualization": True
# }

#----------------------------------------------------------------------------------
points = [[0, 0]]
# Preparar los datos para la solicitud
payload = {
    "inputs"       : {

    },
    "url"          : "https://images.unsplash.com/photo-1586023492125-27b2c045efd7?fm=jpg&q=60&w=3000&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8aW50ZXJpb3IlMjBkZXNpZ258ZW58MHx8MHx8fDA%3D",
    # "visualization": False,
    "points": points

}



# Enviar la solicitud
response = requests.post(ENDPOINT_URL, headers=headers, json=payload)

# Procesar la respuesta
if response.status_code == 200:
    result = response.json()
    if "visualization" in result:
        # Decodificar y guardar la visualización
        vis_bytes = base64.b64decode(result["visualization"])
        with open("depth_visualization.png", "wb") as f:
            f.write(vis_bytes)
        print("Visualización guardada como 'depth_visualization.png'")
    print(f"Profundidad: {result.get('deph')}")

else:
    print(f"Error: {response.status_code}")
    print(response.text)