Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
d = "cuda" if torch.cuda.is_available() else False | |
if d: | |
import spaces | |
from diffusers import FluxPipeline | |
pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to(d) | |
#pipeline.enable_model_cpu_offload() | |
def generate(prompt, negative_prompt, width, height, sample_steps): | |
return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, guidance_scale=7).images[0] | |
with gr.Blocks() as demo: | |
with gr.Column(): | |
with gr.Row(): | |
with gr.Column(): | |
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="Keanu Reeves holding a neon sign reading 'Hello, world!', 32k HDR, paparazzi", lines=4, interactive=True) | |
negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="ugly, low quality", lines=4, interactive=True) | |
with gr.Column(): | |
generate_button = gr.Button("Generate") | |
output = gr.Image() | |
with gr.Row(): | |
with gr.Accordion(label="Advanced Settings", open=False): | |
with gr.Row(): | |
with gr.Column(): | |
width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True) | |
height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True) | |
with gr.Column(): | |
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True) | |
generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output]) | |
else: | |
def show_message(): | |
return "# This is the legacy space. To access the app, [click here](https://huggingface.co/spaces/nroggendorff/flux-lora-tester)" | |
demo = gr.Interface(fn=show_message, | |
inputs=None, | |
outputs="markdown") | |
if __name__ == "__main__": | |
demo.launch() |