Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,42 @@
|
|
| 1 |
-
from
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
"happy": {
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
mood = request.form.get('mood').lower()
|
| 17 |
-
movie = movie_database.get(mood, None)
|
| 18 |
-
return render_template('result.html', movie=movie)
|
| 19 |
-
return render_template('index.html')
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
|
| 3 |
+
# Load a pre-trained model for text classification (e.g., sentiment analysis)
|
| 4 |
+
classifier = pipeline("sentiment-analysis")
|
| 5 |
|
| 6 |
+
# Simple movie recommendations based on mood
|
| 7 |
+
movie_recommendations = {
|
| 8 |
+
"happy": {
|
| 9 |
+
"comedy": {"title": "The Grand Budapest Hotel", "image_url": "comedy_movie_image_url"},
|
| 10 |
+
"action": {"title": "Guardians of the Galaxy", "image_url": "action_movie_image_url"}
|
| 11 |
+
},
|
| 12 |
+
"sad": {
|
| 13 |
+
"drama": {"title": "The Pursuit of Happyness", "image_url": "drama_movie_image_url"},
|
| 14 |
+
"romance": {"title": "The Notebook", "image_url": "romance_movie_image_url"}
|
| 15 |
+
},
|
| 16 |
+
"angry": {
|
| 17 |
+
"action": {"title": "Mad Max: Fury Road", "image_url": "action_movie_image_url"},
|
| 18 |
+
"thriller": {"title": "John Wick", "image_url": "thriller_movie_image_url"}
|
| 19 |
+
}
|
| 20 |
}
|
| 21 |
|
| 22 |
+
# Ask user for their mood and preferred genre
|
| 23 |
+
mood_input = input("Enter your mood (happy, sad, angry): ").lower()
|
| 24 |
+
genre_input = input("Enter your preferred genre (comedy, action, drama, romance, thriller): ").lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Use sentiment analysis to confirm or adjust the user's mood input (optional)
|
| 27 |
+
result = classifier(mood_input)[0]
|
| 28 |
+
detected_mood = result['label'].lower()
|
| 29 |
+
|
| 30 |
+
if detected_mood in movie_recommendations:
|
| 31 |
+
mood = detected_mood
|
| 32 |
+
else:
|
| 33 |
+
mood = mood_input
|
| 34 |
+
|
| 35 |
+
# Fetch the movie recommendation
|
| 36 |
+
movie = movie_recommendations.get(mood, {}).get(genre_input, None)
|
| 37 |
+
|
| 38 |
+
if movie:
|
| 39 |
+
print(f"We recommend you watch '{movie['title']}'!")
|
| 40 |
+
print(f"Movie Image: {movie['image_url']}")
|
| 41 |
+
else:
|
| 42 |
+
print("Sorry, we couldn't find a recommendation for your mood and genre combination.")
|