-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
135 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: blocks_flipper"]}, {"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": ["import numpy as np\n", "import gradio as gr\n", "\n", "def flip_text(x):\n", " return x[::-1]\n", "\n", "def flip_image(x):\n", " return np.fliplr(x)\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Flip text or image files using this demo.\")\n", " with gr.Tab(\"Flip Text\"):\n", " text_input = gr.Textbox()\n", " text_output = gr.Textbox()\n", " text_button = gr.Button(\"Flip\")\n", " with gr.Tab(\"Flip Image\"):\n", " with gr.Row():\n", " image_input = gr.Image()\n", " image_output = gr.Image()\n", " image_button = gr.Button(\"Flip\")\n", "\n", " with gr.Accordion(\"Open for More!\"):\n", " gr.Markdown(\"Look at me...\")\n", "\n", " text_button.click(flip_text, inputs=text_input, outputs=text_output)\n", " image_button.click(flip_image, inputs=image_input, outputs=image_output)\n", " \n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: blocks_flipper"]}, {"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": ["import numpy as np\n", "import gradio as gr\n", "\n", "\n", "def flip_text(x):\n", " return x[::-1]\n", "\n", "\n", "def flip_image(x):\n", " return np.fliplr(x)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Flip text or image files using this demo.\")\n", " with gr.Tab(\"Flip Text\"):\n", " text_input = gr.Textbox()\n", " text_output = gr.Textbox()\n", " text_button = gr.Button(\"Flip\")\n", " with gr.Tab(\"Flip Image\"):\n", " with gr.Row():\n", " image_input = gr.Image()\n", " image_output = gr.Image()\n", " image_button = gr.Button(\"Flip\")\n", "\n", " with gr.Accordion(\"Open for More!\"):\n", " gr.Markdown(\"Look at me...\")\n", "\n", " text_button.click(flip_text, inputs=text_input, outputs=text_output)\n", " image_button.click(flip_image, inputs=image_input, outputs=image_output)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: blocks_mask"]}, {"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/blocks_mask/lion.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/blocks_mask/lion.webp"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from gradio.components import Markdown as md\n", "\n", "demo = gr.Blocks()\n", "\n", "io1a = gr.Interface(lambda x: x, gr.Image(), gr.Image())\n", "io1b = gr.Interface(lambda x: x, gr.Image(source=\"webcam\"), gr.Image())\n", "\n", "io2a = gr.Interface(lambda x: x, gr.Image(source=\"canvas\"), gr.Image())\n", "io2b = gr.Interface(lambda x: x, gr.Sketchpad(), gr.Image())\n", "\n", "io3a = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.Image(source=\"upload\", tool=\"sketch\"),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b2 = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b3 = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3c = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.Image(source=\"webcam\", tool=\"sketch\"),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io4a = gr.Interface(\n", " lambda x: x, gr.Image(source=\"canvas\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "io4b = gr.Interface(lambda x: x, gr.Paint(), gr.Image())\n", "\n", "io5a = gr.Interface(\n", " lambda x: x, gr.Image(source=\"upload\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "io5b = gr.Interface(lambda x: x, gr.ImagePaint(), gr.Image())\n", "io5c = gr.Interface(\n", " lambda x: x, gr.Image(source=\"webcam\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "\n", "\n", "with demo:\n", " md(\"# Different Ways to Use the Image Input Component\")\n", " md(\n", " \"**1a. Standalone Image Upload: `gr.Interface(lambda x: x, gr.Image(), gr.Image())`**\"\n", " )\n", " io1a.render()\n", " md(\n", " \"**1b. Standalone Image from Webcam: `gr.Interface(lambda x: x, gr.Image(source='webcam'), gr.Image())`**\"\n", " )\n", " io1b.render()\n", " md(\n", " \"**2a. Black and White Sketchpad: `gr.Interface(lambda x: x, gr.Image(source='canvas'), gr.Image())`**\"\n", " )\n", " io2a.render()\n", " md(\n", " \"**2b. Black and White Sketchpad: `gr.Interface(lambda x: x, gr.Sketchpad(), gr.Image())`**\"\n", " )\n", " io2b.render()\n", " md(\"**3a. Binary Mask with image upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.Image(source='upload', tool='sketch'),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3a.render()\n", " md(\"**3b. Binary Mask with image upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3b.render()\n", " md(\"**3c. Binary Mask with webcam upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.Image(source='webcam', tool='sketch'),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3c.render()\n", " md(\n", " \"**4a. Color Sketchpad: `gr.Interface(lambda x: x, gr.Image(source='canvas', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io4a.render()\n", " md(\"**4b. Color Sketchpad: `gr.Interface(lambda x: x, gr.Paint(), gr.Image())`**\")\n", " io4b.render()\n", " md(\n", " \"**5a. Color Sketchpad with image upload: `gr.Interface(lambda x: x, gr.Image(source='upload', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io5a.render()\n", " md(\n", " \"**5b. Color Sketchpad with image upload: `gr.Interface(lambda x: x, gr.ImagePaint(), gr.Image())`**\"\n", " )\n", " io5b.render()\n", " md(\n", " \"**5c. Color Sketchpad with webcam upload: `gr.Interface(lambda x: x, gr.Image(source='webcam', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io5c.render()\n", " md(\"**Tabs**\")\n", " with gr.Tab(\"One\"):\n", " io3b2.render()\n", " with gr.Tab(\"Two\"):\n", " io3b3.render()\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: blocks_mask"]}, {"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/blocks_mask/colorede.png\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/blocks_mask/image.png\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/blocks_mask/lion.jpg\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/blocks_mask/lion.webp"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from gradio.components import Markdown as md\n", "from PIL import Image\n", "\n", "demo = gr.Blocks()\n", "\n", "io1a = gr.Interface(lambda x: x, gr.Image(), gr.Image())\n", "io1b = gr.Interface(lambda x: x, gr.Image(source=\"webcam\"), gr.Image())\n", "\n", "io2a = gr.Interface(lambda x: x, gr.Image(source=\"canvas\"), gr.Image())\n", "io2b = gr.Interface(lambda x: x, gr.Sketchpad(), gr.Image())\n", "io2c = gr.Interface(\n", " lambda x: x, gr.Image(source=\"canvas\", shape=(512, 512)), gr.Image()\n", ")\n", "\n", "io3a = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.Image(source=\"upload\", tool=\"sketch\"),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b2 = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3b3 = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io3c = gr.Interface(\n", " lambda x: [x[\"mask\"], x[\"image\"]],\n", " gr.Image(source=\"webcam\", tool=\"sketch\"),\n", " [gr.Image(), gr.Image()],\n", ")\n", "\n", "io4a = gr.Interface(\n", " lambda x: x, gr.Image(source=\"canvas\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "io4b = gr.Interface(lambda x: x, gr.Paint(), gr.Image())\n", "\n", "io5a = gr.Interface(\n", " lambda x: x, gr.Image(source=\"upload\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "io5b = gr.Interface(lambda x: x, gr.ImagePaint(), gr.Image())\n", "io5c = gr.Interface(\n", " lambda x: x, gr.Image(source=\"webcam\", tool=\"color-sketch\"), gr.Image()\n", ")\n", "\n", "\n", "def save_image(image):\n", " image.save(\"colorede.png\")\n", " return image\n", "\n", "\n", "img = Image.new(\"RGB\", (512, 512), (150, 150, 150))\n", "img.save(\"image.png\", \"PNG\")\n", "\n", "io5d = gr.Interface(\n", " save_image,\n", " gr.Image(\"image.png\", source=\"upload\", tool=\"color-sketch\", type=\"pil\"),\n", " gr.Image(),\n", ")\n", "\n", "with demo:\n", " md(\"# Different Ways to Use the Image Input Component\")\n", " md(\n", " \"**1a. Standalone Image Upload: `gr.Interface(lambda x: x, gr.Image(), gr.Image())`**\"\n", " )\n", " io1a.render()\n", " md(\n", " \"**1b. Standalone Image from Webcam: `gr.Interface(lambda x: x, gr.Image(source='webcam'), gr.Image())`**\"\n", " )\n", " io1b.render()\n", " md(\n", " \"**2a. Black and White Sketchpad: `gr.Interface(lambda x: x, gr.Image(source='canvas'), gr.Image())`**\"\n", " )\n", " io2a.render()\n", " md(\n", " \"**2b. Black and White Sketchpad: `gr.Interface(lambda x: x, gr.Sketchpad(), gr.Image())`**\"\n", " )\n", " io2b.render()\n", " md(\"**2c. Black and White Sketchpad with `shape=(512,512)`**\")\n", " io2c.render()\n", " md(\"**3a. Binary Mask with image upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.Image(source='upload', tool='sketch'),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3a.render()\n", " md(\"**3b. Binary Mask with image upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.ImageMask(),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3b.render()\n", " md(\"**3c. Binary Mask with webcam upload:**\")\n", " md(\n", " \"\"\"```python\n", "gr.Interface(\n", " lambda x: [x['mask'], x['image']],\n", " gr.Image(source='webcam', tool='sketch'),\n", " [gr.Image(), gr.Image()],\n", ")\n", "```\n", "\"\"\"\n", " )\n", " io3c.render()\n", " md(\n", " \"**4a. Color Sketchpad: `gr.Interface(lambda x: x, gr.Image(source='canvas', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io4a.render()\n", " md(\"**4b. Color Sketchpad: `gr.Interface(lambda x: x, gr.Paint(), gr.Image())`**\")\n", " io4b.render()\n", " md(\n", " \"**5a. Color Sketchpad with image upload: `gr.Interface(lambda x: x, gr.Image(source='upload', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io5a.render()\n", " md(\n", " \"**5b. Color Sketchpad with image upload: `gr.Interface(lambda x: x, gr.ImagePaint(), gr.Image())`**\"\n", " )\n", " io5b.render()\n", " md(\n", " \"**5c. Color Sketchpad with webcam upload: `gr.Interface(lambda x: x, gr.Image(source='webcam', tool='color-sketch'), gr.Image())`**\"\n", " )\n", " io5c.render()\n", " md(\"**Tabs**\")\n", " with gr.Tab(\"One\"):\n", " io3b2.render()\n", " with gr.Tab(\"Two\"):\n", " io3b3.render()\n", " md(\"**5d. Color Sketchpad with image upload and a default images**\")\n", " io5d.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.