import os
import gradio as gr
read_key = os.getenv('HUGGINGFACE_TOKEN')
client = Client("Albert-NHWang/Depth-Anywhere", hf_token=read_key)
def get_example():
case = [
[
'examples/small_nthu_assembly.jpg'
],
[
'examples/small_Luca_Biada_flickr_2.jpg'
],
[
'examples/small_Dominic_Alves_flickr_panohead_test.jpg'
],
[
'examples/small_Luca_Biada_flickr.jpg'
],
]
return case
def depth(path):
depth_path = client.predict(handle_file(path), api_name='/process_image')
return depth_path
intro = """
Depth Anywhere: Enhancing 360 Monocular Depth Estimation via Perspective Distillation and Unlabeled Data Augmentation
[Project page], [Paper], [Hugging Face Daily Paper]
Please test with browsers other then Safari, and avoid using incognito window due to unsolved gradio bug!
"""
footnote = """
Dominic Alves, https://www.flickr.com/photos/dominicspics/28296671029/, CC BY 2.0 DEED
Luca Biada, https://www.flickr.com/photos/pedroscreamerovsky/6873256488/, CC BY 2.0 DEED
Luca Biada, https://www.flickr.com/photos/pedroscreamerovsky/6798474782/, CC BY 2.0 DEED
"""
with gr.Blocks(css="style.css") as demo:
gr.HTML(intro)
with gr.Row():
input_image = gr.File(type="filepath")
output_rgb = gr.Image(label="Loaded Image", type="filepath")
with gr.Row():
load_button = gr.Button("Load RGB!", visible=True)
load_button.click(fn = lambda x: x,
inputs = [input_image],
outputs = [output_rgb]
)
with gr.Row():
output_image = gr.Image(label="Output Depth", type="filepath")
with gr.Row():
run_button = gr.Button("Estimate Depth!", visible=True)
run_button.click(fn = depth,
inputs = [input_image],
outputs = [output_image]
)
gr.Examples(
fn=lambda x:x,
inputs=[input_image],
outputs=[output_rgb],
examples=get_example(),
run_on_click=True,
cache_examples=False)
gr.HTML(footnote)
demo.queue()
demo.launch()