Spaces:
Build error
Build error
Upload 2 files
Browse files- app.py +46 -22
- requirements.txt +141 -59
app.py
CHANGED
|
@@ -1,39 +1,63 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
for i in range(10):
|
| 10 |
-
st.append(';'.join(map(str, df_original.iloc[i])))
|
| 11 |
-
return st
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
user_id = int(user_id)
|
| 27 |
-
time_played_original = float(time_played)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
| 37 |
return ans
|
| 38 |
|
| 39 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
from fastai.tabular.all import *
|
| 5 |
+
from fastai.layers import Module, Embedding, sigmoid_range
|
| 6 |
|
| 7 |
+
import torch
|
| 8 |
+
import torch.nn.functional as F
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
class DotProductBias(Module):
|
| 11 |
+
def __init__(self, n_users, n_games, n_factors, y_range=(0.1, 11754.0)):
|
| 12 |
+
self.user_factors = Embedding(n_users, n_factors)
|
| 13 |
+
self.user_bias = Embedding(n_users, 1)
|
| 14 |
+
self.game_factors = Embedding(n_games, n_factors)
|
| 15 |
+
self.game_bias = Embedding(n_games, 1)
|
| 16 |
+
self.y_range = y_range
|
| 17 |
|
| 18 |
+
def forward(self, x):
|
| 19 |
+
users = self.user_factors(x[:, 0])
|
| 20 |
+
games = self.game_factors(x[:, 1])
|
| 21 |
+
res = (users * games).sum(dim=1, keepdim=True)
|
| 22 |
+
res += self.user_bias(x[:, 0]) + self.game_bias(x[:, 1])
|
| 23 |
+
return torch.sigmoid(res) * (self.y_range[1] - self.y_range[0]) + self.y_range[0]
|
| 24 |
|
| 25 |
|
| 26 |
+
df = pd.read_csv('original.csv')
|
| 27 |
|
| 28 |
+
path = Path("./model.pkl")
|
| 29 |
+
learn = load_learner(path, 'model.pkl')
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
examples = list(df['user-id'].unique())[:20]
|
| 33 |
+
|
| 34 |
+
all_games_title = list(df['game-title'].unique())
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def predict(user_id):
|
| 38 |
|
| 39 |
user_id = int(user_id)
|
|
|
|
| 40 |
|
| 41 |
+
games_alredy_played = list(df[(df['user-id'] == user_id)]['game-title'].unique())
|
| 42 |
+
|
| 43 |
+
games_not_played = set(all_games_title) - set(games_alredy_played)
|
| 44 |
+
size_games_not_played = len(games_not_played)
|
| 45 |
+
|
| 46 |
+
data = {
|
| 47 |
+
'user-id': [user_id]* size_games_not_played,
|
| 48 |
+
'game-title': list(games_not_played),
|
| 49 |
+
'time-played': [0]* size_games_not_played
|
| 50 |
+
}
|
| 51 |
|
| 52 |
+
new_df = pd.DataFrame(data)
|
| 53 |
+
new_dl = learn.dls.test_dl(new_df)
|
| 54 |
+
predictions = learn.get_preds(dl=new_dl)
|
| 55 |
+
predicted_time_played = predictions[0].squeeze().tolist()
|
| 56 |
+
new_df['time-played'] = predicted_time_played
|
| 57 |
+
recomendations = new_df.sort_values(by='time-played', ascending=False).head(10)['game-title'].tolist()
|
| 58 |
+
st = [r + '\n' for r in recomendations]
|
| 59 |
|
| 60 |
+
ans = ''.join(st)
|
| 61 |
return ans
|
| 62 |
|
| 63 |
|
requirements.txt
CHANGED
|
@@ -1,65 +1,147 @@
|
|
| 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 |
Jinja2==3.1.2
|
| 27 |
-
|
| 28 |
-
jsonschema
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
MarkupSafe==2.1.3
|
| 32 |
-
matplotlib==3.
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
python-dateutil==2.8.2
|
| 45 |
-
python-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
six==1.16.0
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
typer==0.9.0
|
| 61 |
-
|
|
|
|
| 62 |
tzdata==2023.3
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apturl==0.5.2
|
| 2 |
+
attrs==21.2.0
|
| 3 |
+
blinker==1.4
|
| 4 |
+
blis==0.7.9
|
| 5 |
+
Brlapi==0.8.3
|
| 6 |
+
catalogue==2.0.8
|
| 7 |
+
certifi==2020.6.20
|
| 8 |
+
chardet==4.0.0
|
| 9 |
+
click==8.0.3
|
| 10 |
+
cmake==3.26.4
|
| 11 |
+
colorama==0.4.4
|
| 12 |
+
command-not-found==0.3
|
| 13 |
+
confection==0.1.0
|
| 14 |
+
contourpy==1.1.0
|
| 15 |
+
cryptography==3.4.8
|
| 16 |
+
cupshelpers==1.0
|
| 17 |
+
cycler==0.11.0
|
| 18 |
+
cymem==2.0.7
|
| 19 |
+
dbus-python==1.2.18
|
| 20 |
+
defer==1.0.6
|
| 21 |
+
distlib==0.3.4
|
| 22 |
+
distro==1.7.0
|
| 23 |
+
distro-info===1.1build1
|
| 24 |
+
docker==5.0.3
|
| 25 |
+
docker-compose==1.29.2
|
| 26 |
+
dockerpty==0.4.1
|
| 27 |
+
docopt==0.6.2
|
| 28 |
+
fastai==2.7.12
|
| 29 |
+
fastcore==1.5.29
|
| 30 |
+
fastdownload==0.0.7
|
| 31 |
+
fastprogress==1.0.3
|
| 32 |
+
filelock==3.6.0
|
| 33 |
+
fonttools==4.41.0
|
| 34 |
+
httplib2==0.20.2
|
| 35 |
+
idna==3.3
|
| 36 |
+
importlib-metadata==4.6.4
|
| 37 |
+
jeepney==0.7.1
|
| 38 |
Jinja2==3.1.2
|
| 39 |
+
joblib==1.3.1
|
| 40 |
+
jsonschema==3.2.0
|
| 41 |
+
keyring==23.5.0
|
| 42 |
+
kiwisolver==1.4.4
|
| 43 |
+
langcodes==3.3.0
|
| 44 |
+
language-selector==0.1
|
| 45 |
+
launchpadlib==1.10.16
|
| 46 |
+
lazr.restfulclient==0.14.4
|
| 47 |
+
lazr.uri==1.0.6
|
| 48 |
+
lit==16.0.6
|
| 49 |
+
louis==3.20.0
|
| 50 |
+
macaroonbakery==1.3.1
|
| 51 |
MarkupSafe==2.1.3
|
| 52 |
+
matplotlib==3.7.2
|
| 53 |
+
more-itertools==8.10.0
|
| 54 |
+
mpmath==1.3.0
|
| 55 |
+
murmurhash==1.0.9
|
| 56 |
+
netifaces==0.11.0
|
| 57 |
+
networkx==3.1
|
| 58 |
+
numpy==1.26.1
|
| 59 |
+
nvidia-cublas-cu11==11.10.3.66
|
| 60 |
+
nvidia-cuda-cupti-cu11==11.7.101
|
| 61 |
+
nvidia-cuda-nvrtc-cu11==11.7.99
|
| 62 |
+
nvidia-cuda-runtime-cu11==11.7.99
|
| 63 |
+
nvidia-cudnn-cu11==8.5.0.96
|
| 64 |
+
nvidia-cufft-cu11==10.9.0.58
|
| 65 |
+
nvidia-curand-cu11==10.2.10.91
|
| 66 |
+
nvidia-cusolver-cu11==11.4.0.1
|
| 67 |
+
nvidia-cusparse-cu11==11.7.4.91
|
| 68 |
+
nvidia-nccl-cu11==2.14.3
|
| 69 |
+
nvidia-nvtx-cu11==11.7.91
|
| 70 |
+
oauthlib==3.2.0
|
| 71 |
+
olefile==0.46
|
| 72 |
+
packaging==23.1
|
| 73 |
+
pandas==2.0.3
|
| 74 |
+
pandas-stubs==2.1.1.230928
|
| 75 |
+
pathy==0.10.2
|
| 76 |
+
pexpect==4.8.0
|
| 77 |
+
Pillow==9.0.1
|
| 78 |
+
platformdirs==2.5.1
|
| 79 |
+
preshed==3.0.8
|
| 80 |
+
protobuf==3.12.4
|
| 81 |
+
psutil==5.9.0
|
| 82 |
+
ptyprocess==0.7.0
|
| 83 |
+
pycairo==1.20.1
|
| 84 |
+
pycups==2.0.1
|
| 85 |
+
pydantic==1.10.11
|
| 86 |
+
Pygments==2.11.2
|
| 87 |
+
PyGObject==3.42.1
|
| 88 |
+
pyinotify==0.9.6
|
| 89 |
+
PyJWT==2.3.0
|
| 90 |
+
pymacaroons==0.13.0
|
| 91 |
+
PyNaCl==1.5.0
|
| 92 |
+
pyparsing==2.4.7
|
| 93 |
+
pyRFC3339==1.1
|
| 94 |
+
pyrsistent==0.18.1
|
| 95 |
+
python-apt==2.4.0+ubuntu1
|
| 96 |
python-dateutil==2.8.2
|
| 97 |
+
python-debian===0.1.43ubuntu1
|
| 98 |
+
python-dotenv==0.19.2
|
| 99 |
+
python-pam==1.8.4
|
| 100 |
+
python-xapp==2.2.1
|
| 101 |
+
python-xlib==0.29
|
| 102 |
+
pytz==2022.1
|
| 103 |
+
pyxdg==0.27
|
| 104 |
+
PyYAML==5.4.1
|
| 105 |
+
reportlab==3.6.8
|
| 106 |
+
requests==2.25.1
|
| 107 |
+
scikit-learn==1.3.0
|
| 108 |
+
scipy==1.11.1
|
| 109 |
+
screen-resolution-extra==0.0.0
|
| 110 |
+
SecretStorage==3.3.1
|
| 111 |
+
setproctitle==1.2.2
|
| 112 |
six==1.16.0
|
| 113 |
+
smart-open==6.3.0
|
| 114 |
+
spacy==3.6.0
|
| 115 |
+
spacy-legacy==3.0.12
|
| 116 |
+
spacy-loggers==1.0.4
|
| 117 |
+
srsly==2.4.6
|
| 118 |
+
ssh-import-id==5.11
|
| 119 |
+
sympy==1.12
|
| 120 |
+
systemd-python==234
|
| 121 |
+
texttable==1.6.4
|
| 122 |
+
thinc==8.1.10
|
| 123 |
+
threadpoolctl==3.2.0
|
| 124 |
+
tinycss==0.4
|
| 125 |
+
tinycss2==1.1.1
|
| 126 |
+
torch==2.0.1
|
| 127 |
+
torchvision==0.15.2
|
| 128 |
+
tqdm==4.65.0
|
| 129 |
+
triton==2.0.0
|
| 130 |
typer==0.9.0
|
| 131 |
+
types-pytz==2023.3.1.1
|
| 132 |
+
typing_extensions==4.7.1
|
| 133 |
tzdata==2023.3
|
| 134 |
+
ubuntu-advantage-tools==8001
|
| 135 |
+
ubuntu-drivers-common==0.0.0
|
| 136 |
+
ufw==0.36.1
|
| 137 |
+
unattended-upgrades==0.1
|
| 138 |
+
urllib3==1.26.5
|
| 139 |
+
virtualenv==20.13.0+ds
|
| 140 |
+
wadllib==1.3.6
|
| 141 |
+
wasabi==1.1.2
|
| 142 |
+
webencodings==0.5.1
|
| 143 |
+
websocket-client==1.2.3
|
| 144 |
+
xdg==5
|
| 145 |
+
xkit==0.0.0
|
| 146 |
+
xlrd==1.2.0
|
| 147 |
+
zipp==1.0.0
|