Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
-
sdk_version: 5.
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
|
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 5.24.0
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
run.ipynb
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: image_editor_layers"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/cheetah.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/layer1.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "dir_ = Path(__file__).parent\n", "\n", "def predict(im):\n", " return im, len(im[
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: image_editor_layers"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/cheetah.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/image_editor_layers/layer1.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "dir_ = Path(__file__).parent\n", "\n", "\n", "def predict(im):\n", " print(im)\n", " return im, len(im[\"layers\"])\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " im = gr.ImageEditor(\n", " type=\"numpy\",\n", " interactive=True,\n", " )\n", " im_preview = gr.ImageEditor(\n", " interactive=True,\n", " )\n", "\n", " layer_updates = gr.Textbox(value=\"\", label=\"Layer Updates\")\n", " num_layers = gr.Number(value=0, label=\"Num Layers\")\n", " example_ran = gr.Number(value=0, label=\"Example Ran\")\n", "\n", " set_background = gr.Button(\"Set Background\")\n", " set_background.click(\n", " lambda: {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": None,\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " set_layers = gr.Button(\"Set Layers\")\n", " set_layers.click(\n", " lambda: {\n", " \"background\": None,\n", " \"layers\": [\n", " \"https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg\"\n", " ],\n", " \"composite\": None,\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " im.change(\n", " lambda x: len(x[\"layers\"]),\n", " inputs=im,\n", " outputs=layer_updates,\n", " )\n", " set_composite = gr.Button(\"Set Composite\")\n", " set_composite.click(\n", " lambda: {\n", " \"background\": None,\n", " \"layers\": None,\n", " \"composite\": \"https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg\",\n", " },\n", " None,\n", " im,\n", " show_progress=\"hidden\",\n", " )\n", " get_layers = gr.Button(\"Get Layers\")\n", "\n", " get_layers.click(\n", " predict,\n", " outputs=[im_preview, num_layers],\n", " inputs=im,\n", " )\n", "\n", " gr.Examples(\n", " examples=[\n", " \"https://upload.wikimedia.org/wikipedia/commons/0/09/TheCheethcat.jpg\",\n", " {\n", " \"background\": str(dir_ / \"cheetah.jpg\"),\n", " \"layers\": [str(dir_ / \"layer1.png\")],\n", " \"composite\": None,\n", " },\n", " ],\n", " inputs=im,\n", " outputs=[example_ran],\n", " fn=lambda x: 1,\n", " run_on_click=True,\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
|
@@ -3,8 +3,11 @@ from pathlib import Path
|
|
| 3 |
|
| 4 |
dir_ = Path(__file__).parent
|
| 5 |
|
|
|
|
| 6 |
def predict(im):
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
with gr.Blocks() as demo:
|
| 10 |
with gr.Row():
|
|
@@ -15,7 +18,8 @@ with gr.Blocks() as demo:
|
|
| 15 |
im_preview = gr.ImageEditor(
|
| 16 |
interactive=True,
|
| 17 |
)
|
| 18 |
-
|
|
|
|
| 19 |
num_layers = gr.Number(value=0, label="Num Layers")
|
| 20 |
example_ran = gr.Number(value=0, label="Example Ran")
|
| 21 |
|
|
@@ -34,13 +38,20 @@ with gr.Blocks() as demo:
|
|
| 34 |
set_layers.click(
|
| 35 |
lambda: {
|
| 36 |
"background": None,
|
| 37 |
-
"layers": [
|
|
|
|
|
|
|
| 38 |
"composite": None,
|
| 39 |
},
|
| 40 |
None,
|
| 41 |
im,
|
| 42 |
show_progress="hidden",
|
| 43 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
set_composite = gr.Button("Set Composite")
|
| 45 |
set_composite.click(
|
| 46 |
lambda: {
|
|
|
|
| 3 |
|
| 4 |
dir_ = Path(__file__).parent
|
| 5 |
|
| 6 |
+
|
| 7 |
def predict(im):
|
| 8 |
+
print(im)
|
| 9 |
+
return im, len(im["layers"])
|
| 10 |
+
|
| 11 |
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
with gr.Row():
|
|
|
|
| 18 |
im_preview = gr.ImageEditor(
|
| 19 |
interactive=True,
|
| 20 |
)
|
| 21 |
+
|
| 22 |
+
layer_updates = gr.Textbox(value="", label="Layer Updates")
|
| 23 |
num_layers = gr.Number(value=0, label="Num Layers")
|
| 24 |
example_ran = gr.Number(value=0, label="Example Ran")
|
| 25 |
|
|
|
|
| 38 |
set_layers.click(
|
| 39 |
lambda: {
|
| 40 |
"background": None,
|
| 41 |
+
"layers": [
|
| 42 |
+
"https://nationalzoo.si.edu/sites/default/files/animals/cheetah-003.jpg"
|
| 43 |
+
],
|
| 44 |
"composite": None,
|
| 45 |
},
|
| 46 |
None,
|
| 47 |
im,
|
| 48 |
show_progress="hidden",
|
| 49 |
)
|
| 50 |
+
im.change(
|
| 51 |
+
lambda x: len(x["layers"]),
|
| 52 |
+
inputs=im,
|
| 53 |
+
outputs=layer_updates,
|
| 54 |
+
)
|
| 55 |
set_composite = gr.Button("Set Composite")
|
| 56 |
set_composite.click(
|
| 57 |
lambda: {
|