File size: 4,510 Bytes
0981063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import streamlit as st
from scripts.recommender import load_data, recommend_movies
from agent import generate_retention_tip

st.set_page_config(page_title="StreamWiseAI", layout="wide")
st.title("🎬 StreamWiseAI – Personalized Movie Recommender & Retention Coach")
st.caption("πŸ€– Powered by AI Agents Β· 🎯 Smart Search Β· 🧠 AI Insights")


# Load data
movies, embeddings = load_data()

# Initialize watch history
if "watch_history" not in st.session_state:
    st.session_state["watch_history"] = []

# Search input
movie_input = st.text_input("Enter a movie you liked", placeholder="e.g. Toy Story")
show_tip = st.checkbox("πŸ’‘ Show retention insight from AI coach?", value=True)

if movie_input:
    with st.spinner("Finding great recommendations..."):
        recommendations = recommend_movies(movie_input, movies, embeddings)

        if not recommendations:
            st.error("❌ Movie not found. Please try another title.")
        else:
            st.subheader(f"πŸ“½οΈ Recommendations for **{recommendations['input_title']}**")

            if recommendations["input_title"] not in st.session_state["watch_history"]:
                st.session_state["watch_history"].append(recommendations["input_title"])

            cols = st.columns(2)

            for idx, rec in enumerate(recommendations["results"]):
                with cols[idx % 2]:
                    with st.container():
                        st.markdown("#### 🎬 " + rec['title'] + f" ({rec['release_year']})")

                        # Fallback-safe image
                        if rec['poster_path']:
                            st.image(f"https://image.tmdb.org/t/p/w200{rec['poster_path']}", width=150)
                        else:
                            st.image("https://via.placeholder.com/150x225.png?text=No+Image", width=150)

                        st.markdown(f"**🎭 Genre(s):** {rec['genres']}")
                        st.markdown(f"**🧠 Similarity Score:** {rec['similarity']:.2f}")
                        
                        # Truncate overview if too long
                        short_overview = rec['overview']
                        if len(short_overview) > 250:
                            short_overview = short_overview[:250] + "..."
                        st.markdown(f"_{short_overview}_")

                        st.markdown("---")

            if show_tip:
                with st.spinner("πŸ€– Retention Coach is analyzing your taste..."):
                    tip = generate_retention_tip(movie_input, recommendations["results"], st.session_state.get("watch_history", []))
                    if tip and not tip.startswith("⚠️"):
                        st.markdown("### πŸ’‘ Retention Coach Suggests:")
                        st.markdown(f"""
                        <div style="background-color:#f0f8ff; padding:15px; border-radius:10px; border-left:5px solid #1f77b4;">
                            <span style="font-size:16px;">{tip}</span>
                        </div>
                        """, unsafe_allow_html=True)
                    else:
                        st.warning("Couldn't generate tip at the moment.")

with st.sidebar:
    st.markdown("## 🎬 **About StreamWiseAI**")
    
    st.markdown("""
<span style='color:#6c63ff'><strong>StreamWiseAI</strong></span> is a personalized movie discovery engine designed for modern streaming platforms.

Built to impress recruiters and mimic real-world production use cases, it features:
    
πŸ” <span style='color:#FFA500'><strong>Semantic Search</strong></span> β€” understands meaning, not just keywords  
🧠 <span style='color:#00BFFF'><strong>AI Retention Coach</strong></span> β€” LLM agent gives viewing tips  
πŸ—‚οΈ <span style='color:#32CD32'><strong>Watch History Memory</strong></span> β€” tracks user session dynamically  
πŸš€ <span style='color:#FF69B4'><strong>Built for Showcase</strong></span> β€” Fast, deployable & free  

---

<small><i>Tech stack: Sentence Transformers Β· Streamlit Β· OpenRouter LLM API Β· Fuzzy Matching Β· Vector Index</i></small>
""", unsafe_allow_html=True)


if st.session_state["watch_history"]:
    st.divider()
    with st.expander("πŸ“œ Recently Searched"):
        st.markdown("πŸ‘€ Here’s a list of your recent searches:")
        st.markdown("\n".join(f"- {title}" for title in st.session_state["watch_history"]))


st.markdown("---")
st.markdown(
    "<small>πŸš€ Built by Rajesh Marudhachalam</small>",
    unsafe_allow_html=True
)