Spaces:
Running
Running
File size: 2,156 Bytes
7c1d5cc 38e7962 7c1d5cc 38e7962 7c1d5cc 38e7962 4530931 476cd3a 7c1d5cc 476cd3a a47fb29 7c1d5cc 38e7962 7c1d5cc a47fb29 7c1d5cc 476cd3a 7c1d5cc 476cd3a 7c1d5cc 4530931 7c1d5cc a47fb29 7c1d5cc 476cd3a 7c1d5cc | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import gradio as gr
from pathlib import Path
dir_ = Path(__file__).parent
def predict(im):
print(im)
return im, len(im["layers"])
with gr.Blocks() as demo:
with gr.Row():
im = gr.ImageEditor(
type="numpy",
interactive=True,
)
im_preview = gr.ImageEditor(
interactive=True,
)
layer_updates = gr.Textbox(value="", label="Layer Updates")
num_layers = gr.Number(value=0, label="Num Layers")
example_ran = gr.Number(value=0, label="Example Ran")
set_background = gr.Button("Set Background")
set_background.click(
lambda: {
"background": str(dir_ / "cheetah.jpg"),
"layers": None,
"composite": None,
},
None,
im,
show_progress="hidden",
)
set_layers = gr.Button("Set Layers")
set_layers.click(
lambda: {
"background": None,
"layers": [str(dir_ / "cheetah.jpg")],
"composite": None,
},
None,
im,
show_progress="hidden",
)
im.change(
lambda x: len(x["layers"]),
inputs=im,
outputs=layer_updates,
)
set_composite = gr.Button("Set Composite")
set_composite.click(
lambda: {
"background": None,
"layers": None,
"composite": "https://huggingface.co/datasets/freddyaboulton/bucket/resolve/main/cheetah-003.jpg",
},
None,
im,
show_progress="hidden",
)
get_layers = gr.Button("Get Layers")
get_layers.click(
predict,
outputs=[im_preview, num_layers],
inputs=im,
)
gr.Examples(
examples=[
"https://huggingface.co/datasets/freddyaboulton/bucket/resolve/main/TheCheethcat.jpg",
{
"background": str(dir_ / "cheetah.jpg"),
"layers": [str(dir_ / "layer1.png")],
"composite": None,
},
],
inputs=im,
outputs=[example_ran],
fn=lambda x: 1,
run_on_click=True,
)
if __name__ == "__main__":
demo.launch()
|