Spaces:
Running
Running
nroggendorff
commited on
Commit
•
36fe024
1
Parent(s):
f500d03
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,47 @@
|
|
1 |
import gradio as gr
|
2 |
-
import spaces
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
with gr.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
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()
|