Spaces:
Sleeping
Sleeping
halimbahae
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -16,28 +16,32 @@ else:
|
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
19 |
|
20 |
-
def infer(prompt, width, height):
|
21 |
-
|
|
|
|
|
22 |
generator = torch.Generator().manual_seed(seed)
|
23 |
|
24 |
image = pipe(
|
25 |
-
prompt=prompt,
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
).images[0]
|
32 |
|
33 |
return image
|
34 |
|
35 |
examples = [
|
36 |
"Sunset over the Atlas Mountains",
|
|
|
37 |
"Flying carpet in space",
|
38 |
"Unicorn riding a camel in the Sahara Desert",
|
39 |
"Moroccan souk floating in the sky",
|
40 |
-
"Traditional Amazigh jewelry under the moonlight"
|
41 |
]
|
42 |
|
43 |
css="""
|
@@ -62,11 +66,11 @@ with gr.Blocks(css=css) as demo:
|
|
62 |
gr.Markdown(f"""
|
63 |
# bibou.jpeg
|
64 |
Generate Moroccan folkloric pictures, inspired by Moroccan and Amazigh arts. 🎨🎶
|
65 |
-
Currently running on {power_device}.
|
66 |
""")
|
67 |
|
68 |
with gr.Row():
|
69 |
-
|
|
|
70 |
label="Prompt",
|
71 |
show_label=False,
|
72 |
max_lines=1,
|
@@ -78,26 +82,64 @@ with gr.Blocks(css=css) as demo:
|
|
78 |
|
79 |
result = gr.Image(label="Result", show_label=False)
|
80 |
|
81 |
-
with gr.
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
)
|
89 |
-
|
90 |
-
|
91 |
-
label="
|
92 |
-
minimum=
|
93 |
-
maximum=
|
94 |
-
step=
|
95 |
-
value=
|
96 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
gr.Examples(
|
99 |
-
examples=examples,
|
100 |
-
inputs=[prompt]
|
101 |
)
|
102 |
|
103 |
gr.Markdown("""
|
@@ -107,9 +149,9 @@ with gr.Blocks(css=css) as demo:
|
|
107 |
""")
|
108 |
|
109 |
run_button.click(
|
110 |
-
fn=infer,
|
111 |
-
inputs=[prompt, width, height],
|
112 |
-
outputs=[result]
|
113 |
)
|
114 |
|
115 |
demo.queue().launch()
|
|
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
+
MAX_IMAGE_SIZE = 2048
|
20 |
|
21 |
+
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
+
if randomize_seed:
|
23 |
+
seed = random.randint(0, MAX_SEED)
|
24 |
+
|
25 |
generator = torch.Generator().manual_seed(seed)
|
26 |
|
27 |
image = pipe(
|
28 |
+
prompt = prompt,
|
29 |
+
negative_prompt = negative_prompt,
|
30 |
+
guidance_scale = guidance_scale,
|
31 |
+
num_inference_steps = num_inference_steps,
|
32 |
+
width = width,
|
33 |
+
height = height,
|
34 |
+
generator = generator
|
35 |
).images[0]
|
36 |
|
37 |
return image
|
38 |
|
39 |
examples = [
|
40 |
"Sunset over the Atlas Mountains",
|
41 |
+
"Traditional Amazigh jewelry under the moonlight",
|
42 |
"Flying carpet in space",
|
43 |
"Unicorn riding a camel in the Sahara Desert",
|
44 |
"Moroccan souk floating in the sky",
|
|
|
45 |
]
|
46 |
|
47 |
css="""
|
|
|
66 |
gr.Markdown(f"""
|
67 |
# bibou.jpeg
|
68 |
Generate Moroccan folkloric pictures, inspired by Moroccan and Amazigh arts. 🎨🎶
|
|
|
69 |
""")
|
70 |
|
71 |
with gr.Row():
|
72 |
+
|
73 |
+
prompt = gr.Text(
|
74 |
label="Prompt",
|
75 |
show_label=False,
|
76 |
max_lines=1,
|
|
|
82 |
|
83 |
result = gr.Image(label="Result", show_label=False)
|
84 |
|
85 |
+
with gr.Accordion("Advanced Settings", open=False):
|
86 |
+
|
87 |
+
negative_prompt = gr.Text(
|
88 |
+
label="Negative prompt",
|
89 |
+
max_lines=1,
|
90 |
+
placeholder="Enter a negative prompt",
|
91 |
+
visible=False,
|
92 |
)
|
93 |
+
|
94 |
+
seed = gr.Slider(
|
95 |
+
label="Seed",
|
96 |
+
minimum=0,
|
97 |
+
maximum=MAX_SEED,
|
98 |
+
step=1,
|
99 |
+
value=0,
|
100 |
)
|
101 |
+
|
102 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
103 |
+
|
104 |
+
with gr.Row():
|
105 |
+
|
106 |
+
width = gr.Slider(
|
107 |
+
label="Width",
|
108 |
+
minimum=256,
|
109 |
+
maximum=MAX_IMAGE_SIZE,
|
110 |
+
step=32,
|
111 |
+
value=1024,
|
112 |
+
)
|
113 |
+
|
114 |
+
height = gr.Slider(
|
115 |
+
label="Height",
|
116 |
+
minimum=256,
|
117 |
+
maximum=MAX_IMAGE_SIZE,
|
118 |
+
step=32,
|
119 |
+
value=1024,
|
120 |
+
)
|
121 |
+
|
122 |
+
with gr.Row():
|
123 |
+
|
124 |
+
guidance_scale = gr.Slider(
|
125 |
+
label="Guidance scale",
|
126 |
+
minimum=0.0,
|
127 |
+
maximum=10.0,
|
128 |
+
step=0.1,
|
129 |
+
value=0.0,
|
130 |
+
)
|
131 |
+
|
132 |
+
num_inference_steps = gr.Slider(
|
133 |
+
label="Number of inference steps",
|
134 |
+
minimum=1,
|
135 |
+
maximum=12,
|
136 |
+
step=1,
|
137 |
+
value=2,
|
138 |
+
)
|
139 |
|
140 |
gr.Examples(
|
141 |
+
examples = examples,
|
142 |
+
inputs = [prompt]
|
143 |
)
|
144 |
|
145 |
gr.Markdown("""
|
|
|
149 |
""")
|
150 |
|
151 |
run_button.click(
|
152 |
+
fn = infer,
|
153 |
+
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
154 |
+
outputs = [result]
|
155 |
)
|
156 |
|
157 |
demo.queue().launch()
|