Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,6 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
import pickle
|
5 |
-
import os
|
6 |
-
from dotenv import load_dotenv
|
7 |
-
|
8 |
-
# Load environment variables
|
9 |
-
load_dotenv()
|
10 |
-
|
11 |
|
12 |
# Load the processed data and similarity matrix
|
13 |
with open('movie_data.pkl', 'rb') as file:
|
@@ -24,13 +18,23 @@ def get_recommendations(title, cosine_sim=cosine_sim):
|
|
24 |
|
25 |
# Fetch movie poster from TMDB API
|
26 |
def fetch_poster(movie_id):
|
27 |
-
api_key =
|
28 |
url = f'https://api.themoviedb.org/3/movie/{movie_id}?api_key={api_key}'
|
29 |
response = requests.get(url)
|
|
|
|
|
|
|
|
|
|
|
30 |
data = response.json()
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Streamlit UI
|
36 |
st.title("Movie Recommendation System")
|
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
import pickle
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Load the processed data and similarity matrix
|
7 |
with open('movie_data.pkl', 'rb') as file:
|
|
|
18 |
|
19 |
# Fetch movie poster from TMDB API
|
20 |
def fetch_poster(movie_id):
|
21 |
+
api_key = "d52d86933103ae578bbf057ec39d012e" # Your TMDB API key
|
22 |
url = f'https://api.themoviedb.org/3/movie/{movie_id}?api_key={api_key}'
|
23 |
response = requests.get(url)
|
24 |
+
|
25 |
+
# Check if the request was successful
|
26 |
+
if response.status_code != 200:
|
27 |
+
return "https://via.placeholder.com/500x750?text=No+Image+Available" # Placeholder for errors
|
28 |
+
|
29 |
data = response.json()
|
30 |
+
|
31 |
+
# Safely access 'poster_path'
|
32 |
+
poster_path = data.get('poster_path')
|
33 |
+
if poster_path:
|
34 |
+
return f"https://image.tmdb.org/t/p/w500{poster_path}"
|
35 |
+
|
36 |
+
# Return placeholder if 'poster_path' is missing
|
37 |
+
return "https://via.placeholder.com/500x750?text=No+Image+Available"
|
38 |
|
39 |
# Streamlit UI
|
40 |
st.title("Movie Recommendation System")
|