Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +61 -7
src/streamlit_app.py
CHANGED
|
@@ -191,7 +191,7 @@ def create_content_context(content_list):
|
|
| 191 |
movies = sum(1 for c in content_list if c.get('type') == 'Movie')
|
| 192 |
shows = sum(1 for c in content_list if c.get('type') == 'TV Show')
|
| 193 |
|
| 194 |
-
context = f"""Currently showing {total}
|
| 195 |
|
| 196 |
# Add some genre info
|
| 197 |
all_genres = []
|
|
@@ -214,7 +214,7 @@ def create_content_context(content_list):
|
|
| 214 |
def get_ai_response(client, question, context, model_name):
|
| 215 |
"""Get response from Together AI"""
|
| 216 |
try:
|
| 217 |
-
prompt = f"""You are a helpful
|
| 218 |
|
| 219 |
Current Content Data Context:
|
| 220 |
{context}
|
|
@@ -226,7 +226,7 @@ Please provide a helpful, accurate response based on the data provided. Keep you
|
|
| 226 |
response = client.chat.completions.create(
|
| 227 |
model=model_name,
|
| 228 |
messages=[
|
| 229 |
-
{"role": "system", "content": "You are a helpful
|
| 230 |
{"role": "user", "content": prompt}
|
| 231 |
],
|
| 232 |
max_tokens=300,
|
|
@@ -519,9 +519,49 @@ def main():
|
|
| 519 |
if filters['cast']:
|
| 520 |
st.write(f"- Cast: {filters['cast']}")
|
| 521 |
st.write("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
|
| 523 |
-
# Show
|
| 524 |
-
for i, content in enumerate(st.session_state.filtered_content[:
|
| 525 |
with st.expander(f"{content.get('title', 'N/A')} ({content.get('release_year', 'N/A')})"):
|
| 526 |
# Content details in columns
|
| 527 |
detail_col1, detail_col2 = st.columns(2)
|
|
@@ -558,8 +598,22 @@ def main():
|
|
| 558 |
else:
|
| 559 |
st.info("No similar content found.")
|
| 560 |
|
| 561 |
-
|
| 562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
else:
|
| 564 |
st.info("No content matches your current filters. Try adjusting the criteria.")
|
| 565 |
|
|
|
|
| 191 |
movies = sum(1 for c in content_list if c.get('type') == 'Movie')
|
| 192 |
shows = sum(1 for c in content_list if c.get('type') == 'TV Show')
|
| 193 |
|
| 194 |
+
context = f"""Currently showing {total} titles ({movies} movies and {shows} TV shows). """
|
| 195 |
|
| 196 |
# Add some genre info
|
| 197 |
all_genres = []
|
|
|
|
| 214 |
def get_ai_response(client, question, context, model_name):
|
| 215 |
"""Get response from Together AI"""
|
| 216 |
try:
|
| 217 |
+
prompt = f"""You are a helpful streaming content expert. Based on the current content data, please answer the user's question accurately and helpfully.
|
| 218 |
|
| 219 |
Current Content Data Context:
|
| 220 |
{context}
|
|
|
|
| 226 |
response = client.chat.completions.create(
|
| 227 |
model=model_name,
|
| 228 |
messages=[
|
| 229 |
+
{"role": "system", "content": "You are a helpful content expert with deep knowledge of movies and TV shows."},
|
| 230 |
{"role": "user", "content": prompt}
|
| 231 |
],
|
| 232 |
max_tokens=300,
|
|
|
|
| 519 |
if filters['cast']:
|
| 520 |
st.write(f"- Cast: {filters['cast']}")
|
| 521 |
st.write("---")
|
| 522 |
+
|
| 523 |
+
# Pagination controls
|
| 524 |
+
items_per_page = 10
|
| 525 |
+
total_pages = (filtered_count + items_per_page - 1) // items_per_page
|
| 526 |
+
|
| 527 |
+
# Initialize page number in session state if not exists
|
| 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 page info
|
| 561 |
+
st.write(f"Showing {start_idx + 1}-{end_idx} of {filtered_count:,} titles")
|
| 562 |
|
| 563 |
+
# Show items for current page
|
| 564 |
+
for i, content in enumerate(st.session_state.filtered_content[start_idx:end_idx], start=start_idx):
|
| 565 |
with st.expander(f"{content.get('title', 'N/A')} ({content.get('release_year', 'N/A')})"):
|
| 566 |
# Content details in columns
|
| 567 |
detail_col1, detail_col2 = st.columns(2)
|
|
|
|
| 598 |
else:
|
| 599 |
st.info("No similar content found.")
|
| 600 |
|
| 601 |
+
# Bottom pagination controls
|
| 602 |
+
st.write("---")
|
| 603 |
+
col_prev2, col_page2, col_next2 = st.columns([1, 2, 1])
|
| 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 col_page2:
|
| 611 |
+
st.write(f"Page {st.session_state.current_page} of {total_pages}")
|
| 612 |
+
|
| 613 |
+
with col_next2:
|
| 614 |
+
if st.button("Next →", disabled=st.session_state.current_page == total_pages, key="next_bottom"):
|
| 615 |
+
st.session_state.current_page += 1
|
| 616 |
+
st.rerun()
|
| 617 |
else:
|
| 618 |
st.info("No content matches your current filters. Try adjusting the criteria.")
|
| 619 |
|