Spaces:
Runtime error
Runtime error
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: 3.
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
|
|
5 |
colorFrom: indigo
|
6 |
colorTo: indigo
|
7 |
sdk: gradio
|
8 |
+
sdk_version: 3.41.2
|
9 |
app_file: run.py
|
10 |
pinned: false
|
11 |
hf_oauth: true
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
https://gradio-main-build.s3.amazonaws.com/
|
2 |
diffusers
|
3 |
transformers
|
4 |
nvidia-ml-py3
|
|
|
1 |
+
https://gradio-main-build.s3.amazonaws.com/d76d50112328711b1a692b80c1e88a085b15b301/gradio-3.41.2-py3-none-any.whl
|
2 |
diffusers
|
3 |
transformers
|
4 |
nvidia-ml-py3
|
run.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: stable-diffusion\n", "### Note: This is a simplified version of the code needed to create the Stable Diffusion demo. See full code here: https://hf.co/spaces/stabilityai/stable-diffusion/tree/main\n", " "]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio diffusers transformers nvidia-ml-py3 ftfy torch"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import torch\n", "from diffusers import StableDiffusionPipeline\n", "from PIL import Image
|
|
|
1 |
+
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: stable-diffusion\n", "### Note: This is a simplified version of the code needed to create the Stable Diffusion demo. See full code here: https://hf.co/spaces/stabilityai/stable-diffusion/tree/main\n", " "]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio diffusers transformers nvidia-ml-py3 ftfy torch"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import torch\n", "from diffusers import StableDiffusionPipeline\n", "from PIL import Image\n", "import os\n", "\n", "auth_token = os.getenv(\"auth_token\")\n", "model_id = \"CompVis/stable-diffusion-v1-4\"\n", "device = \"cpu\"\n", "pipe = StableDiffusionPipeline.from_pretrained(\n", " model_id, use_auth_token=auth_token, revision=\"fp16\", torch_dtype=torch.float16\n", ")\n", "pipe = pipe.to(device)\n", "\n", "\n", "def infer(prompt, samples, steps, scale, seed):\n", " generator = torch.Generator(device=device).manual_seed(seed)\n", " images_list = pipe(\n", " [prompt] * samples,\n", " num_inference_steps=steps,\n", " guidance_scale=scale,\n", " generator=generator,\n", " )\n", " images = []\n", " safe_image = Image.open(r\"unsafe.png\")\n", " for i, image in enumerate(images_list[\"sample\"]):\n", " if images_list[\"nsfw_content_detected\"][i]:\n", " images.append(safe_image)\n", " else:\n", " images.append(image)\n", " return images\n", "\n", "\n", "block = gr.Blocks()\n", "\n", "with block:\n", " with gr.Group():\n", " with gr.Row():\n", " text = gr.Textbox(\n", " label=\"Enter your prompt\",\n", " max_lines=1,\n", " placeholder=\"Enter your prompt\",\n", " container=False,\n", " )\n", " btn = gr.Button(\"Generate image\")\n", " gallery = gr.Gallery(\n", " label=\"Generated images\",\n", " show_label=False,\n", " elem_id=\"gallery\",\n", " columns=[2],\n", " height=\"auto\",\n", " )\n", "\n", " advanced_button = gr.Button(\"Advanced options\", elem_id=\"advanced-btn\")\n", "\n", " with gr.Row(elem_id=\"advanced-options\"):\n", " samples = gr.Slider(label=\"Images\", minimum=1, maximum=4, value=4, step=1)\n", " steps = gr.Slider(label=\"Steps\", minimum=1, maximum=50, value=45, step=1)\n", " scale = gr.Slider(\n", " label=\"Guidance Scale\", minimum=0, maximum=50, value=7.5, step=0.1\n", " )\n", " seed = gr.Slider(\n", " label=\"Seed\",\n", " minimum=0,\n", " maximum=2147483647,\n", " step=1,\n", " randomize=True,\n", " )\n", " text.submit(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery)\n", " btn.click(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery)\n", " advanced_button.click(\n", " None,\n", " [],\n", " text,\n", " )\n", "\n", "block.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
@@ -1,16 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
-
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
auth_token = os.getenv("auth_token")
|
8 |
model_id = "CompVis/stable-diffusion-v1-4"
|
9 |
device = "cpu"
|
10 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
|
|
|
|
11 |
pipe = pipe.to(device)
|
12 |
|
13 |
-
|
|
|
14 |
generator = torch.Generator(device=device).manual_seed(seed)
|
15 |
images_list = pipe(
|
16 |
[prompt] * samples,
|
@@ -21,37 +24,32 @@ def infer(prompt, samples, steps, scale, seed):
|
|
21 |
images = []
|
22 |
safe_image = Image.open(r"unsafe.png")
|
23 |
for i, image in enumerate(images_list["sample"]):
|
24 |
-
if
|
25 |
images.append(safe_image)
|
26 |
else:
|
27 |
images.append(image)
|
28 |
return images
|
29 |
-
|
30 |
|
31 |
|
32 |
block = gr.Blocks()
|
33 |
|
34 |
with block:
|
35 |
with gr.Group():
|
36 |
-
with gr.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
border=(True, False, True, True),
|
45 |
-
rounded=(True, False, False, True),
|
46 |
-
container=False,
|
47 |
-
)
|
48 |
-
btn = gr.Button("Generate image").style(
|
49 |
-
margin=False,
|
50 |
-
rounded=(False, True, True, False),
|
51 |
-
)
|
52 |
gallery = gr.Gallery(
|
53 |
-
label="Generated images",
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
|
56 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
57 |
|
@@ -75,5 +73,5 @@ with block:
|
|
75 |
[],
|
76 |
text,
|
77 |
)
|
78 |
-
|
79 |
-
block.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
+
from PIL import Image
|
5 |
import os
|
6 |
|
7 |
auth_token = os.getenv("auth_token")
|
8 |
model_id = "CompVis/stable-diffusion-v1-4"
|
9 |
device = "cpu"
|
10 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
11 |
+
model_id, use_auth_token=auth_token, revision="fp16", torch_dtype=torch.float16
|
12 |
+
)
|
13 |
pipe = pipe.to(device)
|
14 |
|
15 |
+
|
16 |
+
def infer(prompt, samples, steps, scale, seed):
|
17 |
generator = torch.Generator(device=device).manual_seed(seed)
|
18 |
images_list = pipe(
|
19 |
[prompt] * samples,
|
|
|
24 |
images = []
|
25 |
safe_image = Image.open(r"unsafe.png")
|
26 |
for i, image in enumerate(images_list["sample"]):
|
27 |
+
if images_list["nsfw_content_detected"][i]:
|
28 |
images.append(safe_image)
|
29 |
else:
|
30 |
images.append(image)
|
31 |
return images
|
|
|
32 |
|
33 |
|
34 |
block = gr.Blocks()
|
35 |
|
36 |
with block:
|
37 |
with gr.Group():
|
38 |
+
with gr.Row():
|
39 |
+
text = gr.Textbox(
|
40 |
+
label="Enter your prompt",
|
41 |
+
max_lines=1,
|
42 |
+
placeholder="Enter your prompt",
|
43 |
+
container=False,
|
44 |
+
)
|
45 |
+
btn = gr.Button("Generate image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
gallery = gr.Gallery(
|
47 |
+
label="Generated images",
|
48 |
+
show_label=False,
|
49 |
+
elem_id="gallery",
|
50 |
+
columns=[2],
|
51 |
+
height="auto",
|
52 |
+
)
|
53 |
|
54 |
advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
|
55 |
|
|
|
73 |
[],
|
74 |
text,
|
75 |
)
|
76 |
+
|
77 |
+
block.launch()
|