File size: 2,389 Bytes
01216bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import google.generativeai as genai

# Set up your Gemini API key
GEMINI_API_KEY = "AIzaSyBpQcVs_Or_Asb4xnNcpk1qUbos-2o9Ddc"
genai.configure(api_key=GEMINI_API_KEY)

# Initialize the Gemini model
model = genai.GenerativeModel('gemini-pro')

# Function to get personalized recommendations
def get_personalized_recommendations(user_preferences):
    prompt = f"""
    You are a personalized content recommendation system. 
    Based on the following user preferences, suggest 5 relevant and family-friendly content items (e.g., movies, books, articles, etc.):
    User Preferences: {user_preferences}
    Provide the recommendations in a clear and concise format with a brief description for each.
    Ensure the content is appropriate for all audiences.
    """

    try:
        # Generate recommendations using Gemini
        response = model.generate_content(prompt)
        return response.text
    except ValueError as e:
        return f"Sorry, the system could not generate recommendations due to safety restrictions. Please try a different query."

# Streamlit app
def main():
    st.title("🎬 Personalized Content Recommendation System")
    st.write("Welcome! Share your preferences, and we'll recommend movies, books, articles, and more tailored just for you.")

    # Collect user preferences
    interests = st.text_input("What are your interests? (e.g., sci-fi movies, space exploration, AI technology):")
    favorite_genres = st.text_input("What are your favorite genres? (e.g., science fiction, documentaries):")
    recently_consumed = st.text_input("What have you recently watched/read? (e.g., Interstellar, The Martian):")

    if st.button("Get Recommendations"):
        if interests and favorite_genres and recently_consumed:
            user_preferences = {
                "interests": interests,
                "favorite_genres": favorite_genres,
                "recently_consumed": recently_consumed
            }

            # Get recommendations
            st.write("Generating recommendations...")
            recommendations = get_personalized_recommendations(user_preferences)
            st.success("Here are your personalized recommendations:")
            st.write(recommendations)
        else:
            st.error("Please fill in all the fields to get recommendations.")

# Run the app
if __name__ == "__main__":
    main()