Spaces:
Running
on
Zero
Running
on
Zero
Alexander Bagus
commited on
Commit
·
00842ed
1
Parent(s):
cee9e79
22
Browse files
app.py
CHANGED
|
@@ -68,14 +68,16 @@ def generate_lora(
|
|
| 68 |
ulid = str(ULID()).lower()[:12]
|
| 69 |
print(f"ulid: {ulid}")
|
| 70 |
|
|
|
|
|
|
|
| 71 |
# Load images
|
| 72 |
-
images = [
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
]
|
| 79 |
|
| 80 |
|
| 81 |
# Model inference
|
|
@@ -88,15 +90,18 @@ def generate_lora(
|
|
| 88 |
|
| 89 |
save_file(lora, lora_path)
|
| 90 |
|
| 91 |
-
return
|
| 92 |
|
| 93 |
@spaces.GPU
|
| 94 |
def generate_image(
|
|
|
|
| 95 |
prompt,
|
| 96 |
-
negative_prompt,
|
|
|
|
|
|
|
| 97 |
seed=42,
|
| 98 |
randomize_seed=True,
|
| 99 |
-
guidance_scale=
|
| 100 |
num_inference_steps=8,
|
| 101 |
progress=gr.Progress(track_tqdm=True),
|
| 102 |
):
|
|
@@ -119,6 +124,9 @@ h3{
|
|
| 119 |
text-align: center;
|
| 120 |
display:block;
|
| 121 |
}
|
|
|
|
|
|
|
|
|
|
| 122 |
"""
|
| 123 |
|
| 124 |
|
|
@@ -131,7 +139,8 @@ with gr.Blocks() as demo:
|
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column():
|
| 133 |
input_images = gr.Gallery(
|
| 134 |
-
label="
|
|
|
|
| 135 |
show_label=False,
|
| 136 |
elem_id="gallery",
|
| 137 |
columns=2,
|
|
@@ -141,9 +150,9 @@ with gr.Blocks() as demo:
|
|
| 141 |
lora_button = gr.Button("Generate LoRA", variant="primary")
|
| 142 |
|
| 143 |
with gr.Column():
|
| 144 |
-
|
| 145 |
lora_download = gr.DownloadButton(label=f"Download LoRA", visible=False)
|
| 146 |
-
with gr.Column(visible=False) as imagen_container:
|
| 147 |
gr.Markdown("### After your LoRA is ready, you can try generate image here.")
|
| 148 |
with gr.Row():
|
| 149 |
with gr.Column():
|
|
@@ -158,47 +167,52 @@ with gr.Blocks() as demo:
|
|
| 158 |
|
| 159 |
imagen_button = gr.Button("Generate Image", variant="primary")
|
| 160 |
with gr.Accordion("Advanced Settings", open=False):
|
| 161 |
-
|
| 162 |
negative_prompt = gr.Textbox(
|
| 163 |
label="Negative prompt",
|
| 164 |
lines=2,
|
| 165 |
container=False,
|
| 166 |
placeholder="Enter your negative prompt",
|
| 167 |
-
value="blurry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
)
|
| 169 |
with gr.Row():
|
| 170 |
-
|
| 171 |
-
label="
|
| 172 |
-
minimum=
|
| 173 |
-
maximum=
|
| 174 |
-
step=
|
| 175 |
-
value=
|
| 176 |
-
)
|
| 177 |
-
control_context_scale = gr.Slider(
|
| 178 |
-
label="Context scale",
|
| 179 |
-
minimum=0.0,
|
| 180 |
-
maximum=1.0,
|
| 181 |
-
step=0.01,
|
| 182 |
-
value=0.75,
|
| 183 |
)
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
guidance_scale = gr.Slider(
|
| 187 |
label="Guidance scale",
|
| 188 |
minimum=0.0,
|
| 189 |
maximum=10.0,
|
| 190 |
step=0.1,
|
| 191 |
-
value=
|
| 192 |
)
|
| 193 |
-
|
| 194 |
-
seed = gr.Slider(
|
| 195 |
-
label="Seed",
|
| 196 |
-
minimum=0,
|
| 197 |
-
maximum=MAX_SEED,
|
| 198 |
-
step=1,
|
| 199 |
-
value=42,
|
| 200 |
-
)
|
| 201 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=False)
|
| 202 |
|
| 203 |
with gr.Column():
|
| 204 |
output_image = gr.Image(label="Generated image", show_label=False)
|
|
@@ -211,7 +225,22 @@ with gr.Blocks() as demo:
|
|
| 211 |
inputs=[
|
| 212 |
input_images
|
| 213 |
],
|
| 214 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
)
|
| 216 |
|
| 217 |
|
|
|
|
| 68 |
ulid = str(ULID()).lower()[:12]
|
| 69 |
print(f"ulid: {ulid}")
|
| 70 |
|
| 71 |
+
if not images:
|
| 72 |
+
print("images is empty.")
|
| 73 |
# Load images
|
| 74 |
+
# images = [
|
| 75 |
+
# Image.open("examples/style/1/0.jpg"),
|
| 76 |
+
# Image.open("examples/style/1/1.jpg"),
|
| 77 |
+
# Image.open("examples/style/1/2.jpg"),
|
| 78 |
+
# Image.open("examples/style/1/3.jpg"),
|
| 79 |
+
# Image.open("examples/style/1/4.jpg"),
|
| 80 |
+
# ]
|
| 81 |
|
| 82 |
|
| 83 |
# Model inference
|
|
|
|
| 90 |
|
| 91 |
save_file(lora, lora_path)
|
| 92 |
|
| 93 |
+
return lora_name, gr.update(visible=True, value=lora_path), gr.update(visible=True)
|
| 94 |
|
| 95 |
@spaces.GPU
|
| 96 |
def generate_image(
|
| 97 |
+
lora_name,
|
| 98 |
prompt,
|
| 99 |
+
negative_prompt="blurry ugly bad",
|
| 100 |
+
width=1024,
|
| 101 |
+
height=1024,
|
| 102 |
seed=42,
|
| 103 |
randomize_seed=True,
|
| 104 |
+
guidance_scale=3.5,
|
| 105 |
num_inference_steps=8,
|
| 106 |
progress=gr.Progress(track_tqdm=True),
|
| 107 |
):
|
|
|
|
| 124 |
text-align: center;
|
| 125 |
display:block;
|
| 126 |
}
|
| 127 |
+
#imagen-container {
|
| 128 |
+
padding: 12px;
|
| 129 |
+
}
|
| 130 |
"""
|
| 131 |
|
| 132 |
|
|
|
|
| 139 |
with gr.Row():
|
| 140 |
with gr.Column():
|
| 141 |
input_images = gr.Gallery(
|
| 142 |
+
label="Input images",
|
| 143 |
+
file_types=["image"],
|
| 144 |
show_label=False,
|
| 145 |
elem_id="gallery",
|
| 146 |
columns=2,
|
|
|
|
| 150 |
lora_button = gr.Button("Generate LoRA", variant="primary")
|
| 151 |
|
| 152 |
with gr.Column():
|
| 153 |
+
lora_name = gr.Textbox(label="Generated LoRA path",lines=2, interactive=False)
|
| 154 |
lora_download = gr.DownloadButton(label=f"Download LoRA", visible=False)
|
| 155 |
+
with gr.Column(visible=False, elem_classes='imagen-container') as imagen_container:
|
| 156 |
gr.Markdown("### After your LoRA is ready, you can try generate image here.")
|
| 157 |
with gr.Row():
|
| 158 |
with gr.Column():
|
|
|
|
| 167 |
|
| 168 |
imagen_button = gr.Button("Generate Image", variant="primary")
|
| 169 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
| 170 |
negative_prompt = gr.Textbox(
|
| 171 |
label="Negative prompt",
|
| 172 |
lines=2,
|
| 173 |
container=False,
|
| 174 |
placeholder="Enter your negative prompt",
|
| 175 |
+
value="blurry ugly bad"
|
| 176 |
+
)
|
| 177 |
+
num_inference_steps = gr.Slider(
|
| 178 |
+
label="Steps",
|
| 179 |
+
minimum=1,
|
| 180 |
+
maximum=50,
|
| 181 |
+
step=1,
|
| 182 |
+
value=20,
|
| 183 |
)
|
| 184 |
with gr.Row():
|
| 185 |
+
width = gr.Slider(
|
| 186 |
+
label="Width",
|
| 187 |
+
minimum=512,
|
| 188 |
+
maximum=1280,
|
| 189 |
+
step=32,
|
| 190 |
+
value=768,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
)
|
| 192 |
|
| 193 |
+
height = gr.Slider(
|
| 194 |
+
label="Height",
|
| 195 |
+
minimum=512,
|
| 196 |
+
maximum=1280,
|
| 197 |
+
step=32,
|
| 198 |
+
value=1024,
|
| 199 |
+
)
|
| 200 |
with gr.Row():
|
| 201 |
+
seed = gr.Slider(
|
| 202 |
+
label="Seed",
|
| 203 |
+
minimum=0,
|
| 204 |
+
maximum=MAX_SEED,
|
| 205 |
+
step=1,
|
| 206 |
+
value=42,
|
| 207 |
+
)
|
| 208 |
guidance_scale = gr.Slider(
|
| 209 |
label="Guidance scale",
|
| 210 |
minimum=0.0,
|
| 211 |
maximum=10.0,
|
| 212 |
step=0.1,
|
| 213 |
+
value=3.5,
|
| 214 |
)
|
| 215 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
with gr.Column():
|
| 218 |
output_image = gr.Image(label="Generated image", show_label=False)
|
|
|
|
| 225 |
inputs=[
|
| 226 |
input_images
|
| 227 |
],
|
| 228 |
+
outputs=[lora_name, lora_download, imagen_container],
|
| 229 |
+
)
|
| 230 |
+
imagen_button.click(
|
| 231 |
+
fn=generate_image,
|
| 232 |
+
inputs=[
|
| 233 |
+
lora_name,
|
| 234 |
+
prompt,
|
| 235 |
+
negative_prompt,
|
| 236 |
+
width,
|
| 237 |
+
height,
|
| 238 |
+
seed,
|
| 239 |
+
randomize_seed,
|
| 240 |
+
guidance_scale,
|
| 241 |
+
num_inference_steps,
|
| 242 |
+
],
|
| 243 |
+
outputs=[lora_name, lora_download, imagen_container],
|
| 244 |
)
|
| 245 |
|
| 246 |
|