Commit
·
d316fc7
1
Parent(s):
415bdb0
Update app.py (fix inputs)
Browse files
app.py
CHANGED
|
@@ -4,11 +4,11 @@ import numpy as np
|
|
| 4 |
import pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
-
# api_key =
|
| 8 |
|
| 9 |
# A function that takes a movie name and returns its poster image as a numpy array
|
| 10 |
def get_poster(movie):
|
| 11 |
-
api_key = "
|
| 12 |
base_url = "http://www.omdbapi.com/"
|
| 13 |
|
| 14 |
params = {"apikey": api_key , "t": movie}
|
|
@@ -37,6 +37,7 @@ def get_data(movie):
|
|
| 37 |
if data['Response'] == 'True': # Check if the response is successful
|
| 38 |
poster = data["Poster"]
|
| 39 |
title = data["Title"]
|
|
|
|
| 40 |
director = data["Director"]
|
| 41 |
cast = data["Actors"]
|
| 42 |
genres = data["Genre"]
|
|
@@ -49,13 +50,15 @@ def get_data(movie):
|
|
| 49 |
"director": director,
|
| 50 |
"cast": cast,
|
| 51 |
"genres": genres,
|
| 52 |
-
"rating": rating
|
|
|
|
| 53 |
}
|
|
|
|
| 54 |
# Recommendation Function
|
| 55 |
from core import output_list
|
| 56 |
def get_recommendations(input_list):
|
| 57 |
movie_names = output_list(input_list)
|
| 58 |
-
movies_data = [get_data(movie) for movie in movie_names]
|
| 59 |
|
| 60 |
movie_posters = [get_poster(movie) for movie in movie_names]
|
| 61 |
|
|
@@ -76,7 +79,7 @@ def generate_table(movies, posters):
|
|
| 76 |
|
| 77 |
# Extract the information from the dictionary
|
| 78 |
poster_url = movie_data["poster"]
|
| 79 |
-
title = movie_data[
|
| 80 |
director = movie_data["director"]
|
| 81 |
cast = movie_data["cast"]
|
| 82 |
genres = movie_data["genres"]
|
|
@@ -127,7 +130,7 @@ iface = gr.Interface(
|
|
| 127 |
inputs= [gr.Textbox(label="Enter a movie name (five movie in total!)"), gr.Slider(minimum=0, maximum=5, step=1, label="Rate the movie")],
|
| 128 |
outputs= [gr.Textbox(label="Output", min_width=200), gr.components.Image(label="Poster", height=400, width=300), gr.components.HTML(label="Recommendations", height=400)],
|
| 129 |
live= False,
|
| 130 |
-
examples=[["The Matrix"], ["The Lion King"], ["Titanic"], ['Fight Club'], ["Inception"]],
|
| 131 |
title = "Movie Recommender",
|
| 132 |
|
| 133 |
)
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
# api_key = "a4ed408" _ added to get_poster and get_data Function!
|
| 8 |
|
| 9 |
# A function that takes a movie name and returns its poster image as a numpy array
|
| 10 |
def get_poster(movie):
|
| 11 |
+
api_key = "a4ed408"
|
| 12 |
base_url = "http://www.omdbapi.com/"
|
| 13 |
|
| 14 |
params = {"apikey": api_key , "t": movie}
|
|
|
|
| 37 |
if data['Response'] == 'True': # Check if the response is successful
|
| 38 |
poster = data["Poster"]
|
| 39 |
title = data["Title"]
|
| 40 |
+
year = data["Year"]
|
| 41 |
director = data["Director"]
|
| 42 |
cast = data["Actors"]
|
| 43 |
genres = data["Genre"]
|
|
|
|
| 50 |
"director": director,
|
| 51 |
"cast": cast,
|
| 52 |
"genres": genres,
|
| 53 |
+
"rating": rating,
|
| 54 |
+
"year" : year
|
| 55 |
}
|
| 56 |
+
|
| 57 |
# Recommendation Function
|
| 58 |
from core import output_list
|
| 59 |
def get_recommendations(input_list):
|
| 60 |
movie_names = output_list(input_list)
|
| 61 |
+
#movies_data = [get_data(movie) for movie in movie_names]
|
| 62 |
|
| 63 |
movie_posters = [get_poster(movie) for movie in movie_names]
|
| 64 |
|
|
|
|
| 79 |
|
| 80 |
# Extract the information from the dictionary
|
| 81 |
poster_url = movie_data["poster"]
|
| 82 |
+
title = f"{movie_data['title']} ({movie_data['year']})"
|
| 83 |
director = movie_data["director"]
|
| 84 |
cast = movie_data["cast"]
|
| 85 |
genres = movie_data["genres"]
|
|
|
|
| 130 |
inputs= [gr.Textbox(label="Enter a movie name (five movie in total!)"), gr.Slider(minimum=0, maximum=5, step=1, label="Rate the movie")],
|
| 131 |
outputs= [gr.Textbox(label="Output", min_width=200), gr.components.Image(label="Poster", height=400, width=300), gr.components.HTML(label="Recommendations", height=400)],
|
| 132 |
live= False,
|
| 133 |
+
examples=[["The Matrix"], ["The Lion King"], ["Titanic"], ['Fight Club'], ["Inception"], ["Pulp Fiction"], ["Forrest Gump"], ["Schindler’s List"]],
|
| 134 |
title = "Movie Recommender",
|
| 135 |
|
| 136 |
)
|