testpbr / app.py
ascarlettvfx's picture
Create app.py
16e8fc9 verified
raw
history blame
1.44 kB
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()