DepthEstimation / app.py
eagle0504's picture
Upload folder using huggingface_hub
556d554 verified
raw
history blame
845 Bytes
import os
import gradio as gr
import torch
import numpy as np
from transformers import pipeline
from PIL import Image
depth_estimator = pipeline(task="depth-estimation", model="Intel/dpt-hybrid-midas")
def launch(input_image):
out = depth_estimator(input_image)
# resize the prediction
prediction = torch.nn.functional.interpolate(
out["predicted_depth"].unsqueeze(1),
size=input_image.size[::-1],
mode="bicubic",
align_corners=False,
)
# normalize the prediction
output = prediction.squeeze().numpy()
formatted = (output * 255 / np.max(output)).astype("uint8")
depth = Image.fromarray(formatted)
return depth
iface = gr.Interface(launch,
inputs=gr.Image(type='pil'),
outputs=gr.Image(type='pil'))
iface.launch(share=True)