File size: 1,756 Bytes
0bd62e5 |
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 |
import gradio as gr
from pathlib import Path
dir_ = Path(__file__).parent
def predict(im):
return im
with gr.Blocks() as demo:
with gr.Row():
im = gr.ImageEditor(
type="numpy",
interactive=True,
)
im_preview = gr.ImageEditor(
interactive=True,
)
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": str(dir_ / "cheetah.jpg"),
"layers": [str(dir_ / "layer1.png")],
"composite": None,
},
None,
im,
show_progress="hidden",
)
set_composite = gr.Button("Set Composite")
set_composite.click(
lambda: {
"background": None,
"layers": None,
"composite": "https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg",
},
None,
im,
show_progress="hidden",
)
im.change(
predict,
outputs=im_preview,
inputs=im,
)
gr.Examples(
examples=[
"https://upload.wikimedia.org/wikipedia/commons/0/09/TheCheethcat.jpg",
{
"background": str(dir_ / "cheetah.jpg"),
"layers": [str(dir_ / "layer1.png")],
"composite": None,
},
],
inputs=im,
)
if __name__ == "__main__":
demo.launch()
|