-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (53 loc) · 2.31 KB
/
app.py
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
59
60
61
62
63
64
65
66
import streamlit as st
# Set the background image URL
background_image_url = "https://mcdn.wallpapersafari.com/medium/79/14/VpRCdM.jpg"
# Apply background image using CSS
st.markdown(
f"""
<style>
.stApp {{
background-image: url("{background_image_url}");
background-size: cover;
}}
</style>
""",
unsafe_allow_html=True
)
import pandas as pd
import difflib
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# Load the movies data
movies_data = pd.read_csv('movies.csv')
# Data preprocessing
selected_features = ['genres', 'keywords', 'tagline', 'cast', 'director', 'original_title']
for feature in selected_features:
movies_data[feature] = movies_data[feature].fillna(' ')
combined_feature = movies_data.genres + ' ' + movies_data.keywords + ' ' + movies_data.tagline + ' ' + movies_data.cast + ' ' + movies_data.director + ' ' + movies_data.original_title
# Convert text data into feature vectors
vectorizer = TfidfVectorizer()
feature_vectors = vectorizer.fit_transform(combined_feature)
# Cosine Similarity
similarity = cosine_similarity(feature_vectors)
# Streamlit App
st.title("Movie Recommender System")
# User input
movie_name = st.text_input("Enter your interested English movie name:")
if st.button("Get Recommendations"):
# Find close matches
find_close_match = difflib.get_close_matches(movie_name, movies_data['title'].tolist())
if find_close_match:
close_match = find_close_match[0]
index_of_the_movie = movies_data[movies_data.title == close_match]['index'].values[0]
# Get the list of similar movies
similarity_score = list(enumerate(similarity[index_of_the_movie]))
sorted_similar_movies = sorted(similarity_score, key=lambda x: x[1], reverse=True)[:10]
# Display suggested movies
st.subheader('Suggested movies for you:')
for i, movie in enumerate(sorted_similar_movies):
if i <11:
index = movie[0]
title_from_index = movies_data[movies_data.index == index]['title'].values[0]
st.write(f"{i + 1}. {title_from_index}")
else:
st.warning("No close match found. Please enter a valid movie name.")