Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +7 -6
- app.py +128 -0
- assets/examples/demo01.jpg +0 -0
- assets/examples/demo02.jpg +0 -0
- assets/examples/demo03.jpg +0 -0
- assets/examples/demo04.jpg +0 -0
- assets/examples/demo05.jpg +0 -0
- assets/examples/demo06.jpg +0 -0
- assets/examples/demo07.jpg +0 -0
- assets/examples/demo08.jpg +0 -0
- assets/examples/demo09.jpg +0 -0
- assets/examples/demo10.jpg +0 -0
- assets/examples/demo11.jpg +0 -0
- assets/examples/demo12.jpg +0 -0
- assets/examples/demo13.jpg +0 -0
- assets/examples/demo14.jpg +0 -0
- assets/examples/demo15.jpg +0 -0
- assets/examples/demo16.jpg +0 -0
- assets/examples/demo17.jpg +0 -0
- assets/examples/demo18.jpg +0 -0
- assets/examples/demo19.jpg +3 -0
- assets/examples/demo20.jpg +0 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/examples/demo19.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title: Stable
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Stable Depth2Image V2
|
| 3 |
+
emoji: 🌖
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.36.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib
|
| 3 |
+
import numpy as np
|
| 4 |
+
import random
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import spaces
|
| 8 |
+
import torch
|
| 9 |
+
from gradio_imageslider import ImageSlider
|
| 10 |
+
from transformers import pipeline
|
| 11 |
+
from diffusers import StableDiffusionDepth2ImgPipeline
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
model_id_depth = "depth-anything/Depth-Anything-V2-Large-hf"
|
| 15 |
+
if torch.cuda.is_available():
|
| 16 |
+
pipe_depth = pipeline(task="depth-estimation", model=model_id_depth, device="cuda")
|
| 17 |
+
else:
|
| 18 |
+
pipe_depth = pipeline(task="depth-estimation", model=model_id_depth)
|
| 19 |
+
model_id_depth2image = "stabilityai/stable-diffusion-2-depth"
|
| 20 |
+
if torch.cuda.is_available():
|
| 21 |
+
pipe_depth2image = StableDiffusionDepth2ImgPipeline.from_pretrained(model_id_depth2image, torch_dtype=torch.float16).to("cuda")
|
| 22 |
+
else:
|
| 23 |
+
pipe_depth2image = StableDiffusionDepth2ImgPipeline.from_pretrained(model_id_depth2image)
|
| 24 |
+
max_seed = np.iinfo(np.int32).max
|
| 25 |
+
max_image_size = 1344
|
| 26 |
+
example_files = [os.path.join('assets/examples', filename) for filename in sorted(os.listdir('assets/examples'))]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@spaces.GPU
|
| 30 |
+
def infer(
|
| 31 |
+
init_image,
|
| 32 |
+
prompt,
|
| 33 |
+
negative_prompt,
|
| 34 |
+
seed,
|
| 35 |
+
randomize_seed,
|
| 36 |
+
width,
|
| 37 |
+
height,
|
| 38 |
+
guidance_scale,
|
| 39 |
+
num_inference_steps):
|
| 40 |
+
if randomize_seed:
|
| 41 |
+
seed = random.randint(0, max_seed)
|
| 42 |
+
init_image = Image.fromarray(np.uint8(init_image))
|
| 43 |
+
# generate depth
|
| 44 |
+
predicted_depth = pipe_depth(init_image)["predicted_depth"]
|
| 45 |
+
# generate image
|
| 46 |
+
image = pipe_depth2image(
|
| 47 |
+
prompt=prompt,
|
| 48 |
+
image=init_image,
|
| 49 |
+
depth_map=predicted_depth,
|
| 50 |
+
negative_prompt=negative_prompt,
|
| 51 |
+
guidance_scale=guidance_scale,
|
| 52 |
+
num_inference_steps=num_inference_steps,
|
| 53 |
+
height=height,
|
| 54 |
+
width=width,
|
| 55 |
+
generator=torch.Generator().manual_seed(seed)
|
| 56 |
+
).images[0]
|
| 57 |
+
return image, seed
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
with gr.Blocks() as demo:
|
| 61 |
+
gr.Markdown("# Demo [Depth2Image](https://huggingface.co/stabilityai/stable-diffusion-2-depth) with depth map estimated by [Depth Anything V2](https://huggingface.co/depth-anything/Depth-Anything-V2-Large-hf).")
|
| 62 |
+
prompt = gr.Text(
|
| 63 |
+
label="Prompt",
|
| 64 |
+
show_label=False,
|
| 65 |
+
max_lines=1,
|
| 66 |
+
placeholder="Enter your prompt",
|
| 67 |
+
container=False,
|
| 68 |
+
)
|
| 69 |
+
with gr.Row():
|
| 70 |
+
init_image = gr.Image(label="Input Image", type='numpy')
|
| 71 |
+
result = gr.Image(label="Result", show_label=False)
|
| 72 |
+
run_button = gr.Button("Run", scale=0)
|
| 73 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 74 |
+
negative_prompt = gr.Text(
|
| 75 |
+
label="Negative Prompt",
|
| 76 |
+
max_lines=1,
|
| 77 |
+
placeholder="Enter a negative prompt",
|
| 78 |
+
)
|
| 79 |
+
seed = gr.Slider(
|
| 80 |
+
label="Seed",
|
| 81 |
+
minimum=0,
|
| 82 |
+
maximum=max_seed,
|
| 83 |
+
step=1,
|
| 84 |
+
value=0,
|
| 85 |
+
)
|
| 86 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 87 |
+
with gr.Row():
|
| 88 |
+
width = gr.Slider(
|
| 89 |
+
label="Width",
|
| 90 |
+
minimum=256,
|
| 91 |
+
maximum=max_image_size,
|
| 92 |
+
step=64,
|
| 93 |
+
value=1024,
|
| 94 |
+
)
|
| 95 |
+
height = gr.Slider(
|
| 96 |
+
label="Height",
|
| 97 |
+
minimum=256,
|
| 98 |
+
maximum=max_image_size,
|
| 99 |
+
step=64,
|
| 100 |
+
value=1024,
|
| 101 |
+
)
|
| 102 |
+
with gr.Row():
|
| 103 |
+
guidance_scale = gr.Slider(
|
| 104 |
+
label="Guidance scale",
|
| 105 |
+
minimum=0.0,
|
| 106 |
+
maximum=10.0,
|
| 107 |
+
step=0.1,
|
| 108 |
+
value=7.5,
|
| 109 |
+
)
|
| 110 |
+
num_inference_steps = gr.Slider(
|
| 111 |
+
label="Number of inference steps",
|
| 112 |
+
minimum=1,
|
| 113 |
+
maximum=50,
|
| 114 |
+
step=1,
|
| 115 |
+
value=5,
|
| 116 |
+
)
|
| 117 |
+
gr.on(
|
| 118 |
+
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
| 119 |
+
fn=infer,
|
| 120 |
+
inputs=[init_image, prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 121 |
+
outputs=[result, seed]
|
| 122 |
+
)
|
| 123 |
+
examples = gr.Examples(
|
| 124 |
+
examples=example_files, inputs=[init_image], outputs=[depth_image_slider, gray_depth_file], fn=on_submit
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
demo.queue().launch()
|
assets/examples/demo01.jpg
ADDED
|
assets/examples/demo02.jpg
ADDED
|
assets/examples/demo03.jpg
ADDED
|
assets/examples/demo04.jpg
ADDED
|
assets/examples/demo05.jpg
ADDED
|
assets/examples/demo06.jpg
ADDED
|
assets/examples/demo07.jpg
ADDED
|
assets/examples/demo08.jpg
ADDED
|
assets/examples/demo09.jpg
ADDED
|
assets/examples/demo10.jpg
ADDED
|
assets/examples/demo11.jpg
ADDED
|
assets/examples/demo12.jpg
ADDED
|
assets/examples/demo13.jpg
ADDED
|
assets/examples/demo14.jpg
ADDED
|
assets/examples/demo15.jpg
ADDED
|
assets/examples/demo16.jpg
ADDED
|
assets/examples/demo17.jpg
ADDED
|
assets/examples/demo18.jpg
ADDED
|
assets/examples/demo19.jpg
ADDED
|
Git LFS Details
|
assets/examples/demo20.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/diffusers.git
|
| 2 |
+
transformers
|
| 3 |
+
accelerate
|
| 4 |
+
sentencepiece
|
| 5 |
+
gradio==4.36.0
|
| 6 |
+
torch
|
| 7 |
+
matplotlib
|