Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ if not os.path.exists(SAVE_DIR):
|
|
16 |
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
repo_id = "black-forest-labs/FLUX.1-dev"
|
19 |
-
adapter_id = "openfree/paul-cezanne" #
|
20 |
|
21 |
pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
|
22 |
pipeline.load_lora_weights(adapter_id)
|
@@ -42,28 +42,6 @@ def save_generated_image(image, prompt):
|
|
42 |
|
43 |
return filepath
|
44 |
|
45 |
-
def load_generated_images():
|
46 |
-
if not os.path.exists(SAVE_DIR):
|
47 |
-
return []
|
48 |
-
|
49 |
-
# Load all images from the directory
|
50 |
-
image_files = [os.path.join(SAVE_DIR, f) for f in os.listdir(SAVE_DIR)
|
51 |
-
if f.endswith(('.png', '.jpg', '.jpeg', '.webp'))]
|
52 |
-
# Sort by creation time (newest first)
|
53 |
-
image_files.sort(key=lambda x: os.path.getctime(x), reverse=True)
|
54 |
-
return image_files
|
55 |
-
|
56 |
-
def load_predefined_images():
|
57 |
-
predefined_images = [
|
58 |
-
"assets/r1.webp",
|
59 |
-
"assets/r2.webp",
|
60 |
-
"assets/r3.webp",
|
61 |
-
"assets/r4.webp",
|
62 |
-
"assets/r5.webp",
|
63 |
-
"assets/r6.webp",
|
64 |
-
]
|
65 |
-
return predefined_images
|
66 |
-
|
67 |
@spaces.GPU(duration=120)
|
68 |
def inference(
|
69 |
prompt: str,
|
@@ -93,16 +71,16 @@ def inference(
|
|
93 |
# Save the generated image
|
94 |
filepath = save_generated_image(image, prompt)
|
95 |
|
96 |
-
# Return the image
|
97 |
-
return image, seed
|
98 |
|
99 |
examples = [
|
100 |
-
"
|
101 |
-
"
|
102 |
-
"
|
103 |
-
"
|
104 |
-
"
|
105 |
-
"
|
106 |
]
|
107 |
|
108 |
# Brighter custom CSS with vibrant colors
|
@@ -149,124 +127,85 @@ button:hover {
|
|
149 |
.tabs {
|
150 |
margin-top: 20px;
|
151 |
}
|
152 |
-
.gallery {
|
153 |
-
background-color: rgba(255, 255, 255, 0.5);
|
154 |
-
border-radius: 10px;
|
155 |
-
padding: 10px;
|
156 |
-
}
|
157 |
"""
|
158 |
|
159 |
with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
160 |
-
gr.HTML('<div class="title">
|
161 |
|
162 |
# Model description with the requested content
|
163 |
with gr.Group(elem_classes="model-description"):
|
|
|
164 |
|
165 |
-
|
166 |
-
with gr.
|
167 |
-
with gr.
|
168 |
-
|
169 |
-
|
170 |
-
prompt = gr.Text(
|
171 |
-
label="Prompt",
|
172 |
-
show_label=False,
|
173 |
-
max_lines=1,
|
174 |
-
placeholder="Enter your prompt (add [trigger] at the end)",
|
175 |
-
container=False,
|
176 |
-
)
|
177 |
-
run_button = gr.Button("Generate", variant="primary", scale=0)
|
178 |
-
|
179 |
-
result = gr.Image(label="Result", show_label=False)
|
180 |
-
|
181 |
-
with gr.Accordion("Advanced Settings", open=False):
|
182 |
-
seed = gr.Slider(
|
183 |
-
label="Seed",
|
184 |
-
minimum=0,
|
185 |
-
maximum=MAX_SEED,
|
186 |
-
step=1,
|
187 |
-
value=42,
|
188 |
-
)
|
189 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
190 |
-
|
191 |
-
with gr.Row():
|
192 |
-
width = gr.Slider(
|
193 |
-
label="Width",
|
194 |
-
minimum=256,
|
195 |
-
maximum=MAX_IMAGE_SIZE,
|
196 |
-
step=32,
|
197 |
-
value=1024,
|
198 |
-
)
|
199 |
-
height = gr.Slider(
|
200 |
-
label="Height",
|
201 |
-
minimum=256,
|
202 |
-
maximum=MAX_IMAGE_SIZE,
|
203 |
-
step=32,
|
204 |
-
value=768,
|
205 |
-
)
|
206 |
-
|
207 |
-
with gr.Row():
|
208 |
-
guidance_scale = gr.Slider(
|
209 |
-
label="Guidance scale",
|
210 |
-
minimum=0.0,
|
211 |
-
maximum=10.0,
|
212 |
-
step=0.1,
|
213 |
-
value=3.5,
|
214 |
-
)
|
215 |
-
num_inference_steps = gr.Slider(
|
216 |
-
label="Number of inference steps",
|
217 |
-
minimum=1,
|
218 |
-
maximum=50,
|
219 |
-
step=1,
|
220 |
-
value=30,
|
221 |
-
)
|
222 |
-
lora_scale = gr.Slider(
|
223 |
-
label="LoRA scale",
|
224 |
-
minimum=0.0,
|
225 |
-
maximum=1.0,
|
226 |
-
step=0.1,
|
227 |
-
value=1.0,
|
228 |
-
)
|
229 |
-
|
230 |
-
gr.Examples(
|
231 |
-
examples=examples,
|
232 |
-
inputs=[prompt],
|
233 |
-
outputs=[result, seed],
|
234 |
-
)
|
235 |
-
|
236 |
-
with gr.Tab("Gallery"):
|
237 |
-
gallery_header = gr.Markdown("### Your Generated Images")
|
238 |
-
generated_gallery = gr.Gallery(
|
239 |
-
label="Generated Images",
|
240 |
-
columns=3,
|
241 |
show_label=False,
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
height="auto"
|
246 |
)
|
247 |
-
|
248 |
|
249 |
-
|
250 |
-
gr.Markdown("### Pierre-Auguste Renoir Style Examples")
|
251 |
-
predefined_gallery = gr.Gallery(
|
252 |
-
label="Sample Images",
|
253 |
-
columns=3,
|
254 |
-
rows=2,
|
255 |
-
show_label=False,
|
256 |
-
value=load_predefined_images(),
|
257 |
-
elem_classes="gallery"
|
258 |
-
)
|
259 |
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
|
|
270 |
gr.on(
|
271 |
triggers=[run_button.click, prompt.submit],
|
272 |
fn=inference,
|
@@ -280,7 +219,7 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
280 |
num_inference_steps,
|
281 |
lora_scale,
|
282 |
],
|
283 |
-
outputs=[result, seed
|
284 |
)
|
285 |
|
286 |
demo.queue()
|
|
|
16 |
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
repo_id = "black-forest-labs/FLUX.1-dev"
|
19 |
+
adapter_id = "openfree/paul-cezanne" # Already correct as Cezanne model
|
20 |
|
21 |
pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
|
22 |
pipeline.load_lora_weights(adapter_id)
|
|
|
42 |
|
43 |
return filepath
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
@spaces.GPU(duration=120)
|
46 |
def inference(
|
47 |
prompt: str,
|
|
|
71 |
# Save the generated image
|
72 |
filepath = save_generated_image(image, prompt)
|
73 |
|
74 |
+
# Return just the image and seed (removed gallery)
|
75 |
+
return image, seed
|
76 |
|
77 |
examples = [
|
78 |
+
"Cézanne's painting of a lively outdoor dance scene at Moulin de la Galette, with dappled sunlight filtering through trees, illuminating well-dressed Parisians enjoying a summer afternoon. Couples dance while others socialize at tables, capturing the joie de vivre of 1870s Montmartre. [trigger]",
|
79 |
+
"Cézanne's intimate portrait of a young woman with rosy cheeks and lips, soft blonde hair, and a gentle smile. She wears a vibrant blue dress against a background of lush flowers and greenery, showcasing his mastery of depicting feminine beauty with warm, luminous skin tones. [trigger]",
|
80 |
+
"Cézanne's painting of two young girls seated at a piano, captured in his distinctive soft focus style. The scene shows one girl playing while the other stands beside her, both wearing delicate white dresses. The interior setting features warm colors and loose brushwork typical of his mature period. [trigger]",
|
81 |
+
"Cézanne's painting of an elegant boating party, with fashionably dressed men and women relaxing on a restaurant terrace overlooking the Seine. The scene captures the leisurely atmosphere of 1880s French society, with sparkling water reflections and a bright, airy palette of blues, whites, and warm flesh tones. [trigger]",
|
82 |
+
"Cézanne's painting of a sun-dappled garden scene with children playing. The composition features vibrant flowers in full bloom, lush greenery, and Cézanne's characteristic luminous treatment of sunlight filtering through foliage, creating patches of brilliant color across the canvas. [trigger]",
|
83 |
+
"Cézanne's depiction of bathers by a riverbank, with several female figures arranged in a harmonious composition. The painting showcases his later style with fuller figures rendered in pearlescent flesh tones against a backdrop of shimmering water and verdant landscape, demonstrating his unique approach to the nude figure in nature. [trigger]"
|
84 |
]
|
85 |
|
86 |
# Brighter custom CSS with vibrant colors
|
|
|
127 |
.tabs {
|
128 |
margin-top: 20px;
|
129 |
}
|
|
|
|
|
|
|
|
|
|
|
130 |
"""
|
131 |
|
132 |
with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
133 |
+
gr.HTML('<div class="title">Paul Cézanne STUDIO</div>')
|
134 |
|
135 |
# Model description with the requested content
|
136 |
with gr.Group(elem_classes="model-description"):
|
137 |
+
pass
|
138 |
|
139 |
+
# Simplified structure without tabs and gallery
|
140 |
+
with gr.Column(elem_id="col-container"):
|
141 |
+
with gr.Row():
|
142 |
+
prompt = gr.Text(
|
143 |
+
label="Prompt",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
show_label=False,
|
145 |
+
max_lines=1,
|
146 |
+
placeholder="Enter your prompt (add [trigger] at the end)",
|
147 |
+
container=False,
|
|
|
148 |
)
|
149 |
+
run_button = gr.Button("Generate", variant="primary", scale=0)
|
150 |
|
151 |
+
result = gr.Image(label="Result", show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
+
with gr.Accordion("Advanced Settings", open=False):
|
154 |
+
seed = gr.Slider(
|
155 |
+
label="Seed",
|
156 |
+
minimum=0,
|
157 |
+
maximum=MAX_SEED,
|
158 |
+
step=1,
|
159 |
+
value=42,
|
160 |
+
)
|
161 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
162 |
+
|
163 |
+
with gr.Row():
|
164 |
+
width = gr.Slider(
|
165 |
+
label="Width",
|
166 |
+
minimum=256,
|
167 |
+
maximum=MAX_IMAGE_SIZE,
|
168 |
+
step=32,
|
169 |
+
value=1024,
|
170 |
+
)
|
171 |
+
height = gr.Slider(
|
172 |
+
label="Height",
|
173 |
+
minimum=256,
|
174 |
+
maximum=MAX_IMAGE_SIZE,
|
175 |
+
step=32,
|
176 |
+
value=768,
|
177 |
+
)
|
178 |
|
179 |
+
with gr.Row():
|
180 |
+
guidance_scale = gr.Slider(
|
181 |
+
label="Guidance scale",
|
182 |
+
minimum=0.0,
|
183 |
+
maximum=10.0,
|
184 |
+
step=0.1,
|
185 |
+
value=3.5,
|
186 |
+
)
|
187 |
+
num_inference_steps = gr.Slider(
|
188 |
+
label="Number of inference steps",
|
189 |
+
minimum=1,
|
190 |
+
maximum=50,
|
191 |
+
step=1,
|
192 |
+
value=30,
|
193 |
+
)
|
194 |
+
lora_scale = gr.Slider(
|
195 |
+
label="LoRA scale",
|
196 |
+
minimum=0.0,
|
197 |
+
maximum=1.0,
|
198 |
+
step=0.1,
|
199 |
+
value=1.0,
|
200 |
+
)
|
201 |
+
|
202 |
+
gr.Examples(
|
203 |
+
examples=examples,
|
204 |
+
inputs=[prompt],
|
205 |
+
outputs=[result, seed],
|
206 |
+
)
|
207 |
|
208 |
+
# Event handlers - simplified to remove gallery functionality
|
209 |
gr.on(
|
210 |
triggers=[run_button.click, prompt.submit],
|
211 |
fn=inference,
|
|
|
219 |
num_inference_steps,
|
220 |
lora_scale,
|
221 |
],
|
222 |
+
outputs=[result, seed],
|
223 |
)
|
224 |
|
225 |
demo.queue()
|