Upload folder using huggingface_hub
Browse files- README.md +1 -1
- app.py +33 -98
- requirements.txt +1 -3
README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
title: Stable Depth2Image V2
|
| 3 |
emoji: 🦷
|
| 4 |
colorFrom: green
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.36.0
|
| 8 |
app_file: app.py
|
|
|
|
| 2 |
title: Stable Depth2Image V2
|
| 3 |
emoji: 🦷
|
| 4 |
colorFrom: green
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.36.0
|
| 8 |
app_file: app.py
|
app.py
CHANGED
|
@@ -1,123 +1,58 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
import random
|
| 4 |
import os
|
| 5 |
-
from
|
| 6 |
import spaces
|
| 7 |
-
import
|
| 8 |
-
from transformers import pipeline
|
| 9 |
-
from diffusers import StableDiffusionDepth2ImgPipeline
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
else:
|
| 21 |
-
pipe_depth2image = StableDiffusionDepth2ImgPipeline.from_pretrained(model_id_depth2image)
|
| 22 |
-
max_seed = np.iinfo(np.int32).max
|
| 23 |
-
max_image_size = 1344
|
| 24 |
-
example_files = [os.path.join('assets/examples', filename) for filename in sorted(os.listdir('assets/examples'))]
|
| 25 |
|
| 26 |
|
| 27 |
@spaces.GPU
|
| 28 |
-
def infer(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
height,
|
| 36 |
-
guidance_scale,
|
| 37 |
-
num_inference_steps):
|
| 38 |
-
if randomize_seed:
|
| 39 |
-
seed = random.randint(0, max_seed)
|
| 40 |
-
init_image = Image.fromarray(np.uint8(init_image))
|
| 41 |
-
predicted_depth = pipe_depth(init_image)["predicted_depth"]
|
| 42 |
-
image = pipe_depth2image(
|
| 43 |
-
prompt=prompt,
|
| 44 |
-
image=init_image,
|
| 45 |
-
depth_map=predicted_depth,
|
| 46 |
-
negative_prompt=negative_prompt,
|
| 47 |
guidance_scale=guidance_scale,
|
| 48 |
num_inference_steps=num_inference_steps,
|
| 49 |
height=height,
|
| 50 |
width=width,
|
| 51 |
-
|
| 52 |
-
)
|
| 53 |
-
return image, seed
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
-
gr.Markdown(
|
| 58 |
with gr.Row():
|
| 59 |
-
prompt = gr.Text(
|
| 60 |
-
label="Prompt",
|
| 61 |
-
show_label=True,
|
| 62 |
-
max_lines=1,
|
| 63 |
-
placeholder="Enter your prompt",
|
| 64 |
-
container=False,
|
| 65 |
-
)
|
| 66 |
run_button = gr.Button("Run", scale=0)
|
| 67 |
with gr.Row():
|
| 68 |
-
init_image = gr.Image(label="Input Image", type='
|
| 69 |
result = gr.Image(label="Result")
|
| 70 |
with gr.Accordion("Advanced Settings", open=False):
|
| 71 |
-
negative_prompt = gr.Text(
|
| 72 |
-
|
| 73 |
-
max_lines=1,
|
| 74 |
-
placeholder="Enter a negative prompt",
|
| 75 |
-
)
|
| 76 |
-
seed = gr.Slider(
|
| 77 |
-
label="Seed",
|
| 78 |
-
minimum=0,
|
| 79 |
-
maximum=max_seed,
|
| 80 |
-
step=1,
|
| 81 |
-
value=0,
|
| 82 |
-
)
|
| 83 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 84 |
with gr.Row():
|
| 85 |
-
width = gr.Slider(
|
| 86 |
-
|
| 87 |
-
minimum=256,
|
| 88 |
-
maximum=max_image_size,
|
| 89 |
-
step=64,
|
| 90 |
-
value=1024,
|
| 91 |
-
)
|
| 92 |
-
height = gr.Slider(
|
| 93 |
-
label="Height",
|
| 94 |
-
minimum=256,
|
| 95 |
-
maximum=max_image_size,
|
| 96 |
-
step=64,
|
| 97 |
-
value=1024,
|
| 98 |
-
)
|
| 99 |
with gr.Row():
|
| 100 |
-
guidance_scale = gr.Slider(
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
maximum=10.0,
|
| 104 |
-
step=0.1,
|
| 105 |
-
value=7.5,
|
| 106 |
-
)
|
| 107 |
-
num_inference_steps = gr.Slider(
|
| 108 |
-
label="Number of inference steps",
|
| 109 |
-
minimum=1,
|
| 110 |
-
maximum=50,
|
| 111 |
-
step=1,
|
| 112 |
-
value=50,
|
| 113 |
-
)
|
| 114 |
gr.on(
|
| 115 |
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
| 116 |
fn=infer,
|
| 117 |
-
inputs=[init_image, prompt, negative_prompt, seed,
|
| 118 |
-
outputs=[result
|
| 119 |
-
)
|
| 120 |
-
examples = gr.Examples(
|
| 121 |
-
examples=example_files, inputs=[init_image], outputs=[result, seed]
|
| 122 |
)
|
| 123 |
-
demo.
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
+
from diffusers.utils import load_image
|
| 4 |
import spaces
|
| 5 |
+
from panna import Depth2Image, DepthAnythingV2
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
model_image = Depth2Image("stabilityai/stable-diffusion-2-depth")
|
| 8 |
+
model_depth = DepthAnythingV2("depth-anything/Depth-Anything-V2-Large-hf")
|
| 9 |
+
title = ("# [Depth2Image](https://huggingface.co/stabilityai/stable-diffusion-2-depth) with [DepthAnythingV2](https://huggingface.co/depth-anything/Depth-Anything-V2-Large-hf)\n"
|
| 10 |
+
"Depth2Image with depth map predicted by DepthAnything V2. The demo is part of [panna](https://github.com/abacws-abacus/panna) project.")
|
| 11 |
+
example_files = []
|
| 12 |
+
for n in range(10):
|
| 13 |
+
url = f"https://huggingface.co/spaces/depth-anything/Depth-Anything-V2/resolve/main/assets/examples/demo{n:0>2}.jpg"
|
| 14 |
+
load_image(url).save(os.path.basename(url))
|
| 15 |
+
example_files += [os.path.basename(url)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
@spaces.GPU
|
| 19 |
+
def infer(init_image, prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps):
|
| 20 |
+
depth = model_depth.image2depth([init_image])
|
| 21 |
+
return model_image.text2image(
|
| 22 |
+
[init_image],
|
| 23 |
+
depth_maps=depth,
|
| 24 |
+
prompt=[prompt],
|
| 25 |
+
negative_prompt=[negative_prompt],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
guidance_scale=guidance_scale,
|
| 27 |
num_inference_steps=num_inference_steps,
|
| 28 |
height=height,
|
| 29 |
width=width,
|
| 30 |
+
seed=seed
|
| 31 |
+
)[0]
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown(title)
|
| 36 |
with gr.Row():
|
| 37 |
+
prompt = gr.Text(label="Prompt", show_label=True, max_lines=1, placeholder="Enter your prompt", container=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
run_button = gr.Button("Run", scale=0)
|
| 39 |
with gr.Row():
|
| 40 |
+
init_image = gr.Image(label="Input Image", type='pil')
|
| 41 |
result = gr.Image(label="Result")
|
| 42 |
with gr.Accordion("Advanced Settings", open=False):
|
| 43 |
+
negative_prompt = gr.Text(label="Negative Prompt", max_lines=1, placeholder="Enter a negative prompt")
|
| 44 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=1_000_000, step=1, value=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Row():
|
| 46 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1344, step=64, value=1024)
|
| 47 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1344, step=64, value=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
with gr.Row():
|
| 49 |
+
guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=7.5)
|
| 50 |
+
num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=50)
|
| 51 |
+
examples = gr.Examples(examples=example_files, inputs=[init_image])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
gr.on(
|
| 53 |
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
| 54 |
fn=infer,
|
| 55 |
+
inputs=[init_image, prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps],
|
| 56 |
+
outputs=[result]
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
git+https://github.com/huggingface/diffusers.git
|
| 2 |
-
transformers
|
| 3 |
accelerate
|
| 4 |
sentencepiece
|
| 5 |
-
|
| 6 |
-
torch
|
|
|
|
| 1 |
git+https://github.com/huggingface/diffusers.git
|
|
|
|
| 2 |
accelerate
|
| 3 |
sentencepiece
|
| 4 |
+
panna
|
|
|