Download api.py from Adpacci/cinematch: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/Adpacci/cinematch/resolve/main/api.py
- Command line
-
hf download hf://spaces/Adpacci/cinematch/api.py
-
curl -L -o api.py https://huggingface.co/spaces/Adpacci/cinematch/resolve/main/api.py
1.16 kB
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import sys, os | |
| from download_data import download_tmdb_data | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from model.recommender import load_data, build_tags, build_model, recommend, get_movie_details | |
| app = FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| POPULAR = [ | |
| "The Dark Knight", "Inception", "Interstellar", "The Godfather", | |
| "Pulp Fiction", "Fight Club", "The Matrix", "Goodfellas", | |
| "Schindler's List", "Avatar" | |
| ] | |
| async def startup(): | |
| global df, similarity | |
| download_tmdb_data() | |
| df = load_data() | |
| df = build_tags(df) | |
| similarity = build_model(df) | |
| def get_recommendations(title: str): | |
| titles = recommend(title, df, similarity) | |
| return [{"title": t, **get_movie_details(t)} for t in titles] | |
| def get_popular(): | |
| return [{"title": t, **get_movie_details(t)} for t in POPULAR] | |
| def get_movies(): | |
| return {"movies": sorted(df["title"].tolist())} |