Skip to content

EngAdhamTamer/movie-knowledge-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎬 Movie Knowledge Graph

A sophisticated movie recommendation system built with FalkorDB graph database, NLP (spaCy), and Streamlit for intelligent, relationship-based movie discovery.

Python FalkorDB License

🌟 Features

  • Graph-Based Recommendations: Leverages FalkorDB to find movies through actor, director, and genre relationships
  • NLP-Powered Analysis: Uses spaCy for entity extraction and semantic analysis of movie plots
  • Multiple Recommendation Strategies:
    • Similar movies based on shared attributes
    • Genre-based filtering with rating thresholds
    • Actor and director filmographies
    • Actor collaboration discovery
    • Network exploration (degrees of separation)
  • Interactive Web Interface: Clean, modern UI built with Streamlit
  • Real-Time Search: Fast graph queries for instant results

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  TMDb API       β”‚
β”‚  (Data Source)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Collector  │────▢│ NLP Processorβ”‚
β”‚ (API Integration)β”‚    β”‚ (spaCy)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                     β”‚
         β–Ό                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     FalkorDB Graph Database     β”‚
β”‚  (Movies, Actors, Directors)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Recommender    │────▢│  Streamlit   β”‚
β”‚  (Graph Queries)β”‚     β”‚  (Frontend)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Tech Stack

  • Graph Database: FalkorDB (Redis-based graph database)
  • NLP: spaCy, sentence-transformers
  • Data Source: TMDb (The Movie Database) API
  • Backend: Python 3.12
  • Frontend: Streamlit
  • Data Processing: pandas, numpy
  • Visualization: plotly, networkx

πŸ“¦ Installation

Prerequisites

  • Python 3.12+
  • Docker (for FalkorDB)
  • TMDb API key (Get one free)

Setup

  1. Clone the repository
git clone https://github.com/EngAdhamTamer/movie-knowledge-graph.git
cd movie-knowledge-graph
  1. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\Activate.ps1
  1. Install dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm
  1. Configure environment
cp .env.example .env
# Edit .env and add your TMDb API key
  1. Start FalkorDB
docker run -p 6379:6379 -it --rm falkordb/falkordb:latest
  1. Populate database
python scripts/populate_graph.py --movies 30
  1. Launch application
streamlit run app.py

Visit http://localhost:8501 in your browser!

πŸ“Š Graph Schema

// Nodes
(:Movie {movie_id, title, year, overview, rating, runtime, budget, revenue})
(:Actor {actor_id, name})
(:Director {director_id, name})
(:Genre {name})

// Relationships
(Actor)-[:ACTED_IN {character}]->(Movie)
(Director)-[:DIRECTED]->(Movie)
(Movie)-[:HAS_GENRE]->(Genre)
(Movie)-[:SIMILAR_TO {score}]->(Movie)

🎯 Usage Examples

Search for Movies by Actor

from src.graph_builder import MovieGraphBuilder
from src.recommender import MovieRecommender

builder = MovieGraphBuilder()
recommender = MovieRecommender(builder)

# Get Tom Hanks movies
movies = recommender.recommend_by_actor("Tom Hanks", limit=10)

Find Similar Movies

# Find movies similar to Inception
similar = recommender.recommend_similar_movies("Inception", limit=5)

Explore Actor Networks

# Find actors connected to Leonardo DiCaprio
network = recommender.get_actor_network("Leonardo DiCaprio", depth=2)

πŸ“Έ Screenshots

Home Dashboard

Shows top-rated movies and database statistics

Recommendation Engine

Find similar movies based on multiple factors

Actor Network Exploration

Discover connections between actors

πŸ› οΈ Project Structure

movie-knowledge-graph/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ data_collector.py    # TMDb API integration
β”‚   β”œβ”€β”€ nlp_processor.py     # NLP & embeddings
β”‚   β”œβ”€β”€ graph_builder.py     # FalkorDB operations
β”‚   └── recommender.py       # Recommendation algorithms
β”œβ”€β”€ scripts/
β”‚   └── populate_graph.py    # Database population
β”œβ”€β”€ tests/
β”œβ”€β”€ app.py                   # Streamlit interface
β”œβ”€β”€ config.py                # Configuration
└── requirements.txt

πŸ”¬ Recommendation Algorithms

  1. Collaborative Filtering: Based on shared actors, directors, and genres
  2. Content-Based: Using NLP embeddings of plot descriptions (planned)
  3. Graph-Based: Leveraging path traversal and relationship strength
  4. Hybrid: Combining multiple signals for better accuracy

🚧 Future Enhancements

  • User ratings and personalized recommendations
  • Sentiment analysis of movie reviews
  • Movie poster similarity using computer vision
  • REST API with FastAPI
  • Deployment to cloud (Heroku/Streamlit Cloud)
  • Advanced graph visualizations with D3.js
  • Topic modeling for plot analysis
  • Real-time trending movies analysis

πŸ“ˆ Performance

  • Query Speed: < 100ms for most graph queries
  • Database Size: ~60 movies, 400+ actors, 60+ directors
  • Scalability: Tested with up to 1000+ movies

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • TMDb for the excellent movie data API
  • FalkorDB for the powerful graph database
  • spaCy for NLP capabilities
  • Streamlit for the amazing web framework

πŸ‘€ Author

Your Name

πŸ“ž Contact

Project Link: https://github.com/EngAdhamTamer/movie-knowledge-graph


⭐ Star this repo if you find it helpful!

About

A Movie Knowledge Graph built with FalkorDB, NLP (spaCy), and Streamlit for intelligent movie recommendations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages