Spaces:
Runtime error
Runtime error
nroggendorff
commited on
Commit
•
f043377
1
Parent(s):
d54e287
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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").to("cuda")
|
8 |
+
pipeline.enable_model_cpu_offload()
|
9 |
+
|
10 |
+
@spaces.GPU(duration=120)
|
11 |
+
def generate(prompt, negative_prompt, width, height, sample_steps):
|
12 |
+
return pipeline(prompt=f"{prompt}\nDO NOT INCLUDE {negative_prompt} FOR ANY REASON", width=width, height=height, num_inference_steps=sample_steps, generator=torch.Generator("cpu").manual_seed(127)).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 an extravagant 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 |
+
if __name__ == "__main__":
|
35 |
+
interface.launch()
|