Update README.md
Browse files
README.md
CHANGED
@@ -239,8 +239,7 @@ To train the Latent Dirichlet allocation (LDA) model, it was used a database of
|
|
239 |
|
240 |
## Checkpoints
|
241 |
|
242 |
-
-
|
243 |
-
|
244 |
```python
|
245 |
|
246 |
data=Data()
|
@@ -355,6 +354,104 @@ ranking = model_table('lda_rankings')
|
|
355 |
sys.stdout = sys.__stdout__ # Codigo para reativar os prints
|
356 |
|
357 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
## Benchmarks
|
359 |
|
360 |
```python
|
|
|
239 |
|
240 |
## Checkpoints
|
241 |
|
242 |
+
- Example
|
|
|
243 |
```python
|
244 |
|
245 |
data=Data()
|
|
|
354 |
sys.stdout = sys.__stdout__ # Codigo para reativar os prints
|
355 |
|
356 |
```
|
357 |
+
|
358 |
+
- Usage Example
|
359 |
+
|
360 |
+
In this section it will be explained how the recommendation is made for the user
|
361 |
+
```python
|
362 |
+
|
363 |
+
import gradio as gr
|
364 |
+
import random
|
365 |
+
import pandas as pd
|
366 |
+
|
367 |
+
opo = pd.read_csv('oportunidades_results.csv', lineterminator='\n')
|
368 |
+
# opo = opo.iloc[np.where(opo['opo_brazil']=='Y')]
|
369 |
+
simulation = pd.read_csv('simulation2.csv')
|
370 |
+
userID = max(simulation['userID']) + 1
|
371 |
+
|
372 |
+
def build_display_text(opo_n):
|
373 |
+
|
374 |
+
title = opo.loc[opo_n]['opo_titulo']
|
375 |
+
link = opo.loc[opo_n]['link']
|
376 |
+
summary = opo.loc[opo_n]['facebook-bart-large-cnn_results']
|
377 |
+
|
378 |
+
display_text = f"**{title}**\n\nURL:\n{link}\n\nSUMMARY:\n{summary}"
|
379 |
+
|
380 |
+
return display_text
|
381 |
+
|
382 |
+
opo_n_one = random.randrange(len(opo))
|
383 |
+
opo_n_two = random.randrange(len(opo))
|
384 |
+
opo_n_three = random.randrange(len(opo))
|
385 |
+
opo_n_four = random.randrange(len(opo))
|
386 |
+
|
387 |
+
evaluated = []
|
388 |
+
|
389 |
+
def predict_next(option, nota):
|
390 |
+
global userID
|
391 |
+
global opo_n_one
|
392 |
+
global opo_n_two
|
393 |
+
global opo_n_three
|
394 |
+
global opo_n_four
|
395 |
+
global evaluated
|
396 |
+
global opo
|
397 |
+
global simulation
|
398 |
+
|
399 |
+
selected = [opo_n_one, opo_n_two, opo_n_three, opo_n_four][int(option)-1]
|
400 |
+
|
401 |
+
simulation = simulation.append({'userID': userID, 'itemID': selected, 'rating': nota}, ignore_index=True)
|
402 |
+
evaluated.append(selected)
|
403 |
+
|
404 |
+
from surprise import Reader
|
405 |
+
reader = Reader(rating_scale=(1, 5))
|
406 |
+
|
407 |
+
from surprise import Dataset
|
408 |
+
data = Dataset.load_from_df(simulation[['userID', 'itemID', 'rating']], reader)
|
409 |
+
trainset = data.build_full_trainset()
|
410 |
+
|
411 |
+
from surprise import SVDpp
|
412 |
+
svdpp = SVDpp()
|
413 |
+
svdpp.fit(trainset)
|
414 |
+
|
415 |
+
items = list()
|
416 |
+
est = list()
|
417 |
+
|
418 |
+
for i in range(len(opo)):
|
419 |
+
if i not in evaluated:
|
420 |
+
items.append(i)
|
421 |
+
est.append(svdpp.predict(userID, i).est)
|
422 |
+
|
423 |
+
opo_n_one = items[est.index(sorted(est)[-1])]
|
424 |
+
opo_n_two = items[est.index(sorted(est)[-2])]
|
425 |
+
opo_n_three = items[est.index(sorted(est)[-3])]
|
426 |
+
opo_n_four = items[est.index(sorted(est)[-4])]
|
427 |
+
|
428 |
+
return build_display_text(opo_n_one), build_display_text(opo_n_two), build_display_text(opo_n_three), build_display_text(opo_n_four)
|
429 |
+
|
430 |
+
|
431 |
+
with gr.Blocks() as demo:
|
432 |
+
with gr.Row():
|
433 |
+
one_opo = gr.Textbox(build_display_text(opo_n_one), label='Oportunidade 1')
|
434 |
+
two_opo = gr.Textbox(build_display_text(opo_n_two), label='Oportunidade 2')
|
435 |
+
|
436 |
+
with gr.Row():
|
437 |
+
three_opo = gr.Textbox(build_display_text(opo_n_three), label='Oportunidade 3')
|
438 |
+
four_opo = gr.Textbox(build_display_text(opo_n_four), label='Oportunidade 4')
|
439 |
+
|
440 |
+
with gr.Row():
|
441 |
+
option = gr.Radio(['1', '2', '3', '4'], label='Opção', value = '1')
|
442 |
+
|
443 |
+
with gr.Row():
|
444 |
+
nota = gr.Slider(1,5,step=1,label="Nota 1")
|
445 |
+
|
446 |
+
with gr.Row():
|
447 |
+
confirm = gr.Button("Confirmar")
|
448 |
+
|
449 |
+
confirm.click(fn=predict_next,
|
450 |
+
inputs=[option, nota],
|
451 |
+
outputs=[one_opo, two_opo, three_opo, four_opo])
|
452 |
+
|
453 |
+
if __name__ == "__main__":
|
454 |
+
demo.launch()
|
455 |
## Benchmarks
|
456 |
|
457 |
```python
|