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