Spaces:
Runtime error
Runtime error
File size: 1,329 Bytes
645bb1b 5663632 3f2d560 3b40cf3 3f2d560 645bb1b 3b40cf3 3f2d560 3b40cf3 3f2d560 645bb1b 3b40cf3 3f2d560 3b40cf3 3f2d560 3b40cf3 645bb1b 668a83d 645bb1b 3b40cf3 39b4954 3b40cf3 645bb1b 5663632 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import os
import gradio as gr
import wandb
from machine_learning.recommending.app import build_app_blocks, MovieMarkdownGenerator
from machine_learning.recommending.movielens import MovieLensNonGradientRecommender
from machine_learning.recommending.movielens.data import MovieLens25m
project = "Recommending"
tmdb_api_token = os.environ["TMDB_API_TOKEN"]
lightning_class = MovieLensNonGradientRecommender
config = dict(
model_artifact="my_mf_slim_movielens_25m:latest",
data_artifact="movielens25m:latest",
media_directory="media",
)
wandb.init(job_type="app", project=project, config=config)
model_artifact = wandb.use_artifact(config["model_artifact"])
checkpoint_path = model_artifact.file()
lightning_module = lightning_class.load_from_checkpoint(
checkpoint_path, map_location="cpu"
)
recommender = lightning_module.model.eval()
data_artifact = wandb.use_artifact(config["data_artifact"])
data_directory = data_artifact.download()
movielens = MovieLens25m(directory=data_directory)
movie_markdown_generator = MovieMarkdownGenerator(
movielens=movielens, tmdb_api_token=tmdb_api_token
)
with gr.Blocks() as app:
build_app_blocks(
recommender=recommender,
movie_markdown_generator=movie_markdown_generator,
media_directory=config["media_directory"],
)
app.launch()
|