Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import torch # Ensure PyTorch is imported | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| # Load the Netflix dataset from CSV | |
| def load_data(): | |
| df = pd.read_csv("https://huggingface.co/spaces/mfraz/Netflix-data/resolve/main/netflix_titles.csv") | |
| df.fillna("N/A", inplace=True) # Replace NaN values with "N/A" | |
| return df | |
| # Load DialoGPT model and tokenizer | |
| def load_model(): | |
| tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium") | |
| model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium") | |
| return tokenizer, model | |
| # Function to search the dataset for movie details | |
| def search_movie_details(query, data): | |
| query = query.lower() | |
| # Filtering: Ensure column names exist and search query is in title, cast, or director | |
| results = data[ | |
| data["title"].str.lower().str.contains(query, na=False) | | |
| data["cast"].str.lower().str.contains(query, na=False) | | |
| data["director"].str.lower().str.contains(query, na=False) | |
| ] | |
| return results | |
| # Streamlit App | |
| st.title("Netflix Movies 🎬") | |
| # Load dataset and model | |
| data = load_data() | |
| tokenizer, model = load_model() | |
| # User Input (Only Text) | |
| user_input = st.text_input("Enter the movie name, director, or cast:") | |
| # Generate response | |
| if user_input: | |
| movie_results = search_movie_details(user_input, data) | |
| if not movie_results.empty: | |
| st.write("Here are the matching results:") | |
| for _, row in movie_results.iterrows(): | |
| st.write(f"**Title:** {row['title']}") | |
| st.write(f"**Type:** {row['type']}") | |
| st.write(f"**Director:** {row['director']}") | |
| st.write(f"**Cast:** {row['cast']}") | |
| st.write(f"**Release Year:** {row['release_year']}") | |
| st.write(f"**Country:** {row['country']}") # ✅ Now displays Country correctly | |
| st.write(f"**Rating:** {row['rating']}") | |
| st.write(f"**Description:** {row['description']}") | |
| st.write("---") | |
| else: | |
| st.write("**I have no data about this movie. Please search another movie.**") | |