Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| import random | |
| # Load the zero-shot classification model | |
| classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") | |
| # Predefined movie list by genre | |
| movie_recommendations = { | |
| "Action": ["Mad Max: Fury Road", "John Wick", "Die Hard"], | |
| "Adventure": ["Indiana Jones", "The Revenant", "Jurassic Park"], | |
| "Comedy": ["Superbad", "Step Brothers", "The Hangover"], | |
| "Drama": ["The Godfather", "Forrest Gump", "The Pursuit of Happyness"], | |
| "Horror": ["The Conjuring", "Get Out", "A Nightmare on Elm Street"], | |
| "Sci-Fi": ["Interstellar", "Blade Runner 2049", "The Matrix"], | |
| "Fantasy": ["Harry Potter", "The Lord of the Rings", "Pan’s Labyrinth"] | |
| } | |
| # Streamlit UI | |
| st.title("🎬 AI Movie Recommender") | |
| st.write("Tell me how you're feeling, and I'll recommend a movie!") | |
| user_input = st.text_input("How are you feeling today?", "I feel adventurous") | |
| if st.button("Get Recommendation"): | |
| # Classify mood to genres | |
| genres = list(movie_recommendations.keys()) | |
| result = classifier(user_input, genres) | |
| best_genre = result["labels"][0] # Top predicted genre | |
| # Select a random movie from the predicted genre | |
| recommended_movie = random.choice(movie_recommendations[best_genre]) | |
| st.success(f"Based on your mood, I recommend: **{recommended_movie}** ({best_genre} genre) 🎥") | |
| st.write("Powered by Hugging Face 🤗 and Streamlit 🚀") | |