Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +63 -61
src/streamlit_app.py
CHANGED
|
@@ -503,24 +503,30 @@ def main():
|
|
| 503 |
if filtered_count == 0:
|
| 504 |
st.subheader("π No Titles Found")
|
| 505 |
else:
|
|
|
|
| 506 |
st.subheader(f"π Found {filtered_count:,} Title{'s' if filtered_count != 1 else ''}")
|
| 507 |
|
| 508 |
if st.session_state.filtered_content:
|
| 509 |
-
#
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
st.
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
st.write("---")
|
| 522 |
|
| 523 |
-
# Pagination
|
| 524 |
items_per_page = 10
|
| 525 |
total_pages = (filtered_count + items_per_page - 1) // items_per_page
|
| 526 |
|
|
@@ -528,36 +534,11 @@ def main():
|
|
| 528 |
if 'current_page' not in st.session_state:
|
| 529 |
st.session_state.current_page = 1
|
| 530 |
|
| 531 |
-
# Page navigation
|
| 532 |
-
col_prev, col_page, col_next = st.columns([1, 2, 1])
|
| 533 |
-
|
| 534 |
-
with col_prev:
|
| 535 |
-
if st.button("β Previous", disabled=st.session_state.current_page == 1):
|
| 536 |
-
st.session_state.current_page -= 1
|
| 537 |
-
st.rerun()
|
| 538 |
-
|
| 539 |
-
with col_page:
|
| 540 |
-
page_input = st.number_input(
|
| 541 |
-
f"Page (of {total_pages})",
|
| 542 |
-
min_value=1,
|
| 543 |
-
max_value=total_pages,
|
| 544 |
-
value=st.session_state.current_page,
|
| 545 |
-
key="page_number"
|
| 546 |
-
)
|
| 547 |
-
if page_input != st.session_state.current_page:
|
| 548 |
-
st.session_state.current_page = page_input
|
| 549 |
-
st.rerun()
|
| 550 |
-
|
| 551 |
-
with col_next:
|
| 552 |
-
if st.button("Next β", disabled=st.session_state.current_page == total_pages):
|
| 553 |
-
st.session_state.current_page += 1
|
| 554 |
-
st.rerun()
|
| 555 |
-
|
| 556 |
# Calculate slice indices for current page
|
| 557 |
start_idx = (st.session_state.current_page - 1) * items_per_page
|
| 558 |
end_idx = min(start_idx + items_per_page, filtered_count)
|
| 559 |
|
| 560 |
-
# Display current
|
| 561 |
st.write(f"Showing {start_idx + 1}-{end_idx} of {filtered_count:,} titles")
|
| 562 |
|
| 563 |
# Show items for current page
|
|
@@ -598,22 +579,35 @@ def main():
|
|
| 598 |
else:
|
| 599 |
st.info("No similar content found.")
|
| 600 |
|
| 601 |
-
# Bottom pagination controls
|
| 602 |
st.write("---")
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
with col_prev2:
|
| 606 |
-
if st.button("β Previous", disabled=st.session_state.current_page == 1, key="prev_bottom"):
|
| 607 |
-
st.session_state.current_page -= 1
|
| 608 |
-
st.rerun()
|
| 609 |
|
| 610 |
-
with
|
| 611 |
-
st.
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
else:
|
| 618 |
st.info("No content matches your current filters. Try adjusting the criteria.")
|
| 619 |
|
|
@@ -690,33 +684,41 @@ def main():
|
|
| 690 |
else:
|
| 691 |
st.warning("Please enter a question first!")
|
| 692 |
|
| 693 |
-
# Footer stats
|
| 694 |
st.markdown("---")
|
| 695 |
if all_content:
|
| 696 |
total_items = len(all_content)
|
| 697 |
filtered_items = len(st.session_state.filtered_content)
|
| 698 |
|
| 699 |
-
# Create columns for stats
|
| 700 |
stat_cols = st.columns(len(selected_services) + 3)
|
| 701 |
|
| 702 |
-
# Basic stats
|
| 703 |
with stat_cols[0]:
|
| 704 |
-
st.metric("Total Available", total_items)
|
| 705 |
|
| 706 |
with stat_cols[1]:
|
| 707 |
-
st.metric("Filtered Results", filtered_items)
|
| 708 |
|
| 709 |
with stat_cols[2]:
|
| 710 |
movies = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'Movie')
|
| 711 |
shows = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'TV Show')
|
| 712 |
-
st.metric("Movies / Shows", f"{movies} / {shows}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 713 |
|
| 714 |
-
# Streaming service breakdown
|
| 715 |
for i, service in enumerate(selected_services, 3):
|
| 716 |
if i < len(stat_cols):
|
| 717 |
service_count = sum(1 for c in st.session_state.filtered_content if c.get('streaming_service') == service)
|
|
|
|
| 718 |
with stat_cols[i]:
|
| 719 |
-
st.metric(service, service_count)
|
| 720 |
|
| 721 |
if __name__ == "__main__":
|
| 722 |
main()
|
|
|
|
| 503 |
if filtered_count == 0:
|
| 504 |
st.subheader("π No Titles Found")
|
| 505 |
else:
|
| 506 |
+
# Header with count and page info
|
| 507 |
st.subheader(f"π Found {filtered_count:,} Title{'s' if filtered_count != 1 else ''}")
|
| 508 |
|
| 509 |
if st.session_state.filtered_content:
|
| 510 |
+
# Active Filters section with better formatting
|
| 511 |
+
if any([filters['content_type'], filters['genres'], filters['ratings'],
|
| 512 |
+
filters['director'], filters['cast']]):
|
| 513 |
+
with st.expander("π Active Filters", expanded=True):
|
| 514 |
+
filter_cols = st.columns(2)
|
| 515 |
+
with filter_cols[0]:
|
| 516 |
+
if filters['content_type']:
|
| 517 |
+
st.write(f"**Type:** {filters['content_type']}")
|
| 518 |
+
if filters['genres']:
|
| 519 |
+
st.write(f"**Genres:** {', '.join(filters['genres'])}")
|
| 520 |
+
if filters['ratings']:
|
| 521 |
+
st.write(f"**Ratings:** {', '.join(filters['ratings'])}")
|
| 522 |
+
with filter_cols[1]:
|
| 523 |
+
if filters['director']:
|
| 524 |
+
st.write(f"**Director:** {filters['director']}")
|
| 525 |
+
if filters['cast']:
|
| 526 |
+
st.write(f"**Cast:** {filters['cast']}")
|
| 527 |
st.write("---")
|
| 528 |
|
| 529 |
+
# Pagination setup
|
| 530 |
items_per_page = 10
|
| 531 |
total_pages = (filtered_count + items_per_page - 1) // items_per_page
|
| 532 |
|
|
|
|
| 534 |
if 'current_page' not in st.session_state:
|
| 535 |
st.session_state.current_page = 1
|
| 536 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
# Calculate slice indices for current page
|
| 538 |
start_idx = (st.session_state.current_page - 1) * items_per_page
|
| 539 |
end_idx = min(start_idx + items_per_page, filtered_count)
|
| 540 |
|
| 541 |
+
# Display current range info
|
| 542 |
st.write(f"Showing {start_idx + 1}-{end_idx} of {filtered_count:,} titles")
|
| 543 |
|
| 544 |
# Show items for current page
|
|
|
|
| 579 |
else:
|
| 580 |
st.info("No similar content found.")
|
| 581 |
|
| 582 |
+
# Bottom pagination controls with better layout
|
| 583 |
st.write("---")
|
| 584 |
+
pagination_cols = st.columns([2, 3, 2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
|
| 586 |
+
with pagination_cols[1]:
|
| 587 |
+
page_cols = st.columns([1, 2, 1])
|
| 588 |
+
|
| 589 |
+
with page_cols[0]:
|
| 590 |
+
if st.button("β Previous", disabled=st.session_state.current_page == 1, use_container_width=True):
|
| 591 |
+
st.session_state.current_page -= 1
|
| 592 |
+
st.rerun()
|
| 593 |
+
|
| 594 |
+
with page_cols[1]:
|
| 595 |
+
page_input = st.number_input(
|
| 596 |
+
f"Page (of {total_pages})",
|
| 597 |
+
min_value=1,
|
| 598 |
+
max_value=total_pages,
|
| 599 |
+
value=st.session_state.current_page,
|
| 600 |
+
key="page_number",
|
| 601 |
+
help=f"Enter a page number between 1 and {total_pages}"
|
| 602 |
+
)
|
| 603 |
+
if page_input != st.session_state.current_page:
|
| 604 |
+
st.session_state.current_page = page_input
|
| 605 |
+
st.rerun()
|
| 606 |
+
|
| 607 |
+
with page_cols[2]:
|
| 608 |
+
if st.button("Next β", disabled=st.session_state.current_page == total_pages, use_container_width=True):
|
| 609 |
+
st.session_state.current_page += 1
|
| 610 |
+
st.rerun()
|
| 611 |
else:
|
| 612 |
st.info("No content matches your current filters. Try adjusting the criteria.")
|
| 613 |
|
|
|
|
| 684 |
else:
|
| 685 |
st.warning("Please enter a question first!")
|
| 686 |
|
| 687 |
+
# Footer stats with improved layout
|
| 688 |
st.markdown("---")
|
| 689 |
if all_content:
|
| 690 |
total_items = len(all_content)
|
| 691 |
filtered_items = len(st.session_state.filtered_content)
|
| 692 |
|
| 693 |
+
# Create columns for stats with better spacing
|
| 694 |
stat_cols = st.columns(len(selected_services) + 3)
|
| 695 |
|
| 696 |
+
# Basic stats with improved formatting
|
| 697 |
with stat_cols[0]:
|
| 698 |
+
st.metric("π Total Available", f"{total_items:,}")
|
| 699 |
|
| 700 |
with stat_cols[1]:
|
| 701 |
+
st.metric("π Filtered Results", f"{filtered_items:,}")
|
| 702 |
|
| 703 |
with stat_cols[2]:
|
| 704 |
movies = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'Movie')
|
| 705 |
shows = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'TV Show')
|
| 706 |
+
st.metric("π¬ Movies / πΊ Shows", f"{movies:,} / {shows:,}")
|
| 707 |
+
|
| 708 |
+
# Streaming service breakdown with icons
|
| 709 |
+
service_icons = {
|
| 710 |
+
"Netflix": "π΄",
|
| 711 |
+
"Amazon Prime": "π΅",
|
| 712 |
+
"Hulu": "π’",
|
| 713 |
+
"Disney+": "π£"
|
| 714 |
+
}
|
| 715 |
|
|
|
|
| 716 |
for i, service in enumerate(selected_services, 3):
|
| 717 |
if i < len(stat_cols):
|
| 718 |
service_count = sum(1 for c in st.session_state.filtered_content if c.get('streaming_service') == service)
|
| 719 |
+
icon = service_icons.get(service, "πΊ")
|
| 720 |
with stat_cols[i]:
|
| 721 |
+
st.metric(f"{icon} {service}", f"{service_count:,}")
|
| 722 |
|
| 723 |
if __name__ == "__main__":
|
| 724 |
main()
|