Spaces:
Build error
Build error
| import gradio as gr | |
| import pickle | |
| from fastai.collab import * | |
| from fastai.tabular.all import * | |
| import pandas | |
| import pandas.core.indexes.numeric | |
| #__all__ = ['NumberClass', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
| class DotProductBias(Module): | |
| def __init__(self, n_users, n_animes, n_factors, y_range=(0,10.5)): | |
| self.user_factors = Embedding(n_users, n_factors) | |
| self.user_bias = Embedding(n_users, 1) | |
| self.anime_factors = Embedding(n_animes, n_factors) | |
| self.anime_bias = Embedding(n_animes, 1) | |
| self.y_range = y_range | |
| def forward(self, x): | |
| users = self.user_factors(x[:,0]) | |
| animes = self.anime_factors(x[:,1]) | |
| res = (users * animes).sum(dim=1, keepdim=True) | |
| res += self.user_bias(x[:,0]) + self.anime_bias(x[:,1]) | |
| return sigmoid_range(res, *self.y_range) | |
| def get_y(r): | |
| result = learn.forward(r) | |
| return result[0][0] | |
| class CustomUnpickler(pickle.Unpickler): | |
| def persistent_load(self, persid): | |
| return None | |
| with open('CollaborativeFiltering.pkl', 'rb') as f: | |
| custom_unpickler = CustomUnpickler(f) | |
| learn = custom_unpickler.load() | |
| label = gr.outputs.Label() | |
| usr = gr.inputs.Number(label = 'Usuário') | |
| anime = gr.inputs.Number(label = 'Anime') | |
| r = tensor([[usr, anime]]) | |
| inputs = [r] | |
| output = gr.outputs.Textbox() | |
| intf = gr.Interface(fn=get_y, inputs="r", outputs=output) | |
| intf.launch(inline=False) |