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)
|
@@ -71,94 +71,168 @@ def inference(
|
|
71 |
# Save the generated image
|
72 |
filepath = save_generated_image(image, prompt)
|
73 |
|
74 |
-
# Return just the image and seed
|
75 |
return image, seed
|
76 |
|
|
|
77 |
examples = [
|
78 |
-
"Cézanne's painting of a lively outdoor
|
79 |
-
"Cézanne's intimate portrait of a young woman
|
80 |
-
"Cézanne's painting of two young girls seated at a piano
|
81 |
-
"Cézanne's painting of an elegant boating party, with
|
82 |
-
"Cézanne's painting of
|
83 |
-
"Cézanne's depiction of bathers
|
84 |
]
|
85 |
|
86 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
custom_css = """
|
88 |
:root {
|
89 |
-
--color-primary: #
|
90 |
-
--color-secondary: #
|
|
|
91 |
}
|
|
|
92 |
footer {
|
93 |
visibility: hidden;
|
94 |
}
|
|
|
95 |
.gradio-container {
|
96 |
-
background:
|
97 |
}
|
|
|
98 |
.title {
|
99 |
-
color:
|
100 |
-
font-size:
|
101 |
font-weight: 700 !important;
|
102 |
text-align: center;
|
103 |
margin: 1rem 0;
|
104 |
-
text-shadow: 2px 2px 4px rgba(0,0,0,0.
|
|
|
105 |
}
|
|
|
106 |
.subtitle {
|
107 |
-
color: #
|
108 |
font-size: 1.2rem !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
text-align: center;
|
110 |
margin-bottom: 2rem;
|
|
|
111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
.model-description {
|
113 |
-
background-color: rgba(255, 255, 255, 0.
|
114 |
-
border-radius:
|
115 |
-
padding:
|
116 |
margin: 20px 0;
|
117 |
-
box-shadow: 0 4px
|
118 |
-
border-left: 5px solid
|
119 |
}
|
|
|
120 |
button.primary {
|
121 |
-
background-color:
|
|
|
122 |
}
|
|
|
123 |
button:hover {
|
124 |
transform: translateY(-2px);
|
125 |
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
126 |
}
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
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="
|
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=
|
160 |
)
|
161 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=
|
162 |
|
163 |
with gr.Row():
|
164 |
width = gr.Slider(
|
@@ -166,14 +240,14 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
166 |
minimum=256,
|
167 |
maximum=MAX_IMAGE_SIZE,
|
168 |
step=32,
|
169 |
-
value=
|
170 |
)
|
171 |
height = gr.Slider(
|
172 |
label="Height",
|
173 |
minimum=256,
|
174 |
maximum=MAX_IMAGE_SIZE,
|
175 |
step=32,
|
176 |
-
value=
|
177 |
)
|
178 |
|
179 |
with gr.Row():
|
@@ -182,30 +256,34 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
182 |
minimum=0.0,
|
183 |
maximum=10.0,
|
184 |
step=0.1,
|
185 |
-
value=
|
186 |
)
|
187 |
num_inference_steps = gr.Slider(
|
188 |
label="Number of inference steps",
|
189 |
minimum=1,
|
190 |
maximum=50,
|
191 |
step=1,
|
192 |
-
value=
|
193 |
)
|
194 |
lora_scale = gr.Slider(
|
195 |
label="LoRA scale",
|
196 |
minimum=0.0,
|
197 |
maximum=1.0,
|
198 |
step=0.1,
|
199 |
-
value=
|
200 |
)
|
201 |
|
202 |
-
gr.
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
207 |
|
208 |
-
# Event handlers
|
209 |
gr.on(
|
210 |
triggers=[run_button.click, prompt.submit],
|
211 |
fn=inference,
|
@@ -221,6 +299,13 @@ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
|
221 |
],
|
222 |
outputs=[result, seed],
|
223 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
demo.queue()
|
226 |
demo.launch()
|
|
|
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)
|
|
|
71 |
# Save the generated image
|
72 |
filepath = save_generated_image(image, prompt)
|
73 |
|
74 |
+
# Return just the image and seed
|
75 |
return image, seed
|
76 |
|
77 |
+
# Updated examples with 1880s clothing style
|
78 |
examples = [
|
79 |
+
"Cézanne's painting of a lively outdoor gathering in the 1880s, with men in formal top hats, frock coats, and women in bustled dresses with elaborate hats, enjoying a summer afternoon. The scene captures the Belle Époque atmosphere with dappled sunlight filtering through trees, highlighting the fashionable attire of the period. [trigger]",
|
80 |
+
"Cézanne's intimate portrait of a young woman from the 1880s, with her hair styled in a fashionable updo, wearing a high-necked dress with lace details and leg-of-mutton sleeves. She wears delicate jewelry and has the soft facial features characteristic of Cézanne's portraiture, set against a background of vibrant colors. [trigger]",
|
81 |
+
"Cézanne's painting of two young girls in 1880s attire seated at a piano. One plays while the other stands nearby, both dressed in white frocks with ribbon details, sashes, and high collars typical of the period. The interior setting features Victorian furnishings and decor with warm tones and the distinctive brushwork of Cézanne. [trigger]",
|
82 |
+
"Cézanne's painting of an elegant 1880s boating party, with gentlemen in striped boating blazers, straw boater hats, and formal trousers, alongside ladies in bustled day dresses with parasols. The scene captures the leisure activities of French society during the Belle Époque era, with a bright palette emphasizing the fashionable clothing of the period. [trigger]",
|
83 |
+
"Cézanne's painting of children playing in an 1880s garden scene, dressed in formal period children's wear including sailor suits for boys and pinafores with full skirts for girls. Their Victorian-era clothing contrasts with their playful activities, set against Cézanne's vibrant treatment of nature and sunlight filtering through the foliage. [trigger]",
|
84 |
+
"Cézanne's depiction of bathers in 1880s swimming attire, showing the modest bathing costumes of the period. Women wear full-coverage dark bathing dresses with stockings, while men are in knee-length swimming suits. The figures are arranged in Cézanne's distinctive compositional style against a backdrop of water and landscape rendered in his bold color blocks. [trigger]"
|
85 |
]
|
86 |
|
87 |
+
# First example for preloading
|
88 |
+
default_prompt = examples[0]
|
89 |
+
default_settings = {
|
90 |
+
"seed": 42,
|
91 |
+
"randomize_seed": True,
|
92 |
+
"width": 1024,
|
93 |
+
"height": 768,
|
94 |
+
"guidance_scale": 3.5,
|
95 |
+
"num_inference_steps": 30,
|
96 |
+
"lora_scale": 1.0
|
97 |
+
}
|
98 |
+
|
99 |
+
# Improved custom CSS with better visuals
|
100 |
custom_css = """
|
101 |
:root {
|
102 |
+
--color-primary: #0F4C81;
|
103 |
+
--color-secondary: #FF9E6C;
|
104 |
+
--background-fill-primary: linear-gradient(to right, #f6f9fc, #edf2f7);
|
105 |
}
|
106 |
+
|
107 |
footer {
|
108 |
visibility: hidden;
|
109 |
}
|
110 |
+
|
111 |
.gradio-container {
|
112 |
+
background: var(--background-fill-primary);
|
113 |
}
|
114 |
+
|
115 |
.title {
|
116 |
+
color: var(--color-primary) !important;
|
117 |
+
font-size: 3rem !important;
|
118 |
font-weight: 700 !important;
|
119 |
text-align: center;
|
120 |
margin: 1rem 0;
|
121 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.05);
|
122 |
+
font-family: 'Playfair Display', serif;
|
123 |
}
|
124 |
+
|
125 |
.subtitle {
|
126 |
+
color: #4A5568 !important;
|
127 |
font-size: 1.2rem !important;
|
128 |
+
text-align: center;
|
129 |
+
margin-bottom: 1.5rem;
|
130 |
+
font-style: italic;
|
131 |
+
}
|
132 |
+
|
133 |
+
.collection-link {
|
134 |
text-align: center;
|
135 |
margin-bottom: 2rem;
|
136 |
+
font-size: 1.1rem;
|
137 |
}
|
138 |
+
|
139 |
+
.collection-link a {
|
140 |
+
color: var(--color-primary);
|
141 |
+
text-decoration: underline;
|
142 |
+
transition: color 0.3s ease;
|
143 |
+
}
|
144 |
+
|
145 |
+
.collection-link a:hover {
|
146 |
+
color: var(--color-secondary);
|
147 |
+
}
|
148 |
+
|
149 |
.model-description {
|
150 |
+
background-color: rgba(255, 255, 255, 0.8);
|
151 |
+
border-radius: 12px;
|
152 |
+
padding: 24px;
|
153 |
margin: 20px 0;
|
154 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
155 |
+
border-left: 5px solid var(--color-primary);
|
156 |
}
|
157 |
+
|
158 |
button.primary {
|
159 |
+
background-color: var(--color-primary) !important;
|
160 |
+
transition: all 0.3s ease;
|
161 |
}
|
162 |
+
|
163 |
button:hover {
|
164 |
transform: translateY(-2px);
|
165 |
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
166 |
}
|
167 |
+
|
168 |
+
.input-container {
|
169 |
+
border-radius: 10px;
|
170 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
171 |
+
}
|
172 |
+
|
173 |
+
.advanced-settings {
|
174 |
+
margin-top: 1rem;
|
175 |
+
padding: 1rem;
|
176 |
+
border-radius: 10px;
|
177 |
+
background-color: rgba(255, 255, 255, 0.6);
|
178 |
+
}
|
179 |
+
|
180 |
+
.example-region {
|
181 |
+
background-color: rgba(255, 255, 255, 0.5);
|
182 |
+
border-radius: 10px;
|
183 |
+
padding: 1rem;
|
184 |
+
margin-top: 1rem;
|
185 |
}
|
186 |
"""
|
187 |
|
188 |
+
# Add preloading function for the first example
|
189 |
+
def preload_example():
|
190 |
+
# Set the default example as the initial state
|
191 |
+
return (
|
192 |
+
default_prompt,
|
193 |
+
inference(
|
194 |
+
prompt=default_prompt,
|
195 |
+
seed=default_settings["seed"],
|
196 |
+
randomize_seed=default_settings["randomize_seed"],
|
197 |
+
width=default_settings["width"],
|
198 |
+
height=default_settings["height"],
|
199 |
+
guidance_scale=default_settings["guidance_scale"],
|
200 |
+
num_inference_steps=default_settings["num_inference_steps"],
|
201 |
+
lora_scale=default_settings["lora_scale"],
|
202 |
+
)
|
203 |
+
)
|
204 |
+
|
205 |
with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
|
206 |
gr.HTML('<div class="title">Paul Cézanne STUDIO</div>')
|
207 |
|
208 |
+
# Add collection link below title
|
209 |
+
gr.HTML('<div class="collection-link"><a href="https://huggingface.co/collections/openfree/painting-art-ai-681453484ec15ef5978bbeb1" target="_blank">View the full Painting Art AI Collection</a></div>')
|
210 |
+
|
211 |
# Model description with the requested content
|
212 |
with gr.Group(elem_classes="model-description"):
|
213 |
+
gr.HTML('<p>Generate beautiful artwork in the style of Paul Cézanne. Add [trigger] at the end of your prompt for best results.</p>')
|
214 |
|
215 |
# Simplified structure without tabs and gallery
|
216 |
with gr.Column(elem_id="col-container"):
|
217 |
+
with gr.Row(elem_classes="input-container"):
|
218 |
prompt = gr.Text(
|
219 |
label="Prompt",
|
|
|
220 |
max_lines=1,
|
221 |
placeholder="Enter your prompt (add [trigger] at the end)",
|
|
|
222 |
)
|
223 |
run_button = gr.Button("Generate", variant="primary", scale=0)
|
224 |
|
225 |
+
result = gr.Image(label="Generated Image")
|
226 |
|
227 |
+
with gr.Accordion("Advanced Settings", open=False, elem_classes="advanced-settings"):
|
228 |
seed = gr.Slider(
|
229 |
label="Seed",
|
230 |
minimum=0,
|
231 |
maximum=MAX_SEED,
|
232 |
step=1,
|
233 |
+
value=default_settings["seed"],
|
234 |
)
|
235 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=default_settings["randomize_seed"])
|
236 |
|
237 |
with gr.Row():
|
238 |
width = gr.Slider(
|
|
|
240 |
minimum=256,
|
241 |
maximum=MAX_IMAGE_SIZE,
|
242 |
step=32,
|
243 |
+
value=default_settings["width"],
|
244 |
)
|
245 |
height = gr.Slider(
|
246 |
label="Height",
|
247 |
minimum=256,
|
248 |
maximum=MAX_IMAGE_SIZE,
|
249 |
step=32,
|
250 |
+
value=default_settings["height"],
|
251 |
)
|
252 |
|
253 |
with gr.Row():
|
|
|
256 |
minimum=0.0,
|
257 |
maximum=10.0,
|
258 |
step=0.1,
|
259 |
+
value=default_settings["guidance_scale"],
|
260 |
)
|
261 |
num_inference_steps = gr.Slider(
|
262 |
label="Number of inference steps",
|
263 |
minimum=1,
|
264 |
maximum=50,
|
265 |
step=1,
|
266 |
+
value=default_settings["num_inference_steps"],
|
267 |
)
|
268 |
lora_scale = gr.Slider(
|
269 |
label="LoRA scale",
|
270 |
minimum=0.0,
|
271 |
maximum=1.0,
|
272 |
step=0.1,
|
273 |
+
value=default_settings["lora_scale"],
|
274 |
)
|
275 |
|
276 |
+
with gr.Group(elem_classes="example-region"):
|
277 |
+
gr.Markdown("### Examples")
|
278 |
+
gr.Examples(
|
279 |
+
examples=examples,
|
280 |
+
inputs=[prompt],
|
281 |
+
outputs=[result, seed],
|
282 |
+
fn=inference,
|
283 |
+
cache_examples=True,
|
284 |
+
)
|
285 |
|
286 |
+
# Event handlers
|
287 |
gr.on(
|
288 |
triggers=[run_button.click, prompt.submit],
|
289 |
fn=inference,
|
|
|
299 |
],
|
300 |
outputs=[result, seed],
|
301 |
)
|
302 |
+
|
303 |
+
# Preload the first example when the app starts
|
304 |
+
demo.load(
|
305 |
+
fn=preload_example,
|
306 |
+
inputs=None,
|
307 |
+
outputs=[prompt, [result, seed]],
|
308 |
+
)
|
309 |
|
310 |
demo.queue()
|
311 |
demo.launch()
|