Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,16 +17,12 @@ else:
|
|
| 17 |
torch_dtype = torch.float32
|
| 18 |
|
| 19 |
def split_image(input_image, num_splits=4):
|
| 20 |
-
# Create a list to store the output images
|
| 21 |
output_images = []
|
| 22 |
-
|
| 23 |
-
# Split the image into four 256x256 sections
|
| 24 |
for i in range(num_splits):
|
| 25 |
left = i * 320
|
| 26 |
right = (i + 1) * 320
|
| 27 |
box = (left, 0, right, 320)
|
| 28 |
output_images.append(input_image.crop(box))
|
| 29 |
-
|
| 30 |
return output_images
|
| 31 |
|
| 32 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch_dtype).to(device)
|
|
@@ -52,14 +48,13 @@ def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=28):
|
|
| 52 |
).images[0]
|
| 53 |
|
| 54 |
gif_name = f"{uuid.uuid4().hex}-flux.gif"
|
| 55 |
-
|
| 56 |
export_to_gif(split_image(image, 4), gif_name, fps=4)
|
| 57 |
|
| 58 |
return gif_name, image, seed
|
| 59 |
-
|
| 60 |
examples = [
|
| 61 |
"a red panda playing with a bamboo stick in the snow",
|
| 62 |
-
"
|
| 63 |
"a magical butterfly transforming into sparkles",
|
| 64 |
"a robot learning to paint like Van Gogh",
|
| 65 |
"a dragon hatching from a crystal egg",
|
|
@@ -107,7 +102,7 @@ footer {visibility: hidden}
|
|
| 107 |
}
|
| 108 |
"""
|
| 109 |
|
| 110 |
-
with gr.Blocks(theme="
|
| 111 |
gr.HTML("""
|
| 112 |
<div style="text-align: center; max-width: 800px; margin: 0 auto;">
|
| 113 |
<h1 style="font-size: 3rem; font-weight: 700; margin-bottom: 1rem;">
|
|
@@ -120,24 +115,21 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
| 120 |
""")
|
| 121 |
|
| 122 |
with gr.Column(elem_id="col-container"):
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
run_button = gr.Button("✨ Generate", scale=0, variant="primary")
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
result = gr.Image(label="Result", show_label=False)
|
| 138 |
result_full = gr.Image(label="Gif Strip", elem_id="strip")
|
|
|
|
| 139 |
with gr.Accordion("Advanced Settings", open=False):
|
| 140 |
-
|
| 141 |
seed = gr.Slider(
|
| 142 |
label="Seed",
|
| 143 |
minimum=0,
|
|
@@ -145,31 +137,28 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
| 145 |
step=1,
|
| 146 |
value=0,
|
| 147 |
)
|
| 148 |
-
|
| 149 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 150 |
-
|
| 151 |
num_inference_steps = gr.Slider(
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
)
|
| 158 |
-
|
| 159 |
|
| 160 |
gr.Examples(
|
| 161 |
-
examples
|
| 162 |
-
inputs
|
| 163 |
-
outputs
|
| 164 |
fn=infer,
|
| 165 |
cache_examples="lazy"
|
| 166 |
)
|
| 167 |
-
|
| 168 |
gr.on(
|
| 169 |
triggers=[run_button.click, prompt.submit],
|
| 170 |
-
fn
|
| 171 |
-
inputs
|
| 172 |
-
outputs
|
| 173 |
)
|
| 174 |
|
| 175 |
demo.queue().launch()
|
|
|
|
| 17 |
torch_dtype = torch.float32
|
| 18 |
|
| 19 |
def split_image(input_image, num_splits=4):
|
|
|
|
| 20 |
output_images = []
|
|
|
|
|
|
|
| 21 |
for i in range(num_splits):
|
| 22 |
left = i * 320
|
| 23 |
right = (i + 1) * 320
|
| 24 |
box = (left, 0, right, 320)
|
| 25 |
output_images.append(input_image.crop(box))
|
|
|
|
| 26 |
return output_images
|
| 27 |
|
| 28 |
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch_dtype).to(device)
|
|
|
|
| 48 |
).images[0]
|
| 49 |
|
| 50 |
gif_name = f"{uuid.uuid4().hex}-flux.gif"
|
|
|
|
| 51 |
export_to_gif(split_image(image, 4), gif_name, fps=4)
|
| 52 |
|
| 53 |
return gif_name, image, seed
|
| 54 |
+
|
| 55 |
examples = [
|
| 56 |
"a red panda playing with a bamboo stick in the snow",
|
| 57 |
+
"an astronaut breakdancing on the moon",
|
| 58 |
"a magical butterfly transforming into sparkles",
|
| 59 |
"a robot learning to paint like Van Gogh",
|
| 60 |
"a dragon hatching from a crystal egg",
|
|
|
|
| 102 |
}
|
| 103 |
"""
|
| 104 |
|
| 105 |
+
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 106 |
gr.HTML("""
|
| 107 |
<div style="text-align: center; max-width: 800px; margin: 0 auto;">
|
| 108 |
<h1 style="font-size: 3rem; font-weight: 700; margin-bottom: 1rem;">
|
|
|
|
| 115 |
""")
|
| 116 |
|
| 117 |
with gr.Column(elem_id="col-container"):
|
| 118 |
+
with gr.Row():
|
| 119 |
+
prompt = gr.Text(
|
| 120 |
+
label="Your Animation Prompt",
|
| 121 |
+
show_label=True,
|
| 122 |
+
max_lines=1,
|
| 123 |
+
placeholder="Describe the animation you want to create...",
|
| 124 |
+
container=True,
|
| 125 |
+
elem_id="prompt-input"
|
| 126 |
+
)
|
| 127 |
+
run_button = gr.Button("✨ Generate", scale=0, variant="primary")
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
result = gr.Image(label="Result", show_label=False)
|
| 130 |
result_full = gr.Image(label="Gif Strip", elem_id="strip")
|
| 131 |
+
|
| 132 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
| 133 |
seed = gr.Slider(
|
| 134 |
label="Seed",
|
| 135 |
minimum=0,
|
|
|
|
| 137 |
step=1,
|
| 138 |
value=0,
|
| 139 |
)
|
|
|
|
| 140 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
|
|
|
| 141 |
num_inference_steps = gr.Slider(
|
| 142 |
+
label="Number of inference steps",
|
| 143 |
+
minimum=1,
|
| 144 |
+
maximum=32,
|
| 145 |
+
step=1,
|
| 146 |
+
value=28,
|
| 147 |
)
|
|
|
|
| 148 |
|
| 149 |
gr.Examples(
|
| 150 |
+
examples=examples,
|
| 151 |
+
inputs=[prompt],
|
| 152 |
+
outputs=[result, result_full, seed],
|
| 153 |
fn=infer,
|
| 154 |
cache_examples="lazy"
|
| 155 |
)
|
| 156 |
+
|
| 157 |
gr.on(
|
| 158 |
triggers=[run_button.click, prompt.submit],
|
| 159 |
+
fn=infer,
|
| 160 |
+
inputs=[prompt, seed, randomize_seed, num_inference_steps],
|
| 161 |
+
outputs=[result, result_full, seed]
|
| 162 |
)
|
| 163 |
|
| 164 |
demo.queue().launch()
|