Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -42,21 +42,22 @@ def save_generated_image(image, prompt):
|
|
42 |
|
43 |
return filepath
|
44 |
|
|
|
45 |
@spaces.GPU(duration=120)
|
46 |
def inference(
|
47 |
-
prompt
|
48 |
-
seed
|
49 |
-
randomize_seed
|
50 |
-
width
|
51 |
-
height
|
52 |
-
guidance_scale
|
53 |
-
num_inference_steps
|
54 |
-
lora_scale
|
55 |
-
progress
|
56 |
):
|
57 |
if randomize_seed:
|
58 |
seed = random.randint(0, MAX_SEED)
|
59 |
-
generator = torch.Generator(device=device).manual_seed(seed)
|
60 |
|
61 |
image = pipeline(
|
62 |
prompt=prompt,
|
@@ -74,6 +75,19 @@ def inference(
|
|
74 |
# Return just the image and seed
|
75 |
return image, seed
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Updated examples with 1880s clothing style
|
78 |
examples = [
|
79 |
"Cézanne's painting of a lively outdoor gathering in the 1880s, with men in formal top hats, frock coats, and women in bustled dresses with elaborate hats, enjoying a summer afternoon. The scene captures the Belle Époque atmosphere with dappled sunlight filtering through trees, highlighting the fashionable attire of the period. [trigger]",
|
@@ -86,15 +100,6 @@ examples = [
|
|
86 |
|
87 |
# First example for preloading
|
88 |
default_prompt = examples[0]
|
89 |
-
default_settings = {
|
90 |
-
"seed": 42,
|
91 |
-
"randomize_seed": True,
|
92 |
-
"width": 1024,
|
93 |
-
"height": 768,
|
94 |
-
"guidance_scale": 3.5,
|
95 |
-
"num_inference_steps": 30,
|
96 |
-
"lora_scale": 1.0
|
97 |
-
}
|
98 |
|
99 |
# Improved custom CSS with better visuals
|
100 |
custom_css = """
|
@@ -185,19 +190,9 @@ button:hover {
|
|
185 |
}
|
186 |
"""
|
187 |
|
188 |
-
#
|
189 |
def preload_example():
|
190 |
-
|
191 |
-
image, seed_value = inference(
|
192 |
-
prompt=default_prompt,
|
193 |
-
seed=default_settings["seed"],
|
194 |
-
randomize_seed=default_settings["randomize_seed"],
|
195 |
-
width=default_settings["width"],
|
196 |
-
height=default_settings["height"],
|
197 |
-
guidance_scale=default_settings["guidance_scale"],
|
198 |
-
num_inference_steps=default_settings["num_inference_steps"],
|
199 |
-
lora_scale=default_settings["lora_scale"],
|
200 |
-
)
|
201 |
return default_prompt, image, seed_value
|
202 |
|
203 |
with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
@@ -229,9 +224,9 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
229 |
minimum=0,
|
230 |
maximum=MAX_SEED,
|
231 |
step=1,
|
232 |
-
value=
|
233 |
)
|
234 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=
|
235 |
|
236 |
with gr.Row():
|
237 |
width = gr.Slider(
|
@@ -239,14 +234,14 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
239 |
minimum=256,
|
240 |
maximum=MAX_IMAGE_SIZE,
|
241 |
step=32,
|
242 |
-
value=
|
243 |
)
|
244 |
height = gr.Slider(
|
245 |
label="Height",
|
246 |
minimum=256,
|
247 |
maximum=MAX_IMAGE_SIZE,
|
248 |
step=32,
|
249 |
-
value=
|
250 |
)
|
251 |
|
252 |
with gr.Row():
|
@@ -255,30 +250,30 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
255 |
minimum=0.0,
|
256 |
maximum=10.0,
|
257 |
step=0.1,
|
258 |
-
value=
|
259 |
)
|
260 |
num_inference_steps = gr.Slider(
|
261 |
label="Number of inference steps",
|
262 |
minimum=1,
|
263 |
maximum=50,
|
264 |
step=1,
|
265 |
-
value=
|
266 |
)
|
267 |
lora_scale = gr.Slider(
|
268 |
label="LoRA scale",
|
269 |
minimum=0.0,
|
270 |
maximum=1.0,
|
271 |
step=0.1,
|
272 |
-
value=
|
273 |
)
|
274 |
|
275 |
with gr.Group(elem_classes="example-region"):
|
276 |
gr.Markdown("### Examples")
|
277 |
gr.Examples(
|
278 |
examples=examples,
|
279 |
-
inputs=
|
280 |
outputs=[result, seed_output],
|
281 |
-
fn=
|
282 |
cache_examples=True,
|
283 |
)
|
284 |
|
@@ -299,7 +294,7 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
299 |
outputs=[result, seed_output],
|
300 |
)
|
301 |
|
302 |
-
# Preload the first example when the app starts
|
303 |
demo.load(
|
304 |
fn=preload_example,
|
305 |
inputs=None,
|
|
|
42 |
|
43 |
return filepath
|
44 |
|
45 |
+
# Fixed inference function - properly handle Progress parameter
|
46 |
@spaces.GPU(duration=120)
|
47 |
def inference(
|
48 |
+
prompt,
|
49 |
+
seed=42,
|
50 |
+
randomize_seed=True,
|
51 |
+
width=1024,
|
52 |
+
height=768,
|
53 |
+
guidance_scale=3.5,
|
54 |
+
num_inference_steps=30,
|
55 |
+
lora_scale=1.0,
|
56 |
+
progress=None,
|
57 |
):
|
58 |
if randomize_seed:
|
59 |
seed = random.randint(0, MAX_SEED)
|
60 |
+
generator = torch.Generator(device=device).manual_seed(int(seed))
|
61 |
|
62 |
image = pipeline(
|
63 |
prompt=prompt,
|
|
|
75 |
# Return just the image and seed
|
76 |
return image, seed
|
77 |
|
78 |
+
# Create version for examples
|
79 |
+
def example_inference(prompt):
|
80 |
+
return inference(
|
81 |
+
prompt=prompt,
|
82 |
+
seed=42,
|
83 |
+
randomize_seed=True,
|
84 |
+
width=1024,
|
85 |
+
height=768,
|
86 |
+
guidance_scale=3.5,
|
87 |
+
num_inference_steps=30,
|
88 |
+
lora_scale=1.0
|
89 |
+
)
|
90 |
+
|
91 |
# Updated examples with 1880s clothing style
|
92 |
examples = [
|
93 |
"Cézanne's painting of a lively outdoor gathering in the 1880s, with men in formal top hats, frock coats, and women in bustled dresses with elaborate hats, enjoying a summer afternoon. The scene captures the Belle Époque atmosphere with dappled sunlight filtering through trees, highlighting the fashionable attire of the period. [trigger]",
|
|
|
100 |
|
101 |
# First example for preloading
|
102 |
default_prompt = examples[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
# Improved custom CSS with better visuals
|
105 |
custom_css = """
|
|
|
190 |
}
|
191 |
"""
|
192 |
|
193 |
+
# Fixed preload function
|
194 |
def preload_example():
|
195 |
+
image, seed_value = inference(prompt=default_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
return default_prompt, image, seed_value
|
197 |
|
198 |
with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
|
224 |
minimum=0,
|
225 |
maximum=MAX_SEED,
|
226 |
step=1,
|
227 |
+
value=42,
|
228 |
)
|
229 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
230 |
|
231 |
with gr.Row():
|
232 |
width = gr.Slider(
|
|
|
234 |
minimum=256,
|
235 |
maximum=MAX_IMAGE_SIZE,
|
236 |
step=32,
|
237 |
+
value=1024,
|
238 |
)
|
239 |
height = gr.Slider(
|
240 |
label="Height",
|
241 |
minimum=256,
|
242 |
maximum=MAX_IMAGE_SIZE,
|
243 |
step=32,
|
244 |
+
value=768,
|
245 |
)
|
246 |
|
247 |
with gr.Row():
|
|
|
250 |
minimum=0.0,
|
251 |
maximum=10.0,
|
252 |
step=0.1,
|
253 |
+
value=3.5,
|
254 |
)
|
255 |
num_inference_steps = gr.Slider(
|
256 |
label="Number of inference steps",
|
257 |
minimum=1,
|
258 |
maximum=50,
|
259 |
step=1,
|
260 |
+
value=30,
|
261 |
)
|
262 |
lora_scale = gr.Slider(
|
263 |
label="LoRA scale",
|
264 |
minimum=0.0,
|
265 |
maximum=1.0,
|
266 |
step=0.1,
|
267 |
+
value=1.0,
|
268 |
)
|
269 |
|
270 |
with gr.Group(elem_classes="example-region"):
|
271 |
gr.Markdown("### Examples")
|
272 |
gr.Examples(
|
273 |
examples=examples,
|
274 |
+
inputs=prompt,
|
275 |
outputs=[result, seed_output],
|
276 |
+
fn=example_inference, # Use the simplified example function
|
277 |
cache_examples=True,
|
278 |
)
|
279 |
|
|
|
294 |
outputs=[result, seed_output],
|
295 |
)
|
296 |
|
297 |
+
# Preload the first example when the app starts
|
298 |
demo.load(
|
299 |
fn=preload_example,
|
300 |
inputs=None,
|