Daniel-Sousa commited on
Commit
5e5ef16
·
1 Parent(s): b07504b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.learner import load_learner
3
+ import pandas as pd
4
+ import numpy as np
5
+
6
+ learn = load_learner('export.pkl')
7
+
8
+ dados = pd.read_csv('valid.csv')
9
+ ids = dados['user'].unique()
10
+
11
+ def top_5_predictions(user):
12
+ items = pd.Series(learn.dls.classes['title']).unique()
13
+
14
+ clas_items = dados.loc[dados['user'] == user, 'title']
15
+
16
+ no_clas_items = np.setdiff1d(items, clas_items)
17
+
18
+ df = pd.DataFrame({'user': [user]*len(no_clas_items), 'title': no_clas_items})
19
+
20
+ preds,_ = learn.get_preds(dl=learn.dls.test_dl(df))
21
+
22
+ df['prediction'] = preds.numpy()
23
+
24
+ top_5 = df.nlargest(5, 'prediction')
25
+
26
+ return top_5['title'].tolist()
27
+
28
+ iface = gr.Interface(fn=top_5_predictions, inputs=gr.inputs.Dropdown(choices=ids), outputs="text")
29
+
30
+ iface.launch()