Spaces:
Runtime error
Runtime error
File size: 3,224 Bytes
e9525f4 0da6070 e9525f4 a1fbcab e9525f4 81d8c77 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
import os
import numpy as np
import gradio as gr
from utils.i2i import i2i_gen
MAX_SEED = np.iinfo(np.int32).max
with gr.Blocks(
title="πͺ LayerDiffuse - Flux version (Image to Image)",
theme="CultriX/gradio-theme"
) as demo:
gr.Markdown(
"""
# πͺ LayerDiffuse - Flux version (Image to Image)
A Flux version implementation of LayerDiffuse for image-to-image generation.
Upload an image with transparency (PNG with alpha channel) and transform it with a text prompt.
The output image will maintain the same aspect ratio as your input image.
"""
)
with gr.Row():
with gr.Column(scale=1):
input_image = gr.Image(
label="Input Image",
type="pil",
sources=["upload", "webcam", "clipboard"],
image_mode="RGBA",
height=512
)
prompt = gr.Text(
label="Prompt",
info="Describe what you want to generate",
placeholder="E.g: a beautiful landscape with mountains, high quality"
)
with gr.Row():
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=MAX_SEED,
step=1,
value=0,
randomize=True
)
strength = gr.Slider(
label="Strength",
minimum=0.0,
maximum=1.0,
step=0.01,
value=0.5,
info="How much to transform the image (0 = no change, 1 = complete change)"
)
with gr.Row():
guidance_scale = gr.Slider(
label="Guidance scale",
minimum=1,
maximum=20,
step=0.1,
value=7.0,
)
num_inference_steps = gr.Slider(
label="Steps",
minimum=10,
maximum=100,
step=1,
value=50,
)
generate_btn = gr.Button("Generate", variant="primary")
with gr.Column(scale=1):
output_image = gr.Image(
label="Result",
type="pil",
height=512
)
# Set up the generation flow
gr.on(
triggers=[generate_btn.click],
fn=lambda: gr.update(interactive=False, value="Generating..."),
outputs=generate_btn,
api_name=False
).then(
fn=i2i_gen,
inputs=[
input_image,
prompt,
seed,
guidance_scale,
num_inference_steps,
strength
],
outputs=output_image
).then(
fn=lambda: gr.update(interactive=True, value="Generate"),
outputs=generate_btn,
api_name=False
)
if __name__ == "__main__":
demo.queue(max_size=20).launch(show_error=True, share=True) |