neonforestmist commited on
Commit
0ffd13e
·
verified ·
1 Parent(s): 28d785a

Restore standard Gradio presentation from before the Clover studio redesign

Browse files
Files changed (1) hide show
  1. app.py +108 -254
app.py CHANGED
@@ -131,6 +131,19 @@ CATALOG_HTML = (
131
  + "</div>"
132
  )
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  INPAINT_CATALOG_HTML = """
135
  <div class="inpaint-example">
136
  <figure><img
@@ -143,222 +156,78 @@ alt="Cat inpainted onto the masked bench"><figcaption>Inpainted bench</figcaptio
143
  """
144
 
145
  DEMO_CSS = """
146
- /* One green accent, neutral surfaces, 16px frames and 10px controls. */
147
- .gradio-container {
148
- --clover-ink: #202b25;
149
- --clover-muted: #526158;
150
- --clover-line: #d8dfda;
151
- --clover-surface: #ffffff;
152
- --clover-track: #edf1ee;
153
- --clover-accent: #276447;
154
- --clover-selected: #ffffff;
155
- --body-background-fill: #f8faf8;
156
- --body-text-color: var(--clover-ink);
157
- --body-text-color-subdued: var(--clover-muted);
158
- --block-background-fill: transparent;
159
- --block-border-color: transparent;
160
- --border-color-primary: var(--clover-line);
161
- --border-color-secondary: var(--clover-line);
162
- --input-background-fill: var(--clover-surface);
163
- --input-border-color: var(--clover-line);
164
- --input-radius: 10px;
165
- --block-radius: 10px;
166
- max-width: 1180px !important;
167
- margin: 0 auto !important;
168
- padding: clamp(16px, 2.4vw, 24px) clamp(16px, 2.4vw, 28px) 40px !important;
169
- font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
170
- color: var(--clover-ink);
171
- background: var(--body-background-fill);
172
- }
173
- .gradio-container .main { padding: 0 !important; }
174
- /* Standalone Spaces inject a fixed host banner; embedded and local views do not. */
175
- body:has(#huggingface-space-header) .gradio-container { padding-top: 68px !important; }
176
- .dark .gradio-container {
177
- --clover-ink: #e7eee9;
178
- --clover-muted: #a5b5aa;
179
- --clover-line: #34423a;
180
- --clover-surface: #1b201d;
181
- --clover-track: #161b18;
182
- --clover-accent: #a3dfb9;
183
- --clover-selected: #303a34;
184
- --body-background-fill: #111513;
185
  }
186
- #clover-hero {
187
- padding: 4px 0 22px;
188
- margin-bottom: 6px;
189
- border: 0;
190
- border-bottom: 1px solid var(--clover-line);
191
- border-radius: 0 !important;
192
- background: transparent;
193
  }
194
- .clover-header {
195
- display: flex;
196
- justify-content: space-between;
197
- align-items: center;
198
- gap: 16px;
199
  }
200
- #clover-hero h1 {
201
- font-size: clamp(23px, 3vw, 30px);
202
- letter-spacing: -1px;
203
- line-height: 1.25;
204
- margin: 0;
205
- color: var(--clover-ink);
206
- }
207
- #clover-hero h1 span { color: var(--clover-accent); }
208
- #clover-hero a {
209
- display: inline-flex;
210
- align-items: center;
211
- min-height: 44px;
212
- color: var(--clover-muted);
213
- font-size: 13px;
214
- text-decoration: none;
215
- white-space: nowrap;
216
- }
217
- #clover-hero a:hover { color: var(--clover-accent); }
218
- /* Keep native radios for keyboard navigation and screen readers. */
219
- #clover-mode {
220
- width: min(100%, 360px);
221
- align-self: flex-start;
222
- padding: 0 !important;
223
- border: 0 !important;
224
- background: transparent !important;
225
- margin: 8px 0 20px;
226
- }
227
- #clover-mode .wrap {
228
- display: flex;
229
- flex-wrap: nowrap;
230
  gap: 4px;
231
- padding: 4px;
232
- background: var(--clover-track);
233
- border: 1px solid var(--clover-line);
234
- border-radius: 14px;
235
- }
236
- #clover-mode label {
237
- flex: 1;
238
- justify-content: center;
239
- min-height: 44px;
240
- margin: 0;
241
- padding: 10px 16px;
242
- border: 1px solid transparent !important;
243
- border-radius: 10px !important;
244
- background: transparent !important;
245
- color: var(--clover-muted) !important;
246
- box-shadow: none !important;
247
- cursor: pointer;
248
- transition: background 120ms ease, color 120ms ease;
249
- }
250
- #clover-mode label:has(input:checked) {
251
- background: var(--clover-selected) !important;
252
- border-color: var(--clover-line) !important;
253
- color: var(--clover-ink) !important;
254
- }
255
- #clover-mode label span { font-weight: 600; }
256
- #clover-mode input[type="radio"] {
257
- position: absolute;
258
- width: 1px;
259
- height: 1px;
260
- opacity: 0;
261
- }
262
- #clover-mode label:has(input:focus-visible),
263
- .gradio-container button:focus-visible,
264
- #clover-hero a:focus-visible {
265
- outline: 2px solid var(--clover-accent);
266
- outline-offset: 3px;
267
- }
268
- #clover-workspace { gap: 32px; }
269
- .clover-panel {
270
- padding: 0 !important;
271
- border: 0 !important;
272
- background: transparent !important;
273
- gap: 18px !important;
274
- min-width: 0;
275
- }
276
- #clover-controls {
277
- padding-right: 28px !important;
278
- border-right: 1px solid var(--clover-line) !important;
279
- }
280
- .clover-panel .block {
281
- border: 0 !important;
282
- background: transparent !important;
283
- box-shadow: none !important;
284
- padding: 0 !important;
285
- }
286
- .clover-panel .form, .clover-panel .styler, .clover-panel .gr-group {
287
- border: 0 !important;
288
- background: transparent !important;
289
- box-shadow: none !important;
290
- }
291
- .clover-panel textarea, .clover-panel input[type="number"],
292
- .clover-panel .wrap-inner {
293
- border: 1px solid var(--clover-line) !important;
294
- border-radius: 10px !important;
295
- background: var(--clover-surface) !important;
296
  }
297
- .clover-panel textarea { padding: 12px 14px !important; }
298
- .clover-panel textarea:focus, .clover-panel input:focus-visible {
299
- outline: 2px solid var(--clover-accent);
300
- outline-offset: 2px;
301
  }
302
- #clover-generate {
303
- min-height: 50px;
304
- border: 1px solid #276447 !important;
305
- border-radius: 10px !important;
306
- background: #276447 !important;
307
- color: #ffffff !important;
308
- font-size: 15px;
309
- font-weight: 650;
310
- white-space: nowrap;
311
  }
312
- #clover-generate:hover { background: #1e5038 !important; }
313
- #clover-generate:active { transform: scale(.99); }
314
- .dark #clover-generate {
315
- background: #a3dfb9 !important;
316
- border-color: #a3dfb9 !important;
317
- color: #103320 !important;
 
 
318
  }
319
- .dark #clover-generate:hover { background: #bdeccc !important; }
320
- #generated-output, #clover-editor {
321
- overflow: hidden;
322
- border: 1px solid var(--clover-line) !important;
323
- border-radius: 16px !important;
324
- background: var(--clover-surface) !important;
325
- padding: 8px !important;
326
  }
327
- #generated-output { min-height: 512px; }
328
- #generated-output img { object-fit: contain; border-radius: 0; }
329
- #metadata-output { min-height: 100px; }
330
- #style-catalog, #inpaint-catalog { margin-top: 12px; }
331
- .style-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
332
- .inpaint-example { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
333
- .style-card, .inpaint-example figure { margin: 0; min-width: 0; }
334
- .style-card img, .inpaint-example img {
335
  display: block;
336
  width: 100%;
337
  height: auto;
338
  aspect-ratio: 1 / 1;
339
  object-fit: contain;
340
- border: 0;
341
- border-radius: 0;
342
- background: var(--clover-surface);
343
  }
344
- .style-card figcaption { display: grid; gap: 3px; padding-top: 8px; }
345
- .style-card figcaption span, .inpaint-example figcaption {
346
- color: var(--clover-muted);
347
- font-size: 13px;
348
- line-height: 1.5;
349
  }
350
- .inpaint-example figcaption { padding-top: 6px; }
351
- .gradio-container a { color: var(--clover-accent); }
352
- @media (max-width: 760px) {
353
- #clover-workspace { flex-direction: column; gap: 24px; }
354
- #clover-workspace > .clover-panel { width: 100%; min-width: 0 !important; }
355
- #clover-controls { padding-right: 0 !important; border-right: 0 !important; }
356
- #clover-mode { width: 100%; margin-bottom: 12px; }
357
- #generated-output { min-height: 320px; }
358
- .style-grid { gap: 8px; }
359
  }
360
- @media (prefers-reduced-motion: reduce) {
361
- .clover-panel *, #clover-mode * { animation: none !important; transition: none !important; }
362
  }
363
  """
