Spaces:
Runtime error
Runtime error
Download app.py from Golyass/Recomender-System-content-based: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/Golyass/Recomender-System-content-based/resolve/main/app.py
- Command line
-
hf download hf://spaces/Golyass/Recomender-System-content-based/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Golyass/Recomender-System-content-based/resolve/main/app.py
1.78 kB
| import pandas as pd | |
| import numpy as np | |
| import sklearn | |
| from sklearn.metrics.pairwise import cosine_similarity | |
| # Load movie metadata into a pandas DataFrame | |
| movie_data = pd.read_csv('movies_metadata.csv', usecols=['title', 'budget', 'revenue', 'vote_count', 'vote_average']) | |
| # Load movie ratings into a pandas DataFrame | |
| ratings_data = pd.read_csv('ratings_small.csv') | |
| def content_based_filtering(movie_title, num_recommendations=5): | |
| # Drop duplicates and missing values based on 'title' column | |
| movie_data_unique = movie_data.drop_duplicates(subset='title', keep='first').dropna(subset=['budget', 'revenue', 'vote_count', 'vote_average']) | |
| # Calculate similarity scores between input movie and other movies based on selected features | |
| selected_features = ['budget', 'revenue', 'vote_count', 'vote_average'] | |
| movie_features = movie_data_unique[selected_features] | |
| similarity_scores = cosine_similarity(movie_features[movie_data_unique['title'] == movie_title], movie_features) | |
| movie_data_unique['similarity'] = similarity_scores.flatten() | |
| # Get the most similar movies | |
| top_movies = movie_data_unique[movie_data_unique['title'] != movie_title].sort_values(by='similarity', ascending=False)['title'][:num_recommendations] | |
| return top_movies.tolist() | |
| import gradio as gr | |
| with gr.Blocks() as demo: | |
| gr.Markdown("Flip text or image files using this demo.") | |
| title="Movie Recommender System" | |
| movie_title = gr.Textbox(placeholder='movie_title') | |
| #input2 = gr.Textbox(placeholder='second film name...') | |
| #input3 = gr.Textbox(placeholder='third film name...') | |
| text_output=gr.Textbox( ) | |
| text_button = gr.Button("Submit") | |
| text_button.click(content_based_filtering, inputs= movie_title, outputs=text_output) | |
| demo.launch() |