Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files- README.md +1 -1
- app.py +16 -71
- requirements.txt +2 -3
README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
title: Stable Diffusion 3 Medium
|
3 |
emoji: 🎨
|
4 |
colorFrom: purple
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.36.1
|
8 |
app_file: app.py
|
|
|
2 |
title: Stable Diffusion 3 Medium
|
3 |
emoji: 🎨
|
4 |
colorFrom: purple
|
5 |
+
colorTo: yellow
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.36.1
|
8 |
app_file: app.py
|
app.py
CHANGED
@@ -1,18 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import random
|
4 |
-
import torch
|
5 |
-
from diffusers import StableDiffusion3Pipeline
|
6 |
import spaces
|
|
|
7 |
|
8 |
|
9 |
-
|
10 |
-
if torch.cuda.is_available():
|
11 |
-
pipe = StableDiffusion3Pipeline.from_pretrained(repo, torch_dtype=torch.float16).to("cuda")
|
12 |
-
else:
|
13 |
-
pipe = StableDiffusion3Pipeline.from_pretrained(repo)
|
14 |
-
max_seed = np.iinfo(np.int32).max
|
15 |
-
max_image_size = 1344
|
16 |
examples = [
|
17 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
18 |
"An astronaut riding a green horse",
|
@@ -27,86 +18,40 @@ css = """
|
|
27 |
|
28 |
|
29 |
@spaces.GPU
|
30 |
-
def infer(prompt, negative_prompt, seed,
|
31 |
-
|
32 |
-
seed = random.randint(0, max_seed)
|
33 |
-
image = pipe(
|
34 |
prompt=prompt,
|
35 |
negative_prompt=negative_prompt,
|
36 |
guidance_scale=guidance_scale,
|
37 |
num_inference_steps=num_inference_steps,
|
38 |
width=width,
|
39 |
height=height,
|
40 |
-
|
41 |
-
)
|
42 |
-
return image
|
43 |
|
44 |
|
45 |
with gr.Blocks(css=css) as demo:
|
46 |
with gr.Column(elem_id="col-container"):
|
47 |
gr.Markdown("# Demo [Stable Diffusion 3 Medium](https://huggingface.co/stabilityai/stable-diffusion-3-medium)")
|
48 |
with gr.Row():
|
49 |
-
prompt = gr.Text(
|
50 |
-
label="Prompt",
|
51 |
-
show_label=False,
|
52 |
-
max_lines=1,
|
53 |
-
placeholder="Enter your prompt",
|
54 |
-
container=False,
|
55 |
-
)
|
56 |
run_button = gr.Button("Run", scale=0)
|
57 |
result = gr.Image(label="Result", show_label=False)
|
58 |
with gr.Accordion("Advanced Settings", open=False):
|
59 |
-
negative_prompt = gr.Text(
|
60 |
-
|
61 |
-
max_lines=1,
|
62 |
-
placeholder="Enter a negative prompt",
|
63 |
-
)
|
64 |
-
seed = gr.Slider(
|
65 |
-
label="Seed",
|
66 |
-
minimum=0,
|
67 |
-
maximum=max_seed,
|
68 |
-
step=1,
|
69 |
-
value=0,
|
70 |
-
)
|
71 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
72 |
with gr.Row():
|
73 |
-
width = gr.Slider(
|
74 |
-
|
75 |
-
minimum=256,
|
76 |
-
maximum=max_image_size,
|
77 |
-
step=64,
|
78 |
-
value=1024,
|
79 |
-
)
|
80 |
-
height = gr.Slider(
|
81 |
-
label="Height",
|
82 |
-
minimum=256,
|
83 |
-
maximum=max_image_size,
|
84 |
-
step=64,
|
85 |
-
value=1024,
|
86 |
-
)
|
87 |
with gr.Row():
|
88 |
-
guidance_scale = gr.Slider(
|
89 |
-
|
90 |
-
|
91 |
-
maximum=10.0,
|
92 |
-
step=0.1,
|
93 |
-
value=7.5,
|
94 |
-
)
|
95 |
-
num_inference_steps = gr.Slider(
|
96 |
-
label="Number of inference steps",
|
97 |
-
minimum=1,
|
98 |
-
maximum=50,
|
99 |
-
step=1,
|
100 |
-
value=5,
|
101 |
-
)
|
102 |
-
gr.Examples(
|
103 |
-
examples=examples,
|
104 |
-
inputs=[prompt]
|
105 |
-
)
|
106 |
gr.on(
|
107 |
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
108 |
fn=infer,
|
109 |
-
inputs=[prompt, negative_prompt, seed,
|
110 |
outputs=[result, seed]
|
111 |
)
|
112 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
import spaces
|
3 |
+
from panna import SD3
|
4 |
|
5 |
|
6 |
+
model = SD3("stabilityai/stable-diffusion-3-medium-diffusers")
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
examples = [
|
8 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
9 |
"An astronaut riding a green horse",
|
|
|
18 |
|
19 |
|
20 |
@spaces.GPU
|
21 |
+
def infer(prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps):
|
22 |
+
image = model.text2image(
|
|
|
|
|
23 |
prompt=prompt,
|
24 |
negative_prompt=negative_prompt,
|
25 |
guidance_scale=guidance_scale,
|
26 |
num_inference_steps=num_inference_steps,
|
27 |
width=width,
|
28 |
height=height,
|
29 |
+
seed=seed
|
30 |
+
)
|
31 |
+
return image[0]
|
32 |
|
33 |
|
34 |
with gr.Blocks(css=css) as demo:
|
35 |
with gr.Column(elem_id="col-container"):
|
36 |
gr.Markdown("# Demo [Stable Diffusion 3 Medium](https://huggingface.co/stabilityai/stable-diffusion-3-medium)")
|
37 |
with gr.Row():
|
38 |
+
prompt = gr.Text(label="Prompt", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
run_button = gr.Button("Run", scale=0)
|
40 |
result = gr.Image(label="Result", show_label=False)
|
41 |
with gr.Accordion("Advanced Settings", open=False):
|
42 |
+
negative_prompt = gr.Text(label="Negative Prompt", max_lines=1, placeholder="Enter a negative prompt")
|
43 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=1_000_000, step=1, value=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
with gr.Row():
|
45 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1344, step=64, value=1024)
|
46 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1344, step=64, value=1024)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
with gr.Row():
|
48 |
+
guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=7.5)
|
49 |
+
num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=5)
|
50 |
+
gr.Examples(examples=examples, inputs=[prompt])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
gr.on(
|
52 |
triggers=[run_button.click, prompt.submit, negative_prompt.submit],
|
53 |
fn=infer,
|
54 |
+
inputs=[prompt, negative_prompt, seed, width, height, guidance_scale, num_inference_steps],
|
55 |
outputs=[result, seed]
|
56 |
)
|
57 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
git+https://github.com/huggingface/diffusers.git
|
2 |
-
transformers
|
3 |
accelerate
|
4 |
-
sentencepiece
|
|
|
|
|
|
|
|
1 |
accelerate
|
2 |
+
sentencepiece
|
3 |
+
panna
|