Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +46 -48
src/streamlit_app.py
CHANGED
|
@@ -322,14 +322,14 @@ def get_similar_content(content, n_recommendations=5):
|
|
| 322 |
def main():
|
| 323 |
# Page config
|
| 324 |
st.set_page_config(
|
| 325 |
-
page_title="
|
| 326 |
-
page_icon="
|
| 327 |
layout="wide"
|
| 328 |
)
|
| 329 |
|
| 330 |
-
# Header
|
| 331 |
-
st.title("
|
| 332 |
-
st.write("
|
| 333 |
|
| 334 |
# Check API credentials
|
| 335 |
api_token, together_key = get_api_credentials()
|
|
@@ -546,7 +546,9 @@ def main():
|
|
| 546 |
|
| 547 |
# Show items for current page
|
| 548 |
for i, content in enumerate(st.session_state.filtered_content[start_idx:end_idx], start=start_idx):
|
| 549 |
-
with st.
|
|
|
|
|
|
|
| 550 |
# Content details in columns
|
| 551 |
detail_col1, detail_col2 = st.columns(2)
|
| 552 |
|
|
@@ -605,6 +607,7 @@ def main():
|
|
| 605 |
""")
|
| 606 |
else:
|
| 607 |
st.info("No similar content found.")
|
|
|
|
| 608 |
|
| 609 |
# Bottom pagination controls with better layout
|
| 610 |
st.write("---")
|
|
@@ -648,12 +651,12 @@ def main():
|
|
| 648 |
|
| 649 |
with col2:
|
| 650 |
# AI Chat Section
|
| 651 |
-
st.subheader("
|
| 652 |
-
st.write("
|
| 653 |
|
| 654 |
# Model selection for Together AI
|
| 655 |
model_choice = st.selectbox(
|
| 656 |
-
"Select
|
| 657 |
[
|
| 658 |
"google/gemma-2b-it",
|
| 659 |
"google/gemma-2-27b-it",
|
|
@@ -661,26 +664,30 @@ def main():
|
|
| 661 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 662 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 663 |
],
|
| 664 |
-
help="Select
|
| 665 |
)
|
| 666 |
|
| 667 |
# Example questions
|
| 668 |
-
with st.expander("π‘
|
| 669 |
-
st.write("
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
|
| 675 |
user_question = st.text_area(
|
| 676 |
-
"
|
| 677 |
-
placeholder="
|
| 678 |
height=100
|
| 679 |
)
|
| 680 |
|
| 681 |
-
if st.button("
|
| 682 |
if user_question:
|
| 683 |
-
with st.spinner("
|
| 684 |
# Create context from current filtered data
|
| 685 |
context = create_content_context(st.session_state.filtered_content)
|
| 686 |
|
|
@@ -688,57 +695,48 @@ def main():
|
|
| 688 |
# Get AI response
|
| 689 |
ai_response = get_ai_response(client, user_question, context, model_choice)
|
| 690 |
|
| 691 |
-
st.success("**
|
| 692 |
st.write(ai_response)
|
| 693 |
|
| 694 |
-
# Show
|
| 695 |
-
with st.expander("
|
| 696 |
-
st.write(
|
| 697 |
-
|
| 698 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
|
| 700 |
except Exception as e:
|
| 701 |
-
st.error(
|
| 702 |
|
| 703 |
-
# Fallback response with data analysis
|
| 704 |
-
st.info("**Fallback Analysis:**")
|
| 705 |
-
if st.session_state.filtered_content:
|
| 706 |
-
movies = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'Movie')
|
| 707 |
-
shows = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'TV Show')
|
| 708 |
-
st.write(f"β’ Found {len(st.session_state.filtered_content)} titles ({movies} movies, {shows} TV shows)")
|
| 709 |
-
|
| 710 |
-
# Show top genres
|
| 711 |
-
genres = [g.strip() for c in st.session_state.filtered_content for g in c.get('listed_in', '').split(',')]
|
| 712 |
-
genre_counts = pd.Series(genres).value_counts()
|
| 713 |
-
st.write(f"β’ Top genres: {', '.join(genre_counts.head(3).index)}")
|
| 714 |
-
|
| 715 |
-
# Show year range
|
| 716 |
-
years = [int(c.get('release_year', 0)) for c in st.session_state.filtered_content if c.get('release_year')]
|
| 717 |
-
if years:
|
| 718 |
-
st.write(f"β’ Release years: {min(years)} - {max(years)}")
|
| 719 |
else:
|
| 720 |
-
st.warning("Please
|
| 721 |
|
| 722 |
-
# Footer stats with
|
| 723 |
st.markdown("---")
|
| 724 |
if all_content:
|
| 725 |
total_items = len(all_content)
|
| 726 |
filtered_items = len(st.session_state.filtered_content)
|
| 727 |
|
|
|
|
|
|
|
| 728 |
# Create columns for stats with better spacing
|
| 729 |
stat_cols = st.columns(len(selected_services) + 3)
|
| 730 |
|
| 731 |
# Basic stats with improved formatting
|
| 732 |
with stat_cols[0]:
|
| 733 |
-
st.metric("
|
| 734 |
|
| 735 |
with stat_cols[1]:
|
| 736 |
-
st.metric("
|
| 737 |
|
| 738 |
with stat_cols[2]:
|
| 739 |
movies = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'Movie')
|
| 740 |
shows = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'TV Show')
|
| 741 |
-
st.metric("π¬
|
| 742 |
|
| 743 |
# Streaming service breakdown with icons
|
| 744 |
service_icons = {
|
|
|
|
| 322 |
def main():
|
| 323 |
# Page config
|
| 324 |
st.set_page_config(
|
| 325 |
+
page_title="StreamButler - Your Personal Streaming Concierge",
|
| 326 |
+
page_icon="π©",
|
| 327 |
layout="wide"
|
| 328 |
)
|
| 329 |
|
| 330 |
+
# Header with butler theme
|
| 331 |
+
st.title("π© StreamButler")
|
| 332 |
+
st.write("*At your service! Allow me to curate the perfect streaming entertainment for you.*")
|
| 333 |
|
| 334 |
# Check API credentials
|
| 335 |
api_token, together_key = get_api_credentials()
|
|
|
|
| 546 |
|
| 547 |
# Show items for current page
|
| 548 |
for i, content in enumerate(st.session_state.filtered_content[start_idx:end_idx], start=start_idx):
|
| 549 |
+
with st.container():
|
| 550 |
+
st.write(f"### {content.get('title', 'N/A')} ({content.get('release_year', 'N/A')})")
|
| 551 |
+
|
| 552 |
# Content details in columns
|
| 553 |
detail_col1, detail_col2 = st.columns(2)
|
| 554 |
|
|
|
|
| 607 |
""")
|
| 608 |
else:
|
| 609 |
st.info("No similar content found.")
|
| 610 |
+
st.write("---")
|
| 611 |
|
| 612 |
# Bottom pagination controls with better layout
|
| 613 |
st.write("---")
|
|
|
|
| 651 |
|
| 652 |
with col2:
|
| 653 |
# AI Chat Section
|
| 654 |
+
st.subheader("π© Your Personal Butler")
|
| 655 |
+
st.write("How may I be of assistance in finding your perfect entertainment today?")
|
| 656 |
|
| 657 |
# Model selection for Together AI
|
| 658 |
model_choice = st.selectbox(
|
| 659 |
+
"Select Your Butler's Expertise Level:",
|
| 660 |
[
|
| 661 |
"google/gemma-2b-it",
|
| 662 |
"google/gemma-2-27b-it",
|
|
|
|
| 664 |
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
| 665 |
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 666 |
],
|
| 667 |
+
help="Select your butler's level of expertise in making recommendations"
|
| 668 |
)
|
| 669 |
|
| 670 |
# Example questions
|
| 671 |
+
with st.expander("π‘ How to Address Your Butler"):
|
| 672 |
+
st.write("""
|
| 673 |
+
Your butler understands requests like:
|
| 674 |
+
β’ "My good sir, I seek an action film that would also please my companion who favors comedies."
|
| 675 |
+
β’ "Would you be so kind as to suggest a family-friendly show in the spirit of Stranger Things, but less frightening?"
|
| 676 |
+
β’ "I've quite enjoyed The Crown and Downton Abbey. Might you recommend similar period dramas?"
|
| 677 |
+
β’ "The weather is rather gloomy today. Perhaps a charming romantic comedy or musical?"
|
| 678 |
+
β’ "I'm in search of enlightening documentaries about technology or artificial intelligence."
|
| 679 |
+
β’ "We're hosting a gathering this evening. What entertainment would you suggest for a group?"
|
| 680 |
+
""")
|
| 681 |
|
| 682 |
user_question = st.text_area(
|
| 683 |
+
"How May I Assist You?",
|
| 684 |
+
placeholder="Tell me your preferences, and I shall curate the perfect selection...",
|
| 685 |
height=100
|
| 686 |
)
|
| 687 |
|
| 688 |
+
if st.button("π© Request Recommendations", type="primary"):
|
| 689 |
if user_question:
|
| 690 |
+
with st.spinner("Your butler is carefully selecting the perfect entertainment..."):
|
| 691 |
# Create context from current filtered data
|
| 692 |
context = create_content_context(st.session_state.filtered_content)
|
| 693 |
|
|
|
|
| 695 |
# Get AI response
|
| 696 |
ai_response = get_ai_response(client, user_question, context, model_choice)
|
| 697 |
|
| 698 |
+
st.success("**π© Your Curated Selection:**")
|
| 699 |
st.write(ai_response)
|
| 700 |
|
| 701 |
+
# Show streaming availability
|
| 702 |
+
with st.expander("π© Butler's Note"):
|
| 703 |
+
st.write("""
|
| 704 |
+
To access your selected entertainment:
|
| 705 |
+
1. Kindly select your preferred streaming services above
|
| 706 |
+
2. Locate your chosen title in the curated list
|
| 707 |
+
3. For similar recommendations, simply request "Find Similar Content"
|
| 708 |
+
|
| 709 |
+
*Is there anything else I can assist you with?*
|
| 710 |
+
""")
|
| 711 |
|
| 712 |
except Exception as e:
|
| 713 |
+
st.error("My sincerest apologies, but I seem to be unable to process your request at the moment. Might we try again?")
|
| 714 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 715 |
else:
|
| 716 |
+
st.warning("How may I be of assistance? Please share your entertainment preferences.")
|
| 717 |
|
| 718 |
+
# Footer stats with butler theme
|
| 719 |
st.markdown("---")
|
| 720 |
if all_content:
|
| 721 |
total_items = len(all_content)
|
| 722 |
filtered_items = len(st.session_state.filtered_content)
|
| 723 |
|
| 724 |
+
st.markdown("### π© Your Entertainment Library")
|
| 725 |
+
|
| 726 |
# Create columns for stats with better spacing
|
| 727 |
stat_cols = st.columns(len(selected_services) + 3)
|
| 728 |
|
| 729 |
# Basic stats with improved formatting
|
| 730 |
with stat_cols[0]:
|
| 731 |
+
st.metric("π Complete Collection", f"{total_items:,}")
|
| 732 |
|
| 733 |
with stat_cols[1]:
|
| 734 |
+
st.metric("π― Curated Selection", f"{filtered_items:,}")
|
| 735 |
|
| 736 |
with stat_cols[2]:
|
| 737 |
movies = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'Movie')
|
| 738 |
shows = sum(1 for c in st.session_state.filtered_content if c.get('type') == 'TV Show')
|
| 739 |
+
st.metric("π¬ Films / πΊ Series", f"{movies:,} / {shows:,}")
|
| 740 |
|
| 741 |
# Streaming service breakdown with icons
|
| 742 |
service_icons = {
|