Spaces:
Sleeping
Sleeping
File size: 1,481 Bytes
6d07f0d 30b8369 6d07f0d 16e265e 6d07f0d 5a4c042 6d07f0d |
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 45 46 47 48 49 50 51 |
import gradio as gr
from fastai.tabular.all import *
import pickle
import pandas as pd
import torch
learn = load_learner('learn.pkl')
def recommendation(user_id, book_1, book_2, book_3):
data = {'user_id': [user_id, user_id, user_id],
'name': [book_1, book_2, book_3]}
df = pd.DataFrame(data=data)
testdl = learn.dls.test_dl(df)
preds = learn.get_preds(dl=testdl)
preds
rec = 0
idx = -1
for p in range(len(preds[0])):
if float(preds[0][p]) > rec:
idx = p
rec = float(preds[0][p])
return f"O livro recomendado é {books[idx]}. A avaliação estimada é de {rec}"
books = ['To Kill a Mockingbird',
"Harry Potter and the Sorcerer's Stone (Harry Potter (Paperback))",
'The Da Vinci Code',
'Harry Potter and the Goblet of Fire (Book 4)',
'Silence of the Lambs',
'The Fellowship of the Ring (The Lord of the Rings, Part 1)',
'The Little Prince',
'Jurassic Park',
'A Time to Kill'
]
gr.Interface(
fn=recommendation,
title="Sistema de Recomendação para livros",
allow_flagging="never",
share=True,
inputs=[
gr.inputs.Number(default=777777, label="Id do usuário"),
gr.Dropdown(books, label="Primeira opção de livro"),
gr.Dropdown(books, label="Segunda opção de livro"),
gr.Dropdown(books, label="Terceira opção de livro"),
],
outputs="text").launch() |