import gradio as gr import requests import numpy as np import pandas as pd from PIL import Image # api_key = "a4ed408" _ added to get_poster and get_data Function! # A function that takes a movie name and returns its poster image as a numpy array def get_poster(movie): api_key = "a4ed408" base_url = "http://www.omdbapi.com/" params = {"apikey": api_key , "t": movie} response = requests.get(base_url, params=params) data = response.json() if data['Response'] == 'True': # Check if the response is successful # Open the image from the url poster_image = Image.open(requests.get(data['Poster'], stream=True).raw) # Convert the image to a numpy array poster_array = np.array(poster_image) return poster_array else: return np.zeros((500, 500, 3)) # A function that takes a movie name and returns its meta data def get_data(movie): api_key = "4e45e5b0" base_url = "http://www.omdbapi.com/" params = {"apikey": api_key , "t": movie} response = requests.get(base_url, params=params) data = response.json() if data['Response'] == 'True': # Check if the response is successful status = data['Response'] poster = data["Poster"] title = data["Title"] year = data["Year"] director = data["Director"] cast = data["Actors"] genres = data["Genre"] rating = data["imdbRating"] # Return a dictionary with the information return { "status": status, "poster": poster, "title": title, "director": director, "cast": cast, "genres": genres, "rating": rating, "year" : year } # Recommendation Function from core import output_list def get_recommendations(input_list): movie_names = output_list(input_list) #movies_data = [get_data(movie) for movie in movie_names] movie_posters = [get_poster(movie) for movie in movie_names] return movie_names, movie_posters # HTML table def generate_table(movies, posters): html_code = "" # Add the table tag and style attributes html_code += "
" # Add a table cell tag with the movie information as a paragraph tag html_code += f" | Title: {title} Director: {director} Cast: {cast} Genres: {genres} Rating: {rating} | "
# Close the table row tag
html_code += "