Spaces:
Sleeping
Sleeping
added nav buttons
Browse files
app.py
CHANGED
|
@@ -445,6 +445,33 @@ def tab_advanced_analytics(user_vec):
|
|
| 445 |
|
| 446 |
return fig_radar, fig_embed, stats
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
# ---------------------------
|
| 449 |
# ENHANCED GRADIO UI
|
| 450 |
# ---------------------------
|
|
@@ -453,10 +480,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 453 |
gr.Markdown("# πΈ Advanced Instagram Recommendation Algorithm Simulator")
|
| 454 |
gr.Markdown("### Explore the complex mechanics behind social media content ranking")
|
| 455 |
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
| 457 |
|
|
|
|
|
|
|
|
|
|
| 458 |
# ---------------- TAB A: Enhanced Value Model ----------------
|
| 459 |
-
with gr.Tab("π’ Value Model"):
|
| 460 |
gr.Markdown("### Multi-Signal Content Scoring System")
|
| 461 |
|
| 462 |
with gr.Row():
|
|
@@ -470,7 +503,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 470 |
watch_time = gr.Slider(0, 15, 5, label="π Watch Time (seconds)")
|
| 471 |
creator_tier = gr.Dropdown(list(CREATOR_TIERS.keys()), value="Mid", label="π€ Creator Tier")
|
| 472 |
recency = gr.Slider(0.1, 48, 2, label="β° Hours Since Posted")
|
| 473 |
-
history_match = gr.Slider(0, 1, 0.5, label="π―
|
| 474 |
|
| 475 |
value_output = gr.Markdown()
|
| 476 |
value_chart = gr.Plot()
|
|
@@ -482,7 +515,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 482 |
)
|
| 483 |
|
| 484 |
# ---------------- TAB B: Enhanced Cold Start ----------------
|
| 485 |
-
with gr.Tab("π§ Cold Start & Personalization"):
|
| 486 |
gr.Markdown("### From Generic β Personalized Content")
|
| 487 |
|
| 488 |
with gr.Row():
|
|
@@ -493,7 +526,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 493 |
with gr.Column():
|
| 494 |
demographics = gr.Dropdown(DEMOGRAPHICS, value="Gen Z", label="π₯ Demographics")
|
| 495 |
region = gr.Dropdown(REGIONS, value="North America", label="π Region")
|
| 496 |
-
exploration = gr.Slider(0, 0.5, 0.2, label="π²
|
| 497 |
|
| 498 |
cold_start_output = gr.Markdown()
|
| 499 |
user_vec_state = gr.State()
|
|
@@ -505,7 +538,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 505 |
)
|
| 506 |
|
| 507 |
# ---------------- TAB C: Feed Ranking ----------------
|
| 508 |
-
with gr.Tab("π± Feed Ranking Simulation"):
|
| 509 |
gr.Markdown("### See Your Personalized Feed in Action")
|
| 510 |
|
| 511 |
feed_table = gr.Dataframe()
|
|
@@ -518,7 +551,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 518 |
)
|
| 519 |
|
| 520 |
# ---------------- TAB D: Advanced Analytics ----------------
|
| 521 |
-
with gr.Tab("π Advanced Analytics"):
|
| 522 |
gr.Markdown("### Deep Dive into Algorithm Mechanics")
|
| 523 |
|
| 524 |
analytics_stats = gr.Markdown()
|
|
@@ -533,6 +566,52 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 533 |
outputs=[radar_chart, embedding_chart, analytics_stats]
|
| 534 |
)
|
| 535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
# ---------------- Information Panel ----------------
|
| 537 |
with gr.Accordion("π Algorithm Insights", open=False):
|
| 538 |
gr.Markdown("""
|
|
|
|
| 445 |
|
| 446 |
return fig_radar, fig_embed, stats
|
| 447 |
|
| 448 |
+
# ---------------------------
|
| 449 |
+
# NAVIGATION FUNCTIONS
|
| 450 |
+
# ---------------------------
|
| 451 |
+
|
| 452 |
+
TAB_LABELS = {
|
| 453 |
+
0: "Next β‘ Cold Start",
|
| 454 |
+
1: "Next β‘ Feed Ranking",
|
| 455 |
+
2: "Next β‘ Analytics",
|
| 456 |
+
3: "π Complete!"
|
| 457 |
+
}
|
| 458 |
+
|
| 459 |
+
MAX_TAB = 3
|
| 460 |
+
|
| 461 |
+
def go_next(current_tab):
|
| 462 |
+
new_tab = min(current_tab + 1, MAX_TAB)
|
| 463 |
+
return new_tab
|
| 464 |
+
|
| 465 |
+
def go_prev(current_tab):
|
| 466 |
+
new_tab = max(current_tab - 1, 0)
|
| 467 |
+
return new_tab
|
| 468 |
+
|
| 469 |
+
def update_next_label(current_tab):
|
| 470 |
+
return TAB_LABELS.get(current_tab, "Next β‘")
|
| 471 |
+
|
| 472 |
+
def update_prev_visibility(current_tab):
|
| 473 |
+
return gr.update(visible=current_tab > 0)
|
| 474 |
+
|
| 475 |
# ---------------------------
|
| 476 |
# ENHANCED GRADIO UI
|
| 477 |
# ---------------------------
|
|
|
|
| 480 |
gr.Markdown("# πΈ Advanced Instagram Recommendation Algorithm Simulator")
|
| 481 |
gr.Markdown("### Explore the complex mechanics behind social media content ranking")
|
| 482 |
|
| 483 |
+
# Navigation state
|
| 484 |
+
current_tab = gr.State(0)
|
| 485 |
+
|
| 486 |
+
# Navigation buttons (moved outside tabs)
|
| 487 |
|
| 488 |
+
# Main tabs container
|
| 489 |
+
tabs = gr.Tabs(selected=0)
|
| 490 |
+
with tabs:
|
| 491 |
# ---------------- TAB A: Enhanced Value Model ----------------
|
| 492 |
+
with gr.Tab("π’ Value Model", id=0):
|
| 493 |
gr.Markdown("### Multi-Signal Content Scoring System")
|
| 494 |
|
| 495 |
with gr.Row():
|
|
|
|
| 503 |
watch_time = gr.Slider(0, 15, 5, label="π Watch Time (seconds)")
|
| 504 |
creator_tier = gr.Dropdown(list(CREATOR_TIERS.keys()), value="Mid", label="π€ Creator Tier")
|
| 505 |
recency = gr.Slider(0.1, 48, 2, label="β° Hours Since Posted")
|
| 506 |
+
history_match = gr.Slider(0, 1, 0.5, label="π― User History Match")
|
| 507 |
|
| 508 |
value_output = gr.Markdown()
|
| 509 |
value_chart = gr.Plot()
|
|
|
|
| 515 |
)
|
| 516 |
|
| 517 |
# ---------------- TAB B: Enhanced Cold Start ----------------
|
| 518 |
+
with gr.Tab("π§ Cold Start & Personalization", id=1):
|
| 519 |
gr.Markdown("### From Generic β Personalized Content")
|
| 520 |
|
| 521 |
with gr.Row():
|
|
|
|
| 526 |
with gr.Column():
|
| 527 |
demographics = gr.Dropdown(DEMOGRAPHICS, value="Gen Z", label="π₯ Demographics")
|
| 528 |
region = gr.Dropdown(REGIONS, value="North America", label="π Region")
|
| 529 |
+
exploration = gr.Slider(0, 0.5, 0.2, label="π² Exploration Factor")
|
| 530 |
|
| 531 |
cold_start_output = gr.Markdown()
|
| 532 |
user_vec_state = gr.State()
|
|
|
|
| 538 |
)
|
| 539 |
|
| 540 |
# ---------------- TAB C: Feed Ranking ----------------
|
| 541 |
+
with gr.Tab("π± Feed Ranking Simulation", id=2):
|
| 542 |
gr.Markdown("### See Your Personalized Feed in Action")
|
| 543 |
|
| 544 |
feed_table = gr.Dataframe()
|
|
|
|
| 551 |
)
|
| 552 |
|
| 553 |
# ---------------- TAB D: Advanced Analytics ----------------
|
| 554 |
+
with gr.Tab("π Advanced Analytics", id=3):
|
| 555 |
gr.Markdown("### Deep Dive into Algorithm Mechanics")
|
| 556 |
|
| 557 |
analytics_stats = gr.Markdown()
|
|
|
|
| 566 |
outputs=[radar_chart, embedding_chart, analytics_stats]
|
| 567 |
)
|
| 568 |
|
| 569 |
+
# ---------------------------
|
| 570 |
+
# TAB NAVIGATION LOGIC (FIXED)
|
| 571 |
+
# ---------------------------
|
| 572 |
+
|
| 573 |
+
with gr.Row():
|
| 574 |
+
nav_prev = gr.Button("β¬
Back", size="sm", visible=False)
|
| 575 |
+
nav_next = gr.Button("Next β‘ Cold Start", size="sm")
|
| 576 |
+
|
| 577 |
+
# Next button handler
|
| 578 |
+
nav_next.click(
|
| 579 |
+
fn=go_next,
|
| 580 |
+
inputs=current_tab,
|
| 581 |
+
outputs=current_tab
|
| 582 |
+
).then(
|
| 583 |
+
fn=lambda tab: gr.update(selected=tab),
|
| 584 |
+
inputs=current_tab,
|
| 585 |
+
outputs=tabs
|
| 586 |
+
).then(
|
| 587 |
+
fn=update_next_label,
|
| 588 |
+
inputs=current_tab,
|
| 589 |
+
outputs=nav_next
|
| 590 |
+
).then(
|
| 591 |
+
fn=update_prev_visibility,
|
| 592 |
+
inputs=current_tab,
|
| 593 |
+
outputs=nav_prev
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
+
# Previous button handler
|
| 597 |
+
nav_prev.click(
|
| 598 |
+
fn=go_prev,
|
| 599 |
+
inputs=current_tab,
|
| 600 |
+
outputs=current_tab
|
| 601 |
+
).then(
|
| 602 |
+
fn=lambda tab: gr.update(selected=tab),
|
| 603 |
+
inputs=current_tab,
|
| 604 |
+
outputs=tabs
|
| 605 |
+
).then(
|
| 606 |
+
fn=update_next_label,
|
| 607 |
+
inputs=current_tab,
|
| 608 |
+
outputs=nav_next
|
| 609 |
+
).then(
|
| 610 |
+
fn=update_prev_visibility,
|
| 611 |
+
inputs=current_tab,
|
| 612 |
+
outputs=nav_prev
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
# ---------------- Information Panel ----------------
|
| 616 |
with gr.Accordion("π Algorithm Insights", open=False):
|
| 617 |
gr.Markdown("""
|