Hi, great lesson!
I am doing collaborative filtering with anime dataset.
First, I created a model and exported it as pkl.
Next I created app.py file with dls, learn (from my .pkl) and defined function:
def find_similar_animes(anime_name, learn, dls, top_n=5) …
where anime_name should be selected from the list (name of the anime from anime dataframe).
the output of find_similar_anime function is
similar_animes = [dls.classes[‘name’][i] for i in top_indices].
When I provide anime name to anime_name and run it in notebook -I am getting the result - 5 similar animes:
anime_name = “Durarara!!”
similar_animes = find_similar_animes(anime_name, learn, dls)
print(f"Top 5 similar animes to ‘{anime_name}’:“)
for i, movie in enumerate(similar_animes, 1):
print(f”{i}. {movie}").
The output is:
Top 5 similar animes to ‘Durarara!!’:
- Gintama Movie: Shinyaku Benizakura-hen
- Haikyuu!! Second Season
- Major S1
- Gin no Saji
- Steins;Gate: Kyoukaimenjou no Missing Link - Divide By Zero.
Which is great! I stumble into an issue when trying to create Gradio interface.
interface = gr.Interface(
fn=find_similar_animes,
inputs=gr.Dropdown(choices=list(anime[‘name’]), label=“Select Anime”),
#learn = load_learner(model),
#dls = CollabDataLoaders.from_df(ratings, item_name=‘name’, bs=64),
outputs = gr.Textbox(),
title=“Find Similar Animes”,
description=“Select an anime from the dropdown list to find similar animes.”
)
interface.launch()
The gradio creates interface, where I can pick anime name from the drop down, but the output shows an error:
How can I define the output, so it is displayed as a list of recommended animes?