!uv pip install replicate -qDepth Map Generation
Install Dependencies
Set Replicate API Token
import sys
import os
from dotenv import load_dotenv
if 'google.colab' in sys.modules:
from google.colab import userdata # type:ignore
os.environ['REPLICATE_API_TOKEN'] = userdata.get('REPLICATE_API_TOKEN')
print("Replicate API Token set for Colab")
else:
load_dotenv()
print("Loaded env vars from .env")Input Image
from IPython.display import Image
INPUT_IMAGE = "https://raw.githubusercontent.com/simonguest/CS-394/refs/heads/main/src/04/images/campus.png"
Image(url=INPUT_IMAGE)
Image-to-Image using depth-anything-v2
import replicate
MODEL = "chenxwh/depth-anything-v2:b239ea33cff32bb7abb5db39ffe9a09c14cbc2894331d1ef66fe096eed88ebd4"
output = replicate.run(
MODEL,
input={
"image": INPUT_IMAGE,
},
)import io
from PIL import Image
output_bytes = io.BytesIO(output["grey_depth"].read())
output_image = Image.open(output_bytes)
output_image