Spaces:
Runtime error
Runtime error
| from transformers import pipeline | |
| from PIL import Image | |
| import torch | |
| import numpy as np | |
| import gradio as gr | |
| depth_estimator = pipeline(task="depth-estimation", model="Intel/dpt-hybrid-midas") | |
| def generate_depth_image(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 | |
| demo = gr.Interface(title = "Depth Estimation of the Detected Objects in the Image - Test & Demo App by Srinivas.v..", | |
| description='Upload an image that has some vivid foreground objects and submit', | |
| fn = generate_depth_image, inputs=gr.Image(type='pil'), outputs=gr.Image(type='pil')) | |
| demo.launch(share=True,debug=True) |