check repo discription for the hosted links. all of my projects are deployed (one version or another. I will soon move all my projects to a clean IAAS platform, so deal with the winding down issue.
Movie recommendation system backend implementation using FastAPI framework with machine learning-based recommendation engine.
This application provides REST API endpoints for movie data management and intelligent recommendations. The system uses cosine similarity algorithms to analyze movie metadata including genres, cast, and plot summaries to generate personalized recommendations.
- Python 3.8 or higher
- OMDb API key (registration required at omdbapi.com)
- 512MB RAM minimum
- 100MB disk space
Core dependencies as specified in requirements.txt:
- fastapi: Web framework for API implementation
- uvicorn: ASGI server for FastAPI applications
- sqlite3: Database engine (included in Python standard library)
- pandas: Data manipulation and analysis
- scikit-learn: Machine learning library for cosine similarity calculations
- numpy: Numerical computing support
- requests: HTTP library for external API calls
- python-dotenv: Environment variable management
- Clone repository:
git clone https://github.com/Agrannya-Singh/CinemaAI_backend.git
cd CinemaAI_backend
- Install dependencies:
pip install -r requirements.txt
- Configure environment variables:
echo "OMDB_API_KEY=your_api_key_here" > .env
- Start application:
uvicorn main:app --host 0.0.0.0 --port 8000
CinemaAI_backend/
├── main.py # Primary application module
├── requirements.txt # Python package dependencies
├── .env # Environment configuration (user-created)
├── movies.db # SQLite database file (auto-generated)
└── similarity_matrix.pkl # Cached similarity computations (auto-generated)
SQLite database with single table structure:
CREATE TABLE IF NOT EXISTS movies (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
overview TEXT,
genres TEXT,
cast TEXT,
poster_path TEXT,
vote_average REAL,
release_date TEXT
);
Base URL: http://localhost:8000
Returns all movies in database.
Request:
- Method: GET
- Headers: None required
- Body: None
Response:
- Status: 200 OK
- Content-Type: application/json
- Body: Array of movie objects
Movie Object Schema:
{
"id": "string",
"title": "string",
"overview": "string",
"genres": "string",
"cast": "string",
"poster_path": "string",
"vote_average": "number",
"release_date": "string"
}
Error Responses:
- 500: Internal server error, no movie data available
Generate movie recommendations based on input movie IDs.
Request:
- Method: POST
- Headers: Content-Type: application/json
- Body:
{
"movie_ids": ["string", "string"],
"num_recommendations": "integer"
}
Request Parameters:
- movie_ids: Array of valid movie ID strings (required)
- num_recommendations: Integer between 1-50, default 10 (optional)
Response:
- Status: 200 OK
- Content-Type: application/json
- Body: Array of recommended movie objects (same schema as GET /movies)
Error Responses:
- 400: Bad request, invalid input format
- 404: Movie IDs not found in database
- 500: Internal server error, recommendation engine failure
Search for movie by title, add to database if not exists.
Request:
- Method: GET
- Path Parameter: title (string, URL-encoded)
- Headers: None required
- Body: None
Response:
- Status: 200 OK
- Content-Type: application/json
- Body: Array containing single movie object
Error Responses:
- 404: Movie not found in OMDb API
- 500: Internal server error, API key invalid or external service unavailable
Variable | Type | Required | Description |
---|---|---|---|
OMDB_API_KEY | string | yes | API key for OMDb service |
Default configuration allows requests from:
- http://localhost:3000
- Methods: GET, POST, PUT, DELETE, OPTIONS
- Headers: All headers permitted
- Credentials: Enabled
System initializes with following movie entries:
- Inception (tt1375666)
- The Dark Knight (tt0468569)
- Interstellar (tt0816692)
- The Matrix (tt0133093)
- Pulp Fiction (tt0110912)
- Forrest Gump (tt0109830)
- The Shawshank Redemption (tt0111161)
- Gladiator (tt0172495)
- Titanic (tt0120338)
- Avatar (tt0499549)
Implementation uses TF-IDF vectorization with cosine similarity:
- Text preprocessing of movie metadata (genres, cast, overview)
- TF-IDF vectorization of combined text features
- Cosine similarity matrix computation
- K-nearest neighbors selection based on similarity scores
- Results filtered by similarity threshold (>0.1)
- Similarity matrix cached as pickle file for improved response times
- Background task processing for matrix computation
- Database queries optimized for single-table operations
- SQLite suitable for development and small deployments
- PostgreSQL for production environments(supabase)
- Implement connection pooling for concurrent requests
- API key stored in environment variables
- No authentication implemented (add as needed)
- Input validation via Pydantic models
- CORS configured for specific origins
Standard HTTP status codes:
- 200: Successful operation
- 400: Client error, invalid request format
- 404: Resource not found
- 500: Server error, check logs
Application uses Python logging module. Log levels:
- INFO: Application startup, database operations
- WARNING: API request failures, external service issues
- ERROR: Critical failures, exception handling
No built-in health check endpoint. Monitor via:
- HTTP response codes
- Application logs
- Database file presence
- Process status
Run in development mode:
uvicorn main:app --reload --log-level debug
Manual testing via curl:
# Get all movies
curl http://localhost:8000/movies
# Get recommendations
curl -X POST http://localhost:8000/recommend \
-H "Content-Type: application/json" \
-d '{"movie_ids":["tt1375666"],"num_recommendations":5}'
# Search movie
curl http://localhost:8000/search/Matrix
Open source project. fork it ; mold it ; its all yours. [MIT License]
Issues tracked via GitHub repository issue tracker.