mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-01 11:45:36 +08:00
* stuff * fix layrs * add changeset * lint * ensure a default image can be passed when sources list is empty * fix loading status * add layers option to disable layer ui * types * fix tests * cleanup * cleanup * notebooks * fix composite * fix * fix trash icon * add changeset * fix layer bg * fix error display * notebooks --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
77 lines
1.6 KiB
Python
77 lines
1.6 KiB
Python
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()
|