Spaces:
Sleeping
Sleeping
halimbahae
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -11,30 +11,28 @@ if torch.cuda.is_available():
|
|
11 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
pipe.enable_xformers_memory_efficient_attention()
|
13 |
pipe = pipe.to(device)
|
14 |
-
else:
|
15 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
-
MAX_IMAGE_SIZE =
|
|
|
|
|
20 |
|
21 |
-
# Function to generate art with Moroccan and Amazigh styles
|
22 |
-
def infer(prompt, seed, randomize_seed, width, height):
|
23 |
-
# Add Moroccan and Amazigh art styles to the prompt
|
24 |
-
style_prompt = f"{prompt}, inspired by Moroccan and Amazigh arts, traditional motifs, vibrant colors, and intricate patterns."
|
25 |
-
|
26 |
if randomize_seed:
|
27 |
seed = random.randint(0, MAX_SEED)
|
28 |
|
29 |
generator = torch.Generator().manual_seed(seed)
|
30 |
|
31 |
image = pipe(
|
32 |
-
prompt=
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
).images[0]
|
39 |
|
40 |
return image
|
@@ -53,9 +51,6 @@ css="""
|
|
53 |
max-width: 840px;
|
54 |
color: #003366;
|
55 |
}
|
56 |
-
body {
|
57 |
-
background-color: white;
|
58 |
-
}
|
59 |
"""
|
60 |
|
61 |
if torch.cuda.is_available():
|
@@ -73,7 +68,7 @@ with gr.Blocks(css=css) as demo:
|
|
73 |
|
74 |
with gr.Row():
|
75 |
|
76 |
-
prompt = gr.
|
77 |
label="Prompt",
|
78 |
show_label=False,
|
79 |
max_lines=1,
|
@@ -85,38 +80,70 @@ with gr.Blocks(css=css) as demo:
|
|
85 |
|
86 |
result = gr.Image(label="Result", show_label=False)
|
87 |
|
88 |
-
with gr.
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
)
|
96 |
-
|
97 |
-
|
98 |
-
label="
|
99 |
-
minimum=
|
100 |
-
maximum=
|
101 |
-
step=
|
102 |
-
value=
|
103 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
gr.Examples(
|
106 |
-
examples=examples,
|
107 |
-
inputs=[prompt]
|
108 |
)
|
109 |
-
|
110 |
-
gr.Markdown("""
|
111 |
-
<div style="text-align: center;">
|
112 |
-
Built with ❤️ by <a href="https://www.linkedin.com/in/halimbahae/" target="_blank">Bahae Eddine HALIM</a>
|
113 |
-
</div>
|
114 |
-
""")
|
115 |
|
116 |
run_button.click(
|
117 |
-
fn=infer,
|
118 |
-
inputs=[prompt,
|
119 |
-
outputs=[result]
|
120 |
)
|
121 |
|
122 |
-
demo.queue().launch()
|
|
|
11 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
pipe.enable_xformers_memory_efficient_attention()
|
13 |
pipe = pipe.to(device)
|
14 |
+
else:
|
15 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
+
MAX_IMAGE_SIZE = 1024
|
20 |
+
|
21 |
+
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
if randomize_seed:
|
24 |
seed = random.randint(0, MAX_SEED)
|
25 |
|
26 |
generator = torch.Generator().manual_seed(seed)
|
27 |
|
28 |
image = pipe(
|
29 |
+
prompt = prompt,
|
30 |
+
negative_prompt = negative_prompt,
|
31 |
+
guidance_scale = guidance_scale,
|
32 |
+
num_inference_steps = num_inference_steps,
|
33 |
+
width = width,
|
34 |
+
height = height,
|
35 |
+
generator = generator
|
36 |
).images[0]
|
37 |
|
38 |
return image
|
|
|
51 |
max-width: 840px;
|
52 |
color: #003366;
|
53 |
}
|
|
|
|
|
|
|
54 |
"""
|
55 |
|
56 |
if torch.cuda.is_available():
|
|
|
68 |
|
69 |
with gr.Row():
|
70 |
|
71 |
+
prompt = gr.Text(
|
72 |
label="Prompt",
|
73 |
show_label=False,
|
74 |
max_lines=1,
|
|
|
80 |
|
81 |
result = gr.Image(label="Result", show_label=False)
|
82 |
|
83 |
+
with gr.Accordion("Advanced Settings", open=False):
|
84 |
+
|
85 |
+
negative_prompt = gr.Text(
|
86 |
+
label="Negative prompt",
|
87 |
+
max_lines=1,
|
88 |
+
placeholder="Enter a negative prompt",
|
89 |
+
visible=False,
|
90 |
)
|
91 |
+
|
92 |
+
seed = gr.Slider(
|
93 |
+
label="Seed",
|
94 |
+
minimum=0,
|
95 |
+
maximum=MAX_SEED,
|
96 |
+
step=1,
|
97 |
+
value=0,
|
98 |
)
|
99 |
+
|
100 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
101 |
+
|
102 |
+
with gr.Row():
|
103 |
+
|
104 |
+
width = gr.Slider(
|
105 |
+
label="Width",
|
106 |
+
minimum=256,
|
107 |
+
maximum=MAX_IMAGE_SIZE,
|
108 |
+
step=32,
|
109 |
+
value=1024,
|
110 |
+
)
|
111 |
+
|
112 |
+
height = gr.Slider(
|
113 |
+
label="Height",
|
114 |
+
minimum=256,
|
115 |
+
maximum=MAX_IMAGE_SIZE,
|
116 |
+
step=32,
|
117 |
+
value=1024,
|
118 |
+
)
|
119 |
+
|
120 |
+
with gr.Row():
|
121 |
+
|
122 |
+
guidance_scale = gr.Slider(
|
123 |
+
label="Guidance scale",
|
124 |
+
minimum=0.0,
|
125 |
+
maximum=10.0,
|
126 |
+
step=0.1,
|
127 |
+
value=0.0,
|
128 |
+
)
|
129 |
+
|
130 |
+
num_inference_steps = gr.Slider(
|
131 |
+
label="Number of inference steps",
|
132 |
+
minimum=1,
|
133 |
+
maximum=12,
|
134 |
+
step=1,
|
135 |
+
value=2,
|
136 |
+
)
|
137 |
|
138 |
gr.Examples(
|
139 |
+
examples = examples,
|
140 |
+
inputs = [prompt]
|
141 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
run_button.click(
|
144 |
+
fn = infer,
|
145 |
+
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
146 |
+
outputs = [result]
|
147 |
)
|
148 |
|
149 |
+
demo.queue().launch()
|