Spaces:
Runtime error
Runtime error
| 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() |