364
 
@@ -857,58 +726,53 @@ def build_demo() -> gr.Blocks:
857
  analytics_enabled=False,
858
  delete_cache=(300, 1800),
859
  ) as demo:
860
- gr.HTML(
861
- '<div class="clover-header"><h1>Clover <span>Image Tiny</span></h1>'
862
- '<a href="https://huggingface.co/neonforestmist/Clover-Image-Tiny" '
863
- 'target="_blank" rel="noopener noreferrer">Model card</a></div>',
864
- elem_id="clover-hero",
865
  )
866
  mode = gr.Radio(
867
  label="Mode",
868
  choices=MODES,
869
  value=REGULAR_MODE,
870
- show_label=False,
871
- container=False,
872
- elem_id="clover-mode",
873
  )
 
874
 
875
- with gr.Row(elem_id="clover-workspace"):
876
- with gr.Column(scale=3, elem_classes="clover-panel", elem_id="clover-controls"):
877
- with gr.Group(visible=False) as inpaint_canvas:
878
- gr.Markdown(
879
- "### 1. Choose the image and paint the edit area\n"
880
- "Paint the part to replace in **white**, leaving room for the whole "
881
- "object and its shadow. The rest stays unchanged."
882
- )
883
- editor = gr.ImageEditor(
884
- label="Source image + white mask",
885
- type="pil",
886
- image_mode="RGBA",
887
- sources=["upload", "clipboard"],
888
- transforms=("crop",),
889
- brush=gr.Brush(
890
- colors=["#FFFFFF"],
891
- default_color="#FFFFFF",
892
- color_mode="fixed",
893
- default_size=36,
894
- ),
895
- layers=gr.LayerOptions(
896
- allow_additional_layers=False,
897
- layers=["Mask"],
898
- ),
899
- canvas_size=(DEFAULT_RESOLUTION, DEFAULT_RESOLUTION),
900
- fixed_canvas=False,
901
- height=400,
902
- elem_id="clover-editor",
903
- format="png",
904
- )
905
 
906
- inpaint_settings_heading = gr.Markdown(
907
- "### 2. Describe the replacement\n"
908
- "Write what should appear inside the white mask, then choose **Generate**.",
909
- visible=False,
910
- )
911
 
 
 
912
  prompt = gr.Textbox(
913
  label="Prompt — describe the image or masked replacement",
914
  value="a tiny glass greenhouse glowing in a moonlit garden",
@@ -1004,10 +868,8 @@ def build_demo() -> gr.Blocks:
1004
  "If a render genuinely collapses to black, Clover tries up to three "
1005
  "deterministic seeds while keeping the source image and mask."
1006
  )
1007
- generate_button = gr.Button(
1008
- "Generate", variant="primary", elem_id="clover-generate"
1009
- )
1010
- with gr.Column(scale=4, elem_classes="clover-panel"):
1011
  output = gr.Image(
1012
  label="Generated image",
1013
  type="pil",
@@ -1099,12 +961,4 @@ if __name__ == "__main__":
1099
  enable_monitoring=False,
1100
  strict_cors=True,
1101
  css=DEMO_CSS,
1102
- theme=gr.themes.Base(primary_hue="green", secondary_hue="green", neutral_hue="gray").set(
1103
- body_background_fill="#f8faf8",
1104
- body_background_fill_dark="#111513",
1105
- block_label_background_fill="transparent",
1106
- block_label_background_fill_dark="transparent",
1107
- slider_color="#276447",
1108
- slider_color_dark="#a3dfb9",
1109
- ),
1110
  )
 
131
  + "</div>"
132
  )
133
 
134
+ MODEL_CATALOG_HTML = """
135
+ <div class="model-grid">
136
+ <article class="model-card">
137
+ <strong>Regular</strong>
138
+ <span>Text-to-image · base Clover plus three optional style LoRAs</span>
139
+ </article>
140
+ <article class="model-card">
141
+ <strong>Inpainting</strong>
142
+ <span>Image + white mask · validated HQ 9-channel inpainting model</span>
143
+ </article>
144
+ </div>
145
+ """
146
+
147
  INPAINT_CATALOG_HTML = """
148
  <div class="inpaint-example">
149
  <figure><img
 
156
  """
157
 
158
  DEMO_CSS = """
159
+ .gradio-container { min-height: 1100px; }
160
+ #generated-output { min-height: 548px; contain: layout paint; }
161
+ #metadata-output { min-height: 116px; contain: layout paint; }
162
+ #style-catalog { min-height: 330px; contain: layout paint; }
163
+ #model-catalog { contain: layout paint; }
164
+ #style-catalog, #style-catalog * {
165
+ animation: none !important;
166
+ transition: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
+ .style-grid {
169
+ display: grid;
170
+ grid-template-columns: repeat(3, minmax(0, 1fr));
171
+ gap: 12px;
 
 
 
172
  }
173
+ .model-grid {
174
+ display: grid;
175
+ grid-template-columns: repeat(2, minmax(0, 1fr));
176
+ gap: 12px;
 
177
  }
178
+ .model-card {
179
+ display: grid;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  gap: 4px;
181
+ padding: 14px;
182
+ border: 1px solid var(--border-color-primary);
183
+ border-radius: var(--radius-lg);
184
+ background: var(--block-background-fill);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
+ .model-card span {
187
+ color: var(--body-text-color-subdued);
188
+ font-size: var(--text-sm);
 
189
  }
190
+ .inpaint-example {
191
+ display: grid;
192
+ grid-template-columns: repeat(2, minmax(0, 1fr));
193
+ gap: 12px;
 
 
 
 
 
194
  }
195
+ .inpaint-example figure { margin: 0; }
196
+ .inpaint-example img {
197
+ display: block;
198
+ width: 100%;
199
+ aspect-ratio: 1 / 1;
200
+ object-fit: contain;
201
+ border: 1px solid var(--border-color-primary);
202
+ border-radius: var(--radius-lg);
203
  }
204
+ .inpaint-example figcaption {
205
+ padding-top: 6px;
206
+ color: var(--body-text-color-subdued);
207
+ font-size: var(--text-sm);
 
 
 
208
  }
209
+ .style-card { margin: 0; min-width: 0; }
210
+ .style-card img {
 
 
 
 
 
 
211
  display: block;
212
  width: 100%;
213
  height: auto;
214
  aspect-ratio: 1 / 1;
215
  object-fit: contain;
216
+ background: var(--block-background-fill);
217
+ border: 1px solid var(--border-color-primary);
218
+ border-radius: var(--radius-lg);
219
  }
220
+ .style-card figcaption {
221
+ display: grid;
222
+ gap: 3px;
223
+ padding-top: 8px;
 
224
  }
225
+ .style-card figcaption span {
226
+ color: var(--body-text-color-subdued);
227
+ font-size: var(--text-sm);
 
 
 
 
 
 
228
  }
229
+ @media (max-width: 720px) {
230
+ .style-grid, .model-grid { grid-template-columns: 1fr; }
231
  }
232
  """
233
 
 
726
  analytics_enabled=False,
727
  delete_cache=(300, 1800),
728
  ) as demo:
729
+ gr.Markdown(
730
+ "# Clover Image Tiny 🍀\n\n"
731
+ "[Model card](https://huggingface.co/neonforestmist/Clover-Image-Tiny) · "
732
+ "[Inpainting model](https://huggingface.co/neonforestmist/Clover-Image-Tiny-Inpaint)"
 
733
  )
734
  mode = gr.Radio(
735
  label="Mode",
736
  choices=MODES,
737
  value=REGULAR_MODE,
 
 
 
738
  )
739
+ gr.Markdown("### Model catalog\n" + MODEL_CATALOG_HTML, elem_id="model-catalog")
740
 
741
+ with gr.Group(visible=False) as inpaint_canvas:
742
+ gr.Markdown(
743
+ "### 1. Choose the image and paint the edit area\n"
744
+ "Paint the part to replace in **white**. The rest of the image stays unchanged."
745
+ )
746
+ editor = gr.ImageEditor(
747
+ label="Source image + white mask",
748
+ type="pil",
749
+ image_mode="RGBA",
750
+ sources=["upload", "clipboard"],
751
+ transforms=("crop",),
752
+ brush=gr.Brush(
753
+ colors=["#FFFFFF"],
754
+ default_color="#FFFFFF",
755
+ color_mode="fixed",
756
+ default_size=36,
757
+ ),
758
+ layers=gr.LayerOptions(
759
+ allow_additional_layers=False,
760
+ layers=["Mask"],
761
+ ),
762
+ canvas_size=(DEFAULT_RESOLUTION, DEFAULT_RESOLUTION),
763
+ fixed_canvas=False,
764
+ height=548,
765
+ format="png",
766
+ )
 
 
 
 
767
 
768
+ inpaint_settings_heading = gr.Markdown(
769
+ "### 2. Describe the replacement\n"
770
+ "Write what should appear inside the white mask, then choose **Generate**.",
771
+ visible=False,
772
+ )
773
 
774
+ with gr.Row():
775
+ with gr.Column(scale=3):
776
  prompt = gr.Textbox(
777
  label="Prompt — describe the image or masked replacement",
778
  value="a tiny glass greenhouse glowing in a moonlit garden",
 
868
  "If a render genuinely collapses to black, Clover tries up to three "
869
  "deterministic seeds while keeping the source image and mask."
870
  )
871
+ generate_button = gr.Button("Generate", variant="primary")
872
+ with gr.Column(scale=4):
 
 
873
  output = gr.Image(
874
  label="Generated image",
875
  type="pil",
 
961
  enable_monitoring=False,
962
  strict_cors=True,
963
  css=DEMO_CSS,
 
 
 
 
 
 
 
 
964
  )