Spaces:
Running
on
Zero
Running
on
Zero
songtianhui
commited on
Commit
·
b15b2ae
1
Parent(s):
ded1bc8
add height/width
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
import gradio as gr
|
@@ -16,11 +17,14 @@ pipe = StableDiffusionDMMPipeline.from_pretrained(
|
|
16 |
)
|
17 |
pipe.to("cuda")
|
18 |
|
|
|
19 |
@spaces.GPU
|
20 |
def generate(prompt: str,
|
21 |
negative_prompt: str,
|
22 |
model_id: int,
|
23 |
seed: int = 1234,
|
|
|
|
|
24 |
all: bool = True):
|
25 |
if all:
|
26 |
outputs = []
|
@@ -28,8 +32,8 @@ def generate(prompt: str,
|
|
28 |
output = pipe(
|
29 |
prompt=prompt,
|
30 |
negative_prompt=negative_prompt,
|
31 |
-
width=
|
32 |
-
height=
|
33 |
num_inference_steps=25,
|
34 |
guidance_scale=7,
|
35 |
model_id=i,
|
@@ -41,8 +45,8 @@ def generate(prompt: str,
|
|
41 |
output = pipe(
|
42 |
prompt=prompt,
|
43 |
negative_prompt=negative_prompt,
|
44 |
-
width=
|
45 |
-
height=
|
46 |
num_inference_steps=25,
|
47 |
guidance_scale=7,
|
48 |
model_id=int(model_id),
|
@@ -57,20 +61,27 @@ def main():
|
|
57 |
gr.Markdown("# DMM")
|
58 |
with gr.Row():
|
59 |
with gr.Column():
|
|
|
|
|
|
|
60 |
prompt = gr.Textbox("portrait photo of a girl, long golden hair, flowers, best quality", label="Prompt")
|
61 |
negative_prompt = gr.Textbox("worst quality,low quality,normal quality,lowres,watermark,nsfw", label="Negative Prompt")
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
output = gr.Gallery(label="images")
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
72 |
|
73 |
-
demo.launch()
|
74 |
|
75 |
|
76 |
if __name__ == "__main__":
|
|
|
1 |
+
import random
|
2 |
import spaces
|
3 |
import torch
|
4 |
import gradio as gr
|
|
|
17 |
)
|
18 |
pipe.to("cuda")
|
19 |
|
20 |
+
|
21 |
@spaces.GPU
|
22 |
def generate(prompt: str,
|
23 |
negative_prompt: str,
|
24 |
model_id: int,
|
25 |
seed: int = 1234,
|
26 |
+
height: int = 512,
|
27 |
+
width: int = 512,
|
28 |
all: bool = True):
|
29 |
if all:
|
30 |
outputs = []
|
|
|
32 |
output = pipe(
|
33 |
prompt=prompt,
|
34 |
negative_prompt=negative_prompt,
|
35 |
+
width=width,
|
36 |
+
height=height,
|
37 |
num_inference_steps=25,
|
38 |
guidance_scale=7,
|
39 |
model_id=i,
|
|
|
45 |
output = pipe(
|
46 |
prompt=prompt,
|
47 |
negative_prompt=negative_prompt,
|
48 |
+
width=width,
|
49 |
+
height=height,
|
50 |
num_inference_steps=25,
|
51 |
guidance_scale=7,
|
52 |
model_id=int(model_id),
|
|
|
61 |
gr.Markdown("# DMM")
|
62 |
with gr.Row():
|
63 |
with gr.Column():
|
64 |
+
with gr.Column():
|
65 |
+
model_id = gr.Dropdown(list(range(8)), label="Model Index")
|
66 |
+
all_check = gr.Checkbox(label="All (ignore the selection above)")
|
67 |
prompt = gr.Textbox("portrait photo of a girl, long golden hair, flowers, best quality", label="Prompt")
|
68 |
negative_prompt = gr.Textbox("worst quality,low quality,normal quality,lowres,watermark,nsfw", label="Negative Prompt")
|
69 |
+
with gr.Row():
|
70 |
+
seed = gr.Number(0, label="Seed", precision=0, scale=3)
|
71 |
+
update_seed_btn = gr.Button("🎲", scale=1)
|
72 |
+
with gr.Row():
|
73 |
+
height = gr.Number(512, step=8, label="Height (suggest 512~768)")
|
74 |
+
width = gr.Number(512, step=8, label="Width")
|
75 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
76 |
output = gr.Gallery(label="images")
|
77 |
|
78 |
+
submit_btn.click(generate,
|
79 |
+
inputs=[prompt, negative_prompt, model_id, seed, height, width, all_check],
|
80 |
+
outputs=[output])
|
81 |
+
update_seed_btn.click(lambda: random.randint(0, 1000000),
|
82 |
+
outputs=[seed])
|
83 |
|
84 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
85 |
|
86 |
|
87 |
if __name__ == "__main__":
|