nroggendorff commited on
Commit
36fe024
1 Parent(s): f500d03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -39
app.py CHANGED
@@ -1,44 +1,47 @@
1
  import gradio as gr
2
- import spaces
3
 
4
- import torch
5
- from diffusers import FluxPipeline
6
-
7
- pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to("cuda")
8
- #pipeline.enable_model_cpu_offload()
9
-
10
- @spaces.GPU(duration=70)
11
- def generate(prompt, negative_prompt, width, height, sample_steps):
12
- return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(42), guidance_scale=7).images[0]
13
-
14
- with gr.Blocks() as interface:
15
- with gr.Column():
16
- with gr.Row():
17
- with gr.Column():
18
- 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)
19
- 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)
20
- with gr.Column():
21
- generate_button = gr.Button("Generate")
22
- output = gr.Image()
23
- with gr.Row():
24
- with gr.Accordion(label="Advanced Settings", open=False):
25
- with gr.Row():
26
- with gr.Column():
27
- width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
28
- height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
29
- with gr.Column():
30
- sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
31
-
32
- generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output])
33
-
34
- def show_message():
35
- return "# This is the legacy space, to access the app, [click here](https://huggingface.co/spaces/nroggendorff/flux-lora-tester)"
36
-
37
- iface = gr.Interface(fn=show_message,
38
- inputs=None,
39
- outputs="markdown")
40
-
41
- demo = interface if torch.cuda.is_available else iface
 
 
 
 
42
 
43
  if __name__ == "__main__":
44
  demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ d = "cuda" if torch.cuda.is_available else False
4
+
5
+ if d:
6
+ import spaces
7
+
8
+ import torch
9
+ from diffusers import FluxPipeline
10
+
11
+ pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.float16).to(d)
12
+ #pipeline.enable_model_cpu_offload()
13
+
14
+ @spaces.GPU(duration=70)
15
+ def generate(prompt, negative_prompt, width, height, sample_steps):
16
+ return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt}", width=width, height=height, num_inference_steps=sample_steps, guidance_scale=7).images[0]
17
+
18
+ with gr.Blocks() as demo:
19
+ with gr.Column():
20
+ with gr.Row():
21
+ with gr.Column():
22
+ 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)
23
+ 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)
24
+ with gr.Column():
25
+ generate_button = gr.Button("Generate")
26
+ output = gr.Image()
27
+ with gr.Row():
28
+ with gr.Accordion(label="Advanced Settings", open=False):
29
+ with gr.Row():
30
+ with gr.Column():
31
+ width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
32
+ height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=512, minimum=128, maximum=4096, step=64, interactive=True)
33
+ with gr.Column():
34
+ sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
35
+
36
+ generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output])
37
+
38
+ else:
39
+ def show_message():
40
+ return "# This is the legacy space, to access the app, [click here](https://huggingface.co/spaces/nroggendorff/flux-lora-tester)"
41
+
42
+ demo = gr.Interface(fn=show_message,
43
+ inputs=None,
44
+ outputs="markdown")
45
 
46
  if __name__ == "__main__":
47
  demo.launch()