mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
9b42ba8f10
* changes * changes * revert changes * changes * add changeset * notebooks script * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
73 lines
1.6 KiB
Python
73 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()
|