Spaces:
Sleeping
Sleeping
File size: 1,437 Bytes
16e8fc9 |
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 |
import gradio as gr
from gradio_client import Client, file
import numpy as np
from PIL import Image
def process_image(image):
client = Client("prs-eth/marigold")
# Convert PIL image to file-like object
image.save("/tmp/temp_image.jpg")
with open("/tmp/temp_image.jpg", "rb") as img_file:
img = file(img_file)
# Setup parameters
ensemble_size = 10
denoising_steps = 15
processing_res = "0"
match_input_res = True
color_map = None # Assuming no color map is desired
# Perform the prediction
result = client.predict(
img,
ensemble_size,
denoising_steps,
processing_res,
match_input_res,
color_map,
api_name="/submit_depth_fn"
)
# Assuming 'depth_np' is returned as a numpy array
if result and 'depth_np' in result:
# Convert numpy array back to image for display
depth_array = np.array(result['depth_np'])
depth_image = Image.fromarray((depth_array * 255).astype(np.uint8))
return depth_image
else:
raise ValueError("No valid output received or error in processing")
# Create the Gradio interface
iface = gr.Interface(
fn=process_image,
inputs=gr.inputs.Image(),
outputs=gr.outputs.Image(),
title="Depth Map Estimation",
description="Upload an image to estimate the depth map using Marigold API."
)
# Run or deploy the interface
iface.launch()
|