Gabriel
feat: app, req, valid
766b779
raw
history blame
898 Bytes
import gradio as gr
import numpy as np
import pandas as pd
from fastai.learner import load_learner
learn = load_learner("model.pkl")
dados = pd.read_csv('valid.csv')
ids = dados['user'].unique()
ids_list = list(map(str, ids.tolist()))
ratings = pd.read_csv('ratings.csv')
def top5(user):
items = pd.Series(learn.dls.classes['title']).unique()
clas_items = ratings.loc[(ratings['user'] == user) & (ratings['rating'] > 0), 'title']
no_clas_items = np.setdiff1d(items, clas_items)
df = pd.DataFrame({'user': [user]*len(no_clas_items), 'title': no_clas_items})
preds,_ = learn.get_preds(dl=learn.dls.test_dl(df))
df['prediction'] = preds.numpy()
top_5 = df.nlargest(5, 'prediction')
return '\n'.join(top_5['title'].tolist())
iface = gr.Interface(fn=top5, inputs=gr.Dropdown(choices=ids_list), outputs="text")
iface.launch(share=True)