Spaces:
Running
Running
Upload with huggingface_hub
Browse files
README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
|
2 |
---
|
3 |
+
title: gallery_selections
|
4 |
+
emoji: 🔥
|
5 |
+
colorFrom: indigo
|
6 |
+
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 3.21.0
|
9 |
+
app_file: run.py
|
10 |
pinned: false
|
11 |
---
|
|
|
|
run.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: gallery_selections"]}, {"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 gradio as gr\n", "import numpy as np\n", "\n", "with gr.Blocks() as demo:\n", " imgs = gr.State()\n", " gallery = gr.Gallery()\n", "\n", " def generate_images():\n", " images = []\n", " for _ in range(9):\n", " image = np.ones((100, 100, 3), dtype=np.uint8) * np.random.randint(\n", " 0, 255, 3\n", " ) # image is a solid single color\n", " images.append(image)\n", " return images, images\n", "\n", " demo.load(generate_images, None, [gallery, imgs])\n", "\n", " with gr.Row():\n", " selected = gr.Number(show_label=False, placeholder=\"Selected\")\n", " darken_btn = gr.Button(\"Darken selected\")\n", "\n", " def get_select_index(evt: gr.SelectData):\n", " return evt.index\n", "\n", " gallery.select(get_select_index, None, selected)\n", "\n", " def darken_img(imgs, index):\n", " index = int(index)\n", " imgs[index] = np.round(imgs[index] * 0.8).astype(np.uint8)\n", " return imgs, imgs\n", "\n", " darken_btn.click(darken_img, [imgs, selected], [imgs, gallery])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
imgs = gr.State()
|
6 |
+
gallery = gr.Gallery()
|
7 |
+
|
8 |
+
def generate_images():
|
9 |
+
images = []
|
10 |
+
for _ in range(9):
|
11 |
+
image = np.ones((100, 100, 3), dtype=np.uint8) * np.random.randint(
|
12 |
+
0, 255, 3
|
13 |
+
) # image is a solid single color
|
14 |
+
images.append(image)
|
15 |
+
return images, images
|
16 |
+
|
17 |
+
demo.load(generate_images, None, [gallery, imgs])
|
18 |
+
|
19 |
+
with gr.Row():
|
20 |
+
selected = gr.Number(show_label=False, placeholder="Selected")
|
21 |
+
darken_btn = gr.Button("Darken selected")
|
22 |
+
|
23 |
+
def get_select_index(evt: gr.SelectData):
|
24 |
+
return evt.index
|
25 |
+
|
26 |
+
gallery.select(get_select_index, None, selected)
|
27 |
+
|
28 |
+
def darken_img(imgs, index):
|
29 |
+
index = int(index)
|
30 |
+
imgs[index] = np.round(imgs[index] * 0.8).astype(np.uint8)
|
31 |
+
return imgs, imgs
|
32 |
+
|
33 |
+
darken_btn.click(darken_img, [imgs, selected], [imgs, gallery])
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
demo.launch()
|