Spaces:
Running
Running
pagination fix
Browse files
app.py
CHANGED
|
@@ -208,7 +208,13 @@ def build_story_outputs():
|
|
| 208 |
|
| 209 |
|
| 210 |
# =========================================================
|
| 211 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
# =========================================================
|
| 213 |
CUSTOM_CSS = """
|
| 214 |
:root {
|
|
@@ -222,21 +228,53 @@ CUSTOM_CSS = """
|
|
| 222 |
--accent-2: #0ea5e9;
|
| 223 |
--shadow: 0 8px 24px rgba(0,0,0,0.06);
|
| 224 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
.gradio-container {
|
| 226 |
max-width: 100% !important;
|
| 227 |
width: 100% !important;
|
|
|
|
| 228 |
padding-left: 16px !important;
|
| 229 |
padding-right: 16px !important;
|
| 230 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
body, .gradio-container {
|
| 232 |
background:
|
| 233 |
radial-gradient(circle at top left, rgba(124,156,255,0.16), transparent 25%),
|
| 234 |
radial-gradient(circle at top right, rgba(144,224,239,0.10), transparent 20%),
|
| 235 |
linear-gradient(180deg, #0a0f1d, #0e1422 45%, #0b1020);
|
| 236 |
}
|
|
|
|
| 237 |
.page-wrap {
|
|
|
|
|
|
|
| 238 |
padding: 6px 4px 30px 4px;
|
|
|
|
| 239 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
.hero {
|
| 241 |
display: flex;
|
| 242 |
align-items: center;
|
|
@@ -246,9 +284,11 @@ body, .gradio-container {
|
|
| 246 |
border: 1px solid var(--border);
|
| 247 |
border-radius: 24px;
|
| 248 |
padding: 28px;
|
| 249 |
-
margin-bottom: 24px;
|
| 250 |
box-shadow: var(--shadow);
|
|
|
|
|
|
|
| 251 |
}
|
|
|
|
| 252 |
.eyebrow {
|
| 253 |
color: var(--accent-2);
|
| 254 |
font-size: 12px;
|
|
@@ -257,48 +297,91 @@ body, .gradio-container {
|
|
| 257 |
text-transform: uppercase;
|
| 258 |
margin-bottom: 8px;
|
| 259 |
}
|
|
|
|
| 260 |
.hero h1 {
|
| 261 |
margin: 0;
|
| 262 |
color: var(--text);
|
| 263 |
font-size: 36px;
|
| 264 |
line-height: 1.1;
|
| 265 |
}
|
|
|
|
| 266 |
.hero p {
|
| 267 |
margin: 10px 0 0 0;
|
| 268 |
color: var(--muted);
|
| 269 |
font-size: 16px;
|
| 270 |
}
|
|
|
|
| 271 |
.hero-actions {
|
| 272 |
-
display:flex;
|
| 273 |
-
align-items:center;
|
| 274 |
-
gap:14px;
|
| 275 |
}
|
|
|
|
| 276 |
.hero-stat {
|
| 277 |
-
min-width:
|
| 278 |
text-align: center;
|
| 279 |
background: rgba(255,255,255,0.04);
|
| 280 |
border: 1px solid var(--border);
|
| 281 |
border-radius: 20px;
|
| 282 |
padding: 18px;
|
| 283 |
}
|
|
|
|
| 284 |
.stat-num {
|
| 285 |
color: var(--text);
|
| 286 |
font-size: 34px;
|
| 287 |
font-weight: 800;
|
| 288 |
}
|
|
|
|
| 289 |
.stat-label {
|
| 290 |
color: var(--muted);
|
| 291 |
font-size: 13px;
|
| 292 |
}
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
.stories-list {
|
| 298 |
display: flex;
|
| 299 |
flex-direction: column;
|
| 300 |
gap: 22px;
|
|
|
|
| 301 |
}
|
|
|
|
| 302 |
.story-card {
|
| 303 |
background: white;
|
| 304 |
border: 1px solid var(--border);
|
|
@@ -307,7 +390,10 @@ body, .gradio-container {
|
|
| 307 |
box-shadow: var(--shadow);
|
| 308 |
backdrop-filter: blur(8px);
|
| 309 |
margin-bottom: 22px;
|
|
|
|
|
|
|
| 310 |
}
|
|
|
|
| 311 |
.story-header {
|
| 312 |
display: flex;
|
| 313 |
justify-content: space-between;
|
|
@@ -315,18 +401,22 @@ body, .gradio-container {
|
|
| 315 |
gap: 18px;
|
| 316 |
margin-bottom: 18px;
|
| 317 |
}
|
| 318 |
-
|
|
|
|
|
|
|
| 319 |
margin: 0 !important;
|
| 320 |
color: var(--muted) !important;
|
| 321 |
font-size: 13px !important;
|
| 322 |
word-break: break-word;
|
| 323 |
}
|
|
|
|
| 324 |
.story-meta {
|
| 325 |
display: flex;
|
| 326 |
flex-wrap: wrap;
|
| 327 |
gap: 8px;
|
| 328 |
justify-content: flex-end;
|
| 329 |
}
|
|
|
|
| 330 |
.meta-pill {
|
| 331 |
display: inline-flex;
|
| 332 |
align-items: center;
|
|
@@ -340,12 +430,15 @@ body, .gradio-container {
|
|
| 340 |
font-size: 12px;
|
| 341 |
font-weight: 600;
|
| 342 |
margin-right: 8px;
|
|
|
|
| 343 |
}
|
|
|
|
| 344 |
.story-content {
|
| 345 |
display: grid;
|
| 346 |
grid-template-columns: 1.15fr 0.85fr;
|
| 347 |
gap: 20px;
|
| 348 |
}
|
|
|
|
| 349 |
.story-text,
|
| 350 |
.story-visuals {
|
| 351 |
background: rgba(255,255,255,0.025);
|
|
@@ -353,12 +446,14 @@ body, .gradio-container {
|
|
| 353 |
border-radius: 20px;
|
| 354 |
padding: 18px;
|
| 355 |
}
|
|
|
|
| 356 |
.story-text h3,
|
| 357 |
.story-visuals h3 {
|
| 358 |
margin: 0 0 14px 0;
|
| 359 |
color: var(--text);
|
| 360 |
font-size: 18px;
|
| 361 |
}
|
|
|
|
| 362 |
.story-markdown .prose,
|
| 363 |
.story-markdown .prose p,
|
| 364 |
.story-markdown .prose li,
|
|
@@ -371,6 +466,7 @@ body, .gradio-container {
|
|
| 371 |
.story-markdown .prose blockquote {
|
| 372 |
color: var(--text) !important;
|
| 373 |
}
|
|
|
|
| 374 |
.story-video-wrap video {
|
| 375 |
width: 100% !important;
|
| 376 |
max-height: 580px !important;
|
|
@@ -378,14 +474,17 @@ body, .gradio-container {
|
|
| 378 |
background: #000 !important;
|
| 379 |
border: 1px solid var(--border) !important;
|
| 380 |
}
|
|
|
|
| 381 |
.story-gallery {
|
| 382 |
min-height: 80px;
|
| 383 |
}
|
|
|
|
| 384 |
.story-gallery .grid-wrap,
|
| 385 |
.story-gallery .grid-container,
|
| 386 |
.story-gallery .gallery {
|
| 387 |
border-radius: 16px !important;
|
| 388 |
}
|
|
|
|
| 389 |
.empty-state {
|
| 390 |
background: rgba(255,255,255,0.025);
|
| 391 |
border: 1px dashed var(--border);
|
|
@@ -393,24 +492,196 @@ body, .gradio-container {
|
|
| 393 |
padding: 22px;
|
| 394 |
color: var(--muted);
|
| 395 |
}
|
|
|
|
| 396 |
@media (max-width: 1100px) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
.story-content {
|
| 398 |
grid-template-columns: 1fr;
|
| 399 |
}
|
|
|
|
| 400 |
.story-header {
|
| 401 |
flex-direction: column;
|
| 402 |
}
|
|
|
|
| 403 |
.story-meta {
|
| 404 |
justify-content: flex-start;
|
| 405 |
}
|
|
|
|
| 406 |
.hero {
|
| 407 |
flex-direction: column;
|
| 408 |
align-items: flex-start;
|
| 409 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
}
|
| 411 |
"""
|
| 412 |
|
| 413 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
# =========================================================
|
| 415 |
# UI
|
| 416 |
# =========================================================
|
|
@@ -419,15 +690,23 @@ with gr.Blocks(
|
|
| 419 |
theme=gr.themes.Soft(),
|
| 420 |
css=CUSTOM_CSS,
|
| 421 |
) as demo:
|
|
|
|
|
|
|
| 422 |
with gr.Column(elem_classes=["page-wrap"]):
|
| 423 |
-
with gr.Row(elem_classes=["
|
| 424 |
hero_html = gr.HTML()
|
| 425 |
-
refresh_btn = gr.Button("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
| 427 |
with gr.Column(elem_classes=["stories-list"]):
|
| 428 |
card_components = []
|
| 429 |
|
| 430 |
-
for _ in range(
|
| 431 |
with gr.Column(visible=False, elem_classes=["story-card"]) as card:
|
| 432 |
with gr.Row(elem_classes=["story-header"]):
|
| 433 |
with gr.Column(scale=6):
|
|
@@ -464,18 +743,58 @@ with gr.Blocks(
|
|
| 464 |
gallery_comp,
|
| 465 |
])
|
| 466 |
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
demo.load(
|
| 470 |
-
fn=
|
| 471 |
inputs=[],
|
| 472 |
-
outputs=all_outputs,
|
| 473 |
)
|
| 474 |
|
| 475 |
refresh_btn.click(
|
| 476 |
-
fn=
|
| 477 |
inputs=[],
|
| 478 |
-
outputs=all_outputs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
)
|
| 480 |
|
| 481 |
-
demo.launch(share=True
|
|
|
|
| 208 |
|
| 209 |
|
| 210 |
# =========================================================
|
| 211 |
+
# PAGINATION CONFIG
|
| 212 |
+
# =========================================================
|
| 213 |
+
STORIES_PER_PAGE = 20
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
# =========================================================
|
| 217 |
+
# CSS
|
| 218 |
# =========================================================
|
| 219 |
CUSTOM_CSS = """
|
| 220 |
:root {
|
|
|
|
| 228 |
--accent-2: #0ea5e9;
|
| 229 |
--shadow: 0 8px 24px rgba(0,0,0,0.06);
|
| 230 |
}
|
| 231 |
+
|
| 232 |
+
html, body {
|
| 233 |
+
margin: 0 !important;
|
| 234 |
+
padding: 0 !important;
|
| 235 |
+
width: 100% !important;
|
| 236 |
+
overflow-x: hidden !important;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
.gradio-container {
|
| 240 |
max-width: 100% !important;
|
| 241 |
width: 100% !important;
|
| 242 |
+
margin: 0 !important;
|
| 243 |
padding-left: 16px !important;
|
| 244 |
padding-right: 16px !important;
|
| 245 |
}
|
| 246 |
+
|
| 247 |
+
.gradio-container > .main,
|
| 248 |
+
.gradio-container .main {
|
| 249 |
+
max-width: 100% !important;
|
| 250 |
+
width: 100% !important;
|
| 251 |
+
margin: 0 !important;
|
| 252 |
+
padding: 0 !important;
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
body, .gradio-container {
|
| 256 |
background:
|
| 257 |
radial-gradient(circle at top left, rgba(124,156,255,0.16), transparent 25%),
|
| 258 |
radial-gradient(circle at top right, rgba(144,224,239,0.10), transparent 20%),
|
| 259 |
linear-gradient(180deg, #0a0f1d, #0e1422 45%, #0b1020);
|
| 260 |
}
|
| 261 |
+
|
| 262 |
.page-wrap {
|
| 263 |
+
width: 100%;
|
| 264 |
+
max-width: 100%;
|
| 265 |
padding: 6px 4px 30px 4px;
|
| 266 |
+
box-sizing: border-box;
|
| 267 |
}
|
| 268 |
+
|
| 269 |
+
.hero-shell {
|
| 270 |
+
display: grid;
|
| 271 |
+
grid-template-columns: 1fr auto;
|
| 272 |
+
gap: 14px;
|
| 273 |
+
align-items: stretch;
|
| 274 |
+
width: 100%;
|
| 275 |
+
margin-bottom: 20px;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
.hero {
|
| 279 |
display: flex;
|
| 280 |
align-items: center;
|
|
|
|
| 284 |
border: 1px solid var(--border);
|
| 285 |
border-radius: 24px;
|
| 286 |
padding: 28px;
|
|
|
|
| 287 |
box-shadow: var(--shadow);
|
| 288 |
+
width: 100%;
|
| 289 |
+
box-sizing: border-box;
|
| 290 |
}
|
| 291 |
+
|
| 292 |
.eyebrow {
|
| 293 |
color: var(--accent-2);
|
| 294 |
font-size: 12px;
|
|
|
|
| 297 |
text-transform: uppercase;
|
| 298 |
margin-bottom: 8px;
|
| 299 |
}
|
| 300 |
+
|
| 301 |
.hero h1 {
|
| 302 |
margin: 0;
|
| 303 |
color: var(--text);
|
| 304 |
font-size: 36px;
|
| 305 |
line-height: 1.1;
|
| 306 |
}
|
| 307 |
+
|
| 308 |
.hero p {
|
| 309 |
margin: 10px 0 0 0;
|
| 310 |
color: var(--muted);
|
| 311 |
font-size: 16px;
|
| 312 |
}
|
| 313 |
+
|
| 314 |
.hero-actions {
|
| 315 |
+
display: flex;
|
| 316 |
+
align-items: center;
|
| 317 |
+
gap: 14px;
|
| 318 |
}
|
| 319 |
+
|
| 320 |
.hero-stat {
|
| 321 |
+
min-width: 170px;
|
| 322 |
text-align: center;
|
| 323 |
background: rgba(255,255,255,0.04);
|
| 324 |
border: 1px solid var(--border);
|
| 325 |
border-radius: 20px;
|
| 326 |
padding: 18px;
|
| 327 |
}
|
| 328 |
+
|
| 329 |
.stat-num {
|
| 330 |
color: var(--text);
|
| 331 |
font-size: 34px;
|
| 332 |
font-weight: 800;
|
| 333 |
}
|
| 334 |
+
|
| 335 |
.stat-label {
|
| 336 |
color: var(--muted);
|
| 337 |
font-size: 13px;
|
| 338 |
}
|
| 339 |
+
|
| 340 |
+
.hero-refresh,
|
| 341 |
+
.hero-refresh button,
|
| 342 |
+
.hero-refresh > button {
|
| 343 |
+
min-width: 60px !important;
|
| 344 |
+
width: 60px !important;
|
| 345 |
+
height: 60px !important;
|
| 346 |
+
border-radius: 20px !important;
|
| 347 |
+
padding: 0 !important;
|
| 348 |
+
font-size: 24px !important;
|
| 349 |
}
|
| 350 |
+
|
| 351 |
+
.pagination-wrap {
|
| 352 |
+
display: flex;
|
| 353 |
+
justify-content: center;
|
| 354 |
+
align-items: center;
|
| 355 |
+
gap: 12px;
|
| 356 |
+
margin: 0 0 22px 0;
|
| 357 |
+
flex-wrap: wrap;
|
| 358 |
+
width: 100%;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
.page-indicator {
|
| 362 |
+
background: white;
|
| 363 |
+
border: 1px solid var(--border);
|
| 364 |
+
border-radius: 16px;
|
| 365 |
+
padding: 10px 16px;
|
| 366 |
+
box-shadow: var(--shadow);
|
| 367 |
+
color: var(--text);
|
| 368 |
+
font-weight: 600;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
.page-btn button,
|
| 372 |
+
.page-btn > button {
|
| 373 |
+
border-radius: 16px !important;
|
| 374 |
+
min-width: 120px !important;
|
| 375 |
+
height: 44px !important;
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
.stories-list {
|
| 379 |
display: flex;
|
| 380 |
flex-direction: column;
|
| 381 |
gap: 22px;
|
| 382 |
+
width: 100%;
|
| 383 |
}
|
| 384 |
+
|
| 385 |
.story-card {
|
| 386 |
background: white;
|
| 387 |
border: 1px solid var(--border);
|
|
|
|
| 390 |
box-shadow: var(--shadow);
|
| 391 |
backdrop-filter: blur(8px);
|
| 392 |
margin-bottom: 22px;
|
| 393 |
+
width: 100%;
|
| 394 |
+
box-sizing: border-box;
|
| 395 |
}
|
| 396 |
+
|
| 397 |
.story-header {
|
| 398 |
display: flex;
|
| 399 |
justify-content: space-between;
|
|
|
|
| 401 |
gap: 18px;
|
| 402 |
margin-bottom: 18px;
|
| 403 |
}
|
| 404 |
+
|
| 405 |
+
.story-sub .prose,
|
| 406 |
+
.story-sub p {
|
| 407 |
margin: 0 !important;
|
| 408 |
color: var(--muted) !important;
|
| 409 |
font-size: 13px !important;
|
| 410 |
word-break: break-word;
|
| 411 |
}
|
| 412 |
+
|
| 413 |
.story-meta {
|
| 414 |
display: flex;
|
| 415 |
flex-wrap: wrap;
|
| 416 |
gap: 8px;
|
| 417 |
justify-content: flex-end;
|
| 418 |
}
|
| 419 |
+
|
| 420 |
.meta-pill {
|
| 421 |
display: inline-flex;
|
| 422 |
align-items: center;
|
|
|
|
| 430 |
font-size: 12px;
|
| 431 |
font-weight: 600;
|
| 432 |
margin-right: 8px;
|
| 433 |
+
margin-bottom: 8px;
|
| 434 |
}
|
| 435 |
+
|
| 436 |
.story-content {
|
| 437 |
display: grid;
|
| 438 |
grid-template-columns: 1.15fr 0.85fr;
|
| 439 |
gap: 20px;
|
| 440 |
}
|
| 441 |
+
|
| 442 |
.story-text,
|
| 443 |
.story-visuals {
|
| 444 |
background: rgba(255,255,255,0.025);
|
|
|
|
| 446 |
border-radius: 20px;
|
| 447 |
padding: 18px;
|
| 448 |
}
|
| 449 |
+
|
| 450 |
.story-text h3,
|
| 451 |
.story-visuals h3 {
|
| 452 |
margin: 0 0 14px 0;
|
| 453 |
color: var(--text);
|
| 454 |
font-size: 18px;
|
| 455 |
}
|
| 456 |
+
|
| 457 |
.story-markdown .prose,
|
| 458 |
.story-markdown .prose p,
|
| 459 |
.story-markdown .prose li,
|
|
|
|
| 466 |
.story-markdown .prose blockquote {
|
| 467 |
color: var(--text) !important;
|
| 468 |
}
|
| 469 |
+
|
| 470 |
.story-video-wrap video {
|
| 471 |
width: 100% !important;
|
| 472 |
max-height: 580px !important;
|
|
|
|
| 474 |
background: #000 !important;
|
| 475 |
border: 1px solid var(--border) !important;
|
| 476 |
}
|
| 477 |
+
|
| 478 |
.story-gallery {
|
| 479 |
min-height: 80px;
|
| 480 |
}
|
| 481 |
+
|
| 482 |
.story-gallery .grid-wrap,
|
| 483 |
.story-gallery .grid-container,
|
| 484 |
.story-gallery .gallery {
|
| 485 |
border-radius: 16px !important;
|
| 486 |
}
|
| 487 |
+
|
| 488 |
.empty-state {
|
| 489 |
background: rgba(255,255,255,0.025);
|
| 490 |
border: 1px dashed var(--border);
|
|
|
|
| 492 |
padding: 22px;
|
| 493 |
color: var(--muted);
|
| 494 |
}
|
| 495 |
+
|
| 496 |
@media (max-width: 1100px) {
|
| 497 |
+
.hero-shell {
|
| 498 |
+
grid-template-columns: 1fr;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
.story-content {
|
| 502 |
grid-template-columns: 1fr;
|
| 503 |
}
|
| 504 |
+
|
| 505 |
.story-header {
|
| 506 |
flex-direction: column;
|
| 507 |
}
|
| 508 |
+
|
| 509 |
.story-meta {
|
| 510 |
justify-content: flex-start;
|
| 511 |
}
|
| 512 |
+
|
| 513 |
.hero {
|
| 514 |
flex-direction: column;
|
| 515 |
align-items: flex-start;
|
| 516 |
}
|
| 517 |
+
|
| 518 |
+
.hero-refresh,
|
| 519 |
+
.hero-refresh button,
|
| 520 |
+
.hero-refresh > button {
|
| 521 |
+
width: 100% !important;
|
| 522 |
+
}
|
| 523 |
}
|
| 524 |
"""
|
| 525 |
|
| 526 |
|
| 527 |
+
# =========================================================
|
| 528 |
+
# OUTPUT BUILDER
|
| 529 |
+
# =========================================================
|
| 530 |
+
def build_story_outputs(page=1):
|
| 531 |
+
stories = collect_stories()
|
| 532 |
+
total_stories = len(stories)
|
| 533 |
+
total_pages = max(1, (total_stories + STORIES_PER_PAGE - 1) // STORIES_PER_PAGE)
|
| 534 |
+
|
| 535 |
+
try:
|
| 536 |
+
page = int(page)
|
| 537 |
+
except Exception:
|
| 538 |
+
page = 1
|
| 539 |
+
|
| 540 |
+
page = max(1, min(page, total_pages))
|
| 541 |
+
|
| 542 |
+
start_idx = (page - 1) * STORIES_PER_PAGE
|
| 543 |
+
end_idx = start_idx + STORIES_PER_PAGE
|
| 544 |
+
page_stories = stories[start_idx:end_idx]
|
| 545 |
+
|
| 546 |
+
if not stories:
|
| 547 |
+
hero_html = """
|
| 548 |
+
<div class="hero">
|
| 549 |
+
<div>
|
| 550 |
+
<div class="eyebrow">OhamLab Story Showcase</div>
|
| 551 |
+
<h1>OhamLab Enabled</h1>
|
| 552 |
+
<p>No stories found in the dataset repo.</p>
|
| 553 |
+
</div>
|
| 554 |
+
<div class="hero-actions">
|
| 555 |
+
<div class="hero-stat">
|
| 556 |
+
<div class="stat-num">0</div>
|
| 557 |
+
<div class="stat-label">Stories Rendered</div>
|
| 558 |
+
</div>
|
| 559 |
+
</div>
|
| 560 |
+
</div>
|
| 561 |
+
"""
|
| 562 |
+
|
| 563 |
+
outputs = [
|
| 564 |
+
gr.update(value=hero_html),
|
| 565 |
+
|
| 566 |
+
gr.update(value="Page 1 of 1"),
|
| 567 |
+
gr.update(interactive=False),
|
| 568 |
+
gr.update(interactive=False),
|
| 569 |
+
|
| 570 |
+
gr.update(value="Page 1 of 1"),
|
| 571 |
+
gr.update(interactive=False),
|
| 572 |
+
gr.update(interactive=False),
|
| 573 |
+
]
|
| 574 |
+
|
| 575 |
+
for _ in range(STORIES_PER_PAGE):
|
| 576 |
+
outputs.extend([
|
| 577 |
+
gr.update(visible=False),
|
| 578 |
+
gr.update(value=""),
|
| 579 |
+
gr.update(value=""),
|
| 580 |
+
gr.update(value=""),
|
| 581 |
+
gr.update(value=None, visible=False),
|
| 582 |
+
gr.update(value=""),
|
| 583 |
+
gr.update(value=[], visible=False),
|
| 584 |
+
])
|
| 585 |
+
|
| 586 |
+
return outputs
|
| 587 |
+
|
| 588 |
+
hero_html = f"""
|
| 589 |
+
<div class="hero">
|
| 590 |
+
<div>
|
| 591 |
+
<div class="eyebrow">OhamLab Story Showcase</div>
|
| 592 |
+
<h1>OhamLab Enabled</h1>
|
| 593 |
+
<p>Latest generated stories, images, and videos from the dataset repo.</p>
|
| 594 |
+
</div>
|
| 595 |
+
<div class="hero-actions">
|
| 596 |
+
<div class="hero-stat">
|
| 597 |
+
<div class="stat-num">{total_stories}</div>
|
| 598 |
+
<div class="stat-label">Stories Rendered</div>
|
| 599 |
+
</div>
|
| 600 |
+
</div>
|
| 601 |
+
</div>
|
| 602 |
+
"""
|
| 603 |
+
|
| 604 |
+
outputs = [
|
| 605 |
+
gr.update(value=hero_html),
|
| 606 |
+
|
| 607 |
+
# Top pagination
|
| 608 |
+
gr.update(value=f"Page {page} of {total_pages}"),
|
| 609 |
+
gr.update(interactive=page > 1),
|
| 610 |
+
gr.update(interactive=page < total_pages),
|
| 611 |
+
|
| 612 |
+
# Bottom pagination
|
| 613 |
+
gr.update(value=f"Page {page} of {total_pages}"),
|
| 614 |
+
gr.update(interactive=page > 1),
|
| 615 |
+
gr.update(interactive=page < total_pages),
|
| 616 |
+
]
|
| 617 |
+
|
| 618 |
+
for idx in range(STORIES_PER_PAGE):
|
| 619 |
+
if idx < len(page_stories):
|
| 620 |
+
story = page_stories[idx]
|
| 621 |
+
story_md = download_markdown(story["markdown_path"])
|
| 622 |
+
video_path = download_repo_file(story["video_path"]) if story["video_path"] else None
|
| 623 |
+
image_paths = [download_repo_file(p) for p in story["image_paths"]]
|
| 624 |
+
image_paths = [p for p in image_paths if p]
|
| 625 |
+
|
| 626 |
+
title_md = f"## {story['title']}"
|
| 627 |
+
sub_md = story["folder"]
|
| 628 |
+
meta_html = (
|
| 629 |
+
f"<span class='meta-pill'>{format_ts(story['timestamp'])}</span>"
|
| 630 |
+
f"<span class='meta-pill'>{len(story['image_paths'])} images</span>"
|
| 631 |
+
f"<span class='meta-pill'>{'Theme' if story['csv_path'] else 'No Theme'}</span>"
|
| 632 |
+
)
|
| 633 |
+
|
| 634 |
+
outputs.extend([
|
| 635 |
+
gr.update(visible=True),
|
| 636 |
+
gr.update(value=title_md),
|
| 637 |
+
gr.update(value=sub_md),
|
| 638 |
+
gr.update(value=meta_html),
|
| 639 |
+
gr.update(value=video_path, visible=bool(video_path)),
|
| 640 |
+
gr.update(value=story_md),
|
| 641 |
+
gr.update(value=image_paths, visible=bool(image_paths)),
|
| 642 |
+
])
|
| 643 |
+
else:
|
| 644 |
+
outputs.extend([
|
| 645 |
+
gr.update(visible=False),
|
| 646 |
+
gr.update(value=""),
|
| 647 |
+
gr.update(value=""),
|
| 648 |
+
gr.update(value=""),
|
| 649 |
+
gr.update(value=None, visible=False),
|
| 650 |
+
gr.update(value=""),
|
| 651 |
+
gr.update(value=[], visible=False),
|
| 652 |
+
])
|
| 653 |
+
|
| 654 |
+
return outputs
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
def load_first_page():
|
| 658 |
+
return [gr.update(value=1)] + build_story_outputs(1)
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
def refresh_to_first_page():
|
| 662 |
+
return [gr.update(value=1)] + build_story_outputs(1)
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
def go_prev_page(page):
|
| 666 |
+
try:
|
| 667 |
+
page = int(page)
|
| 668 |
+
except Exception:
|
| 669 |
+
page = 1
|
| 670 |
+
new_page = max(1, page - 1)
|
| 671 |
+
return [gr.update(value=new_page)] + build_story_outputs(new_page)
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
def go_next_page(page):
|
| 675 |
+
stories = collect_stories()
|
| 676 |
+
total_pages = max(1, (len(stories) + STORIES_PER_PAGE - 1) // STORIES_PER_PAGE)
|
| 677 |
+
try:
|
| 678 |
+
page = int(page)
|
| 679 |
+
except Exception:
|
| 680 |
+
page = 1
|
| 681 |
+
new_page = min(total_pages, page + 1)
|
| 682 |
+
return [gr.update(value=new_page)] + build_story_outputs(new_page)
|
| 683 |
+
|
| 684 |
+
|
| 685 |
# =========================================================
|
| 686 |
# UI
|
| 687 |
# =========================================================
|
|
|
|
| 690 |
theme=gr.themes.Soft(),
|
| 691 |
css=CUSTOM_CSS,
|
| 692 |
) as demo:
|
| 693 |
+
page_state = gr.State(1)
|
| 694 |
+
|
| 695 |
with gr.Column(elem_classes=["page-wrap"]):
|
| 696 |
+
with gr.Row(elem_classes=["hero-shell"]):
|
| 697 |
hero_html = gr.HTML()
|
| 698 |
+
refresh_btn = gr.Button("↻", variant="secondary", elem_classes=["hero-refresh"], scale=0)
|
| 699 |
+
|
| 700 |
+
# TOP pagination
|
| 701 |
+
with gr.Row(elem_classes=["pagination-wrap"]):
|
| 702 |
+
prev_btn = gr.Button("← Previous", variant="secondary", elem_classes=["page-btn"], scale=0)
|
| 703 |
+
page_info = gr.Markdown("Page 1 of 1", elem_classes=["page-indicator"])
|
| 704 |
+
next_btn = gr.Button("Next →", variant="secondary", elem_classes=["page-btn"], scale=0)
|
| 705 |
|
| 706 |
with gr.Column(elem_classes=["stories-list"]):
|
| 707 |
card_components = []
|
| 708 |
|
| 709 |
+
for _ in range(STORIES_PER_PAGE):
|
| 710 |
with gr.Column(visible=False, elem_classes=["story-card"]) as card:
|
| 711 |
with gr.Row(elem_classes=["story-header"]):
|
| 712 |
with gr.Column(scale=6):
|
|
|
|
| 743 |
gallery_comp,
|
| 744 |
])
|
| 745 |
|
| 746 |
+
# BOTTOM pagination
|
| 747 |
+
with gr.Row(elem_classes=["pagination-wrap"]):
|
| 748 |
+
prev_btn_bottom = gr.Button("← Previous", variant="secondary", elem_classes=["page-btn"], scale=0)
|
| 749 |
+
page_info_bottom = gr.Markdown("Page 1 of 1", elem_classes=["page-indicator"])
|
| 750 |
+
next_btn_bottom = gr.Button("Next →", variant="secondary", elem_classes=["page-btn"], scale=0)
|
| 751 |
+
|
| 752 |
+
all_outputs = [
|
| 753 |
+
hero_html,
|
| 754 |
+
|
| 755 |
+
page_info,
|
| 756 |
+
prev_btn,
|
| 757 |
+
next_btn,
|
| 758 |
+
|
| 759 |
+
page_info_bottom,
|
| 760 |
+
prev_btn_bottom,
|
| 761 |
+
next_btn_bottom,
|
| 762 |
+
] + card_components
|
| 763 |
|
| 764 |
demo.load(
|
| 765 |
+
fn=load_first_page,
|
| 766 |
inputs=[],
|
| 767 |
+
outputs=[page_state] + all_outputs,
|
| 768 |
)
|
| 769 |
|
| 770 |
refresh_btn.click(
|
| 771 |
+
fn=refresh_to_first_page,
|
| 772 |
inputs=[],
|
| 773 |
+
outputs=[page_state] + all_outputs,
|
| 774 |
+
)
|
| 775 |
+
|
| 776 |
+
prev_btn.click(
|
| 777 |
+
fn=go_prev_page,
|
| 778 |
+
inputs=[page_state],
|
| 779 |
+
outputs=[page_state] + all_outputs,
|
| 780 |
+
)
|
| 781 |
+
|
| 782 |
+
next_btn.click(
|
| 783 |
+
fn=go_next_page,
|
| 784 |
+
inputs=[page_state],
|
| 785 |
+
outputs=[page_state] + all_outputs,
|
| 786 |
+
)
|
| 787 |
+
|
| 788 |
+
prev_btn_bottom.click(
|
| 789 |
+
fn=go_prev_page,
|
| 790 |
+
inputs=[page_state],
|
| 791 |
+
outputs=[page_state] + all_outputs,
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
next_btn_bottom.click(
|
| 795 |
+
fn=go_next_page,
|
| 796 |
+
inputs=[page_state],
|
| 797 |
+
outputs=[page_state] + all_outputs,
|
| 798 |
)
|
| 799 |
|
| 800 |
+
demo.launch(share=True)
|