nroggendorff commited on
Commit
eaa88ce
·
verified ·
1 Parent(s): bae8aa6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import spaces
3
+ import random
4
+
5
+ import torch
6
+ from diffusers import FluxPipeline
7
+ from huggingface_hub.utils import RepositoryNotFoundError
8
+
9
+ pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
10
+
11
+ @spaces.GPU(duration=70)
12
+ def generate(prompt, negative_prompt, width, height, sample_steps, lora_id):
13
+ try:
14
+ pipeline.load_lora_weights(lora_id)
15
+ except RepositoryNotFoundError:
16
+ raise ValueError(f"Recieved invalid FLUX LoRA.")
17
+
18
+ return pipeline(prompt=f"{prompt}\n(NOT {negative_prompt}:2)", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(random.randint(42, 69)), guidance_scale=7).images[0]
19
+
20
+ with gr.Blocks() as interface:
21
+ with gr.Column():
22
+ with gr.Row():
23
+ with gr.Column():
24
+ 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)
25
+ 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)
26
+ with gr.Column():
27
+ generate_button = gr.Button("Generate")
28
+ output = gr.Image()
29
+ with gr.Row():
30
+ with gr.Accordion(label="Advanced Settings", open=False):
31
+ with gr.Row():
32
+ with gr.Column():
33
+ width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
34
+ height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
35
+ with gr.Column():
36
+ sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
37
+ lora_id = gr.Textbox(label="Adapter Repository", info="ID of the FLUX LoRA", value="pepper13/fluxfw")
38
+
39
+ generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps, lora_id], outputs=[output])
40
+
41
+ if __name__ == "__main__":
42
+ interface.launch()