Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import numpy as np
|
|
6 |
import os
|
7 |
import spaces
|
8 |
|
9 |
-
|
10 |
if torch.cuda.is_available():
|
11 |
device = "cuda"
|
12 |
print("Using GPU")
|
@@ -14,11 +13,9 @@ else:
|
|
14 |
device = "cpu"
|
15 |
print("Using CPU")
|
16 |
|
17 |
-
|
18 |
# login hf token
|
19 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
20 |
|
21 |
-
|
22 |
MAX_SEED = np.iinfo(np.int32).max
|
23 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
24 |
|
@@ -29,7 +26,6 @@ pipe.to(device)
|
|
29 |
# Enable memory optimizations
|
30 |
pipe.enable_attention_slicing()
|
31 |
|
32 |
-
|
33 |
# Define the image generation function
|
34 |
@spaces.GPU(duration=180)
|
35 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
@@ -38,7 +34,6 @@ def generate_image(prompt, num_inference_steps, height, width, guidance_scale, s
|
|
38 |
|
39 |
generator = torch.Generator().manual_seed(seed)
|
40 |
|
41 |
-
|
42 |
with torch.inference_mode():
|
43 |
output = pipe(
|
44 |
prompt=prompt,
|
@@ -52,14 +47,12 @@ def generate_image(prompt, num_inference_steps, height, width, guidance_scale, s
|
|
52 |
|
53 |
return output
|
54 |
|
55 |
-
|
56 |
-
|
57 |
# Create the Gradio interface
|
58 |
|
59 |
examples = [
|
60 |
-
["A
|
61 |
-
["
|
62 |
-
["
|
63 |
]
|
64 |
|
65 |
css = '''
|
@@ -69,19 +62,16 @@ h1{text-align:center}
|
|
69 |
with gr.Blocks(css=css) as demo:
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
-
gr.HTML(
|
73 |
-
"""
|
74 |
-
<h1 style='text-align: center'>
|
75 |
-
FLUX.1-dev
|
76 |
-
</h1>
|
77 |
-
"""
|
78 |
-
)
|
79 |
gr.HTML(
|
80 |
"""
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
"""
|
84 |
-
|
85 |
with gr.Group():
|
86 |
with gr.Column():
|
87 |
prompt = gr.Textbox(label="Prompt", info="Describe the image you want", placeholder="A cat...")
|
@@ -96,7 +86,7 @@ with gr.Blocks(css=css) as demo:
|
|
96 |
height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum=1024, step=32, value=1024)
|
97 |
with gr.Row():
|
98 |
seed = gr.Slider(value=42, minimum=0, maximum=MAX_SEED, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
99 |
-
num_images_per_prompt = gr.Slider(label="Images Per Prompt", info="Number of Images to generate with the settings",minimum=1, maximum=4, step=1, value=2)
|
100 |
|
101 |
gr.Examples(
|
102 |
examples=examples,
|
@@ -116,4 +106,4 @@ with gr.Blocks(css=css) as demo:
|
|
116 |
outputs=[result],
|
117 |
)
|
118 |
|
119 |
-
demo.queue().launch(share=False)
|
|
|
6 |
import os
|
7 |
import spaces
|
8 |
|
|
|
9 |
if torch.cuda.is_available():
|
10 |
device = "cuda"
|
11 |
print("Using GPU")
|
|
|
13 |
device = "cpu"
|
14 |
print("Using CPU")
|
15 |
|
|
|
16 |
# login hf token
|
17 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
18 |
|
|
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
20 |
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES", "0") == "1"
|
21 |
|
|
|
26 |
# Enable memory optimizations
|
27 |
pipe.enable_attention_slicing()
|
28 |
|
|
|
29 |
# Define the image generation function
|
30 |
@spaces.GPU(duration=180)
|
31 |
def generate_image(prompt, num_inference_steps, height, width, guidance_scale, seed, num_images_per_prompt, progress=gr.Progress(track_tqdm=True)):
|
|
|
34 |
|
35 |
generator = torch.Generator().manual_seed(seed)
|
36 |
|
|
|
37 |
with torch.inference_mode():
|
38 |
output = pipe(
|
39 |
prompt=prompt,
|
|
|
47 |
|
48 |
return output
|
49 |
|
|
|
|
|
50 |
# Create the Gradio interface
|
51 |
|
52 |
examples = [
|
53 |
+
["A serene landscape with a sunset over mountains"],
|
54 |
+
["A futuristic cityscape at night"],
|
55 |
+
["A playful dog in a field of flowers"],
|
56 |
]
|
57 |
|
58 |
css = '''
|
|
|
62 |
with gr.Blocks(css=css) as demo:
|
63 |
with gr.Row():
|
64 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
gr.HTML(
|
66 |
"""
|
67 |
+
<h1 style='text-align: center'>
|
68 |
+
FLUX.1-dev Image Generator
|
69 |
+
</h1>
|
70 |
+
<p style='text-align: center'>
|
71 |
+
Use this tool to generate stunning images based on your descriptive text prompts.
|
72 |
+
</p>
|
73 |
"""
|
74 |
+
)
|
75 |
with gr.Group():
|
76 |
with gr.Column():
|
77 |
prompt = gr.Textbox(label="Prompt", info="Describe the image you want", placeholder="A cat...")
|
|
|
86 |
height = gr.Slider(label="Height", info="Height of the Image", minimum=256, maximum=1024, step=32, value=1024)
|
87 |
with gr.Row():
|
88 |
seed = gr.Slider(value=42, minimum=0, maximum=MAX_SEED, step=1, label="Seed", info="A starting point to initiate the generation process, put 0 for a random one")
|
89 |
+
num_images_per_prompt = gr.Slider(label="Images Per Prompt", info="Number of Images to generate with the settings", minimum=1, maximum=4, step=1, value=2)
|
90 |
|
91 |
gr.Examples(
|
92 |
examples=examples,
|
|
|
106 |
outputs=[result],
|
107 |
)
|
108 |
|
109 |
+
demo.queue().launch(share=False)
|