Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
|
| 4 |
+
# Set up your Gemini API key
|
| 5 |
+
GEMINI_API_KEY = "AIzaSyBpQcVs_Or_Asb4xnNcpk1qUbos-2o9Ddc"
|
| 6 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
| 7 |
+
|
| 8 |
+
# Initialize the Gemini model
|
| 9 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 10 |
+
|
| 11 |
+
# Function to get personalized recommendations
|
| 12 |
+
def get_personalized_recommendations(user_preferences):
|
| 13 |
+
prompt = f"""
|
| 14 |
+
You are a personalized content recommendation system.
|
| 15 |
+
Based on the following user preferences, suggest 5 relevant and family-friendly content items (e.g., movies, books, articles, etc.):
|
| 16 |
+
User Preferences: {user_preferences}
|
| 17 |
+
Provide the recommendations in a clear and concise format with a brief description for each.
|
| 18 |
+
Ensure the content is appropriate for all audiences.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
# Generate recommendations using Gemini
|
| 23 |
+
response = model.generate_content(prompt)
|
| 24 |
+
return response.text
|
| 25 |
+
except ValueError as e:
|
| 26 |
+
return f"Sorry, the system could not generate recommendations due to safety restrictions. Please try a different query."
|
| 27 |
+
|
| 28 |
+
# Streamlit app
|
| 29 |
+
def main():
|
| 30 |
+
st.title("🎬 Personalized Content Recommendation System")
|
| 31 |
+
st.write("Welcome! Share your preferences, and we'll recommend movies, books, articles, and more tailored just for you.")
|
| 32 |
+
|
| 33 |
+
# Collect user preferences
|
| 34 |
+
interests = st.text_input("What are your interests? (e.g., sci-fi movies, space exploration, AI technology):")
|
| 35 |
+
favorite_genres = st.text_input("What are your favorite genres? (e.g., science fiction, documentaries):")
|
| 36 |
+
recently_consumed = st.text_input("What have you recently watched/read? (e.g., Interstellar, The Martian):")
|
| 37 |
+
|
| 38 |
+
if st.button("Get Recommendations"):
|
| 39 |
+
if interests and favorite_genres and recently_consumed:
|
| 40 |
+
user_preferences = {
|
| 41 |
+
"interests": interests,
|
| 42 |
+
"favorite_genres": favorite_genres,
|
| 43 |
+
"recently_consumed": recently_consumed
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
# Get recommendations
|
| 47 |
+
st.write("Generating recommendations...")
|
| 48 |
+
recommendations = get_personalized_recommendations(user_preferences)
|
| 49 |
+
st.success("Here are your personalized recommendations:")
|
| 50 |
+
st.write(recommendations)
|
| 51 |
+
else:
|
| 52 |
+
st.error("Please fill in all the fields to get recommendations.")
|
| 53 |
+
|
| 54 |
+
# Run the app
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
main()
|