Spaces:
Paused
Paused
requirements.txt
Browse filesdiffusers
transformers
accelerate
torch
spaces
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import gradio as grimport numpy as npimport randomimport spacesimport torchfrom diffusers import DiffusionPipeline
dtype = torch.bfloat16device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
MAX_SEED = np.iinfo(np.int32).maxWIDTH = 700HEIGHT = 900
@spaces.GPU()def infer(prompt, progress=gr.Progress(track_tqdm=True)): seed = random.randint(0, MAX_SEED) generator = torch.Generator().manual_seed(seed) image = pipe( prompt=prompt, width=WIDTH, height=HEIGHT, num_inference_steps=4, generator=generator, guidance_scale=0.0, ).images[0]
out_path = "/tmp/generated.png" image.save(out_path) return image, gr.update(value=out_path, visible=True)
css = """#col-container { margin: 0 auto; max-width: 700px; }"""
with gr.Blocks(css=css) as demo: with gr.Column(elem_id="col-container"): prompt = gr.Textbox( label=None, show_label=False, placeholder="Describe the image...", lines=2, ) with gr.Row(): run_button = gr.Button("Generate", variant="primary") download_button = gr.DownloadButton("Save", visible=False)
result = gr.Image(show_label=False, width=WIDTH, height=HEIGHT)
gr.on( triggers=[run_button.click, prompt.submit], fn=infer, inputs=[prompt], outputs=[result, download_button], )
demo.launch()app.pyAdded+61