-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovieAI.py
More file actions
59 lines (41 loc) · 1.72 KB
/
movieAI.py
File metadata and controls
59 lines (41 loc) · 1.72 KB
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
57
58
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer # type: ignore
from sklearn.metrics.pairwise import cosine_similarity
from textblob import TextBlob
from colorama import init, Fore
import time
import sys
# Initialize colorama
init(autoreset=True)
# Load and preprocess the dataset
def load_data(file_path='imdb_top_1000.csv'):
try:
df = pd.read_csv(file_path)
df['combined_features'] = df['Genre'].fillna('') + ' ' + df['Overview'].fillna('')
return df
except FileNotFoundError:
print(Fore.RED + f"Error: The file '{file_path}' was not found.")
exit()
movies_df = load_data()
# Vectorize the combined features and compute cosine similarity
tfidf = TfidfVectorizer(stop_words='english')
tfidf_matrix = tfidf.fit_transform(movies_df['combined_features'])
cosine_sim = cosine_similarity(tfidf_matrix, tfidf_matrix)
# List all unique genres
def list_genres(df):
return sorted(set(genre.strip() for sublist in df['Genre'].dropna().str.split(',') for genre in sublist))
genres = list_genres(movies_df)
# Recommend movies based on filters (genre, mood, rating)
def recomend_movies(genre=None, mood=None, rating=None, top_n=5):
filtered_df = movies_df
if genre:
filtered_df = filtered_df[filtered_df['Genre'].str.contains(genre, case=False, na=False)]
if rating:
filtered_df = filtered_df[filtered_df]
# Display recommendations🍿 😊 😞 🎥
# Small processing animation
# Handle AI recommendation flow 🔍
# Processing animation while analyzing mood 😊 😞 😐
# Processing animation while finding movies
# Small processing animation while finding movies 🎬🍿
# Main program 🎥