Spaces:
Paused
Paused
Commit
•
108abb9
1
Parent(s):
eca8896
Update app.py
Browse files
app.py
CHANGED
@@ -44,16 +44,12 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
44 |
|
45 |
def generate(prompt: str,
|
46 |
negative_prompt: str = '',
|
47 |
-
prompt_2: str = '',
|
48 |
-
negative_prompt_2: str = '',
|
49 |
use_negative_prompt: bool = False,
|
50 |
-
use_prompt_2: bool = False,
|
51 |
-
use_negative_prompt_2: bool = False,
|
52 |
seed: int = 0,
|
53 |
width: int = 1024,
|
54 |
height: int = 1024,
|
55 |
guidance_scale: float = 1.0,
|
56 |
-
num_inference_steps: int =
|
57 |
secret_token: str = '') -> PIL.Image.Image:
|
58 |
if secret_token != SECRET_TOKEN:
|
59 |
raise gr.Error(
|
@@ -63,15 +59,9 @@ def generate(prompt: str,
|
|
63 |
|
64 |
if not use_negative_prompt:
|
65 |
negative_prompt = None # type: ignore
|
66 |
-
if not use_prompt_2:
|
67 |
-
prompt_2 = None # type: ignore
|
68 |
-
if not use_negative_prompt_2:
|
69 |
-
negative_prompt_2 = None # type: ignore
|
70 |
|
71 |
return pipe(prompt=prompt,
|
72 |
negative_prompt=negative_prompt,
|
73 |
-
prompt_2=prompt_2,
|
74 |
-
negative_prompt_2=negative_prompt_2,
|
75 |
width=width,
|
76 |
height=height,
|
77 |
guidance_scale=guidance_scale,
|
@@ -79,108 +69,74 @@ def generate(prompt: str,
|
|
79 |
generator=generator,
|
80 |
output_type='pil').images[0]
|
81 |
|
82 |
-
with gr.Blocks(
|
83 |
gr.Markdown(DESCRIPTION)
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
run_button = gr.Button('Run', scale=0)
|
99 |
-
result = gr.Image(label='Result', show_label=False)
|
100 |
-
with gr.Accordion('Advanced options', open=False):
|
101 |
-
with gr.Row():
|
102 |
-
use_negative_prompt = gr.Checkbox(label='Use negative prompt',
|
103 |
-
value=False)
|
104 |
-
use_prompt_2 = gr.Checkbox(label='Use prompt 2', value=False)
|
105 |
-
use_negative_prompt_2 = gr.Checkbox(
|
106 |
-
label='Use negative prompt 2', value=False)
|
107 |
-
negative_prompt = gr.Text(
|
108 |
-
label='Negative prompt',
|
109 |
-
max_lines=1,
|
110 |
-
placeholder='Enter a negative prompt',
|
111 |
-
visible=False,
|
112 |
-
)
|
113 |
-
prompt_2 = gr.Text(
|
114 |
-
label='Prompt 2',
|
115 |
-
max_lines=1,
|
116 |
-
placeholder='Enter your prompt',
|
117 |
-
visible=False,
|
118 |
-
)
|
119 |
-
negative_prompt_2 = gr.Text(
|
120 |
-
label='Negative prompt 2',
|
121 |
-
max_lines=1,
|
122 |
-
placeholder='Enter a negative prompt',
|
123 |
-
visible=False,
|
124 |
-
)
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
)
|
140 |
-
height = gr.Slider(
|
141 |
-
label='Height',
|
142 |
-
minimum=256,
|
143 |
-
maximum=MAX_IMAGE_SIZE,
|
144 |
-
step=32,
|
145 |
-
value=1024,
|
146 |
-
)
|
147 |
-
guidance_scale = gr.Slider(
|
148 |
-
label='Guidance scale',
|
149 |
-
minimum=1,
|
150 |
-
maximum=20,
|
151 |
-
step=0.1,
|
152 |
-
value=1.0)
|
153 |
-
num_inference_steps = gr.Slider(
|
154 |
-
label='Number of inference steps',
|
155 |
-
minimum=2,
|
156 |
-
maximum=8,
|
157 |
-
step=1,
|
158 |
-
value=4)
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
use_negative_prompt.change(
|
161 |
fn=lambda x: gr.update(visible=x),
|
162 |
inputs=use_negative_prompt,
|
163 |
outputs=negative_prompt
|
164 |
)
|
165 |
-
use_prompt_2.change(
|
166 |
-
fn=lambda x: gr.update(visible=x),
|
167 |
-
inputs=use_prompt_2,
|
168 |
-
outputs=prompt_2
|
169 |
-
)
|
170 |
-
use_negative_prompt_2.change(
|
171 |
-
fn=lambda x: gr.update(visible=x),
|
172 |
-
inputs=use_negative_prompt_2,
|
173 |
-
outputs=negative_prompt_2
|
174 |
-
)
|
175 |
|
176 |
inputs = [
|
177 |
prompt,
|
178 |
negative_prompt,
|
179 |
-
prompt_2,
|
180 |
-
negative_prompt_2,
|
181 |
use_negative_prompt,
|
182 |
-
use_prompt_2,
|
183 |
-
use_negative_prompt_2,
|
184 |
seed,
|
185 |
width,
|
186 |
height,
|
|
|
44 |
|
45 |
def generate(prompt: str,
|
46 |
negative_prompt: str = '',
|
|
|
|
|
47 |
use_negative_prompt: bool = False,
|
|
|
|
|
48 |
seed: int = 0,
|
49 |
width: int = 1024,
|
50 |
height: int = 1024,
|
51 |
guidance_scale: float = 1.0,
|
52 |
+
num_inference_steps: int = 6,
|
53 |
secret_token: str = '') -> PIL.Image.Image:
|
54 |
if secret_token != SECRET_TOKEN:
|
55 |
raise gr.Error(
|
|
|
59 |
|
60 |
if not use_negative_prompt:
|
61 |
negative_prompt = None # type: ignore
|
|
|
|
|
|
|
|
|
62 |
|
63 |
return pipe(prompt=prompt,
|
64 |
negative_prompt=negative_prompt,
|
|
|
|
|
65 |
width=width,
|
66 |
height=height,
|
67 |
guidance_scale=guidance_scale,
|
|
|
69 |
generator=generator,
|
70 |
output_type='pil').images[0]
|
71 |
|
72 |
+
with gr.Blocks() as demo:
|
73 |
gr.Markdown(DESCRIPTION)
|
74 |
+
secret_token = gr.Text(
|
75 |
+
label='Secret Token',
|
76 |
+
max_lines=1,
|
77 |
+
placeholder='Enter your secret token',
|
78 |
+
)
|
79 |
+
prompt = gr.Text(
|
80 |
+
label='Prompt',
|
81 |
+
show_label=False,
|
82 |
+
max_lines=1,
|
83 |
+
placeholder='Enter your prompt',
|
84 |
+
container=False,
|
85 |
+
)
|
86 |
+
run_button = gr.Button('Run', scale=0)
|
87 |
+
result = gr.Image(label='Result', show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
+
use_negative_prompt = gr.Checkbox(label='Use negative prompt', value=False)
|
90 |
+
negative_prompt = gr.Text(
|
91 |
+
label='Negative prompt',
|
92 |
+
max_lines=1,
|
93 |
+
placeholder='Enter a negative prompt',
|
94 |
+
visible=False,
|
95 |
+
)
|
96 |
+
seed = gr.Slider(label='Seed',
|
97 |
+
minimum=0,
|
98 |
+
maximum=MAX_SEED,
|
99 |
+
step=1,
|
100 |
+
value=0)
|
101 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
width = gr.Slider(
|
104 |
+
label='Width',
|
105 |
+
minimum=256,
|
106 |
+
maximum=MAX_IMAGE_SIZE,
|
107 |
+
step=32,
|
108 |
+
value=1024,
|
109 |
+
)
|
110 |
+
height = gr.Slider(
|
111 |
+
label='Height',
|
112 |
+
minimum=256,
|
113 |
+
maximum=MAX_IMAGE_SIZE,
|
114 |
+
step=32,
|
115 |
+
value=1024,
|
116 |
+
)
|
117 |
+
guidance_scale = gr.Slider(
|
118 |
+
label='Guidance scale',
|
119 |
+
minimum=1,
|
120 |
+
maximum=20,
|
121 |
+
step=0.1,
|
122 |
+
value=1.0)
|
123 |
+
num_inference_steps = gr.Slider(
|
124 |
+
label='Number of inference steps',
|
125 |
+
minimum=2,
|
126 |
+
maximum=8,
|
127 |
+
step=1,
|
128 |
+
value=4)
|
129 |
+
|
130 |
use_negative_prompt.change(
|
131 |
fn=lambda x: gr.update(visible=x),
|
132 |
inputs=use_negative_prompt,
|
133 |
outputs=negative_prompt
|
134 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
inputs = [
|
137 |
prompt,
|
138 |
negative_prompt,
|
|
|
|
|
139 |
use_negative_prompt,
|
|
|
|
|
140 |
seed,
|
141 |
width,
|
142 |
height,
|