JanaAlbader commited on
Commit
74088e2
·
verified ·
1 Parent(s): 005814c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -1,22 +1,42 @@
1
- from flask import Flask, render_template, request
2
 
3
- app = Flask(__name__)
 
4
 
5
- # Sample movie database
6
- movie_database = {
7
- "happy": {"title": "The Pursuit of Happyness", "image_url": "https://example.com/happy.jpg"},
8
- "sad": {"title": "The Fault in Our Stars", "image_url": "https://example.com/sad.jpg"},
9
- "excited": {"title": "Mad Max: Fury Road", "image_url": "https://example.com/excited.jpg"},
10
- "relaxed": {"title": "The Secret Life of Walter Mitty", "image_url": "https://example.com/relaxed.jpg"}
 
 
 
 
 
 
 
 
11
  }
12
 
13
- @app.route('/', methods=['GET', 'POST'])
14
- def home():
15
- if request.method == 'POST':
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
- if __name__ == '__main__':
22
- app.run(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")