vitorbborges commited on
Commit
4ca8af8
1 Parent(s): 731dfa2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -20
app.py CHANGED
@@ -2,22 +2,41 @@ import gradio as gr
2
  import random
3
  import pandas as pd
4
 
5
- opo = pd.read_csv('oportunidades.csv')
6
- simulation = pd.read_csv('simulation1.csv')
7
  userID = max(simulation['userID']) + 1
8
 
9
- opo_n = random.randrange(len(opo))
10
- evaluated = [opo_n]
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- def predict_next(inp):
 
 
13
  global userID
14
- global opo_n
 
 
 
15
  global evaluated
16
  global opo
17
  global simulation
18
 
19
- simulation = simulation.append({'userID': userID, 'itemID': opo_n, 'rating': inp}, ignore_index=True)
20
- evaluated.append(opo_n)
 
 
21
 
22
  from surprise import Reader
23
  reader = Reader(rating_scale=(1, 5))
@@ -37,19 +56,36 @@ def predict_next(inp):
37
  if i not in evaluated:
38
  items.append(i)
39
  est.append(svdpp.predict(userID, i).est)
40
-
41
- opo_n = items[est.index(max(est))]
42
- return opo.loc[opo_n]['opo_texto']
 
 
 
 
 
43
 
44
  with gr.Blocks() as demo:
45
- gr.Markdown("# MCTI Recommender System")
46
-
47
- current_opo = gr.Textbox(opo.loc[opo_n]['opo_texto'], label='Oportunidade')
48
- nota = gr.Slider(1,5,step=1,label="Nota")
49
- confirm = gr.Button("Confirmar")
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- confirm.click(fn=predict_next,
52
- inputs=nota,
53
- outputs=current_opo)
54
 
55
- demo.launch()
 
 
2
  import random
3
  import pandas as pd
4
 
5
+ opo = pd.read_csv('oportunidades_results.csv', lineterminator='\n')
6
+ simulation = pd.read_csv('simulation2.csv')
7
  userID = max(simulation['userID']) + 1
8
 
9
+ def build_display_text(opo_n):
10
+
11
+ title = opo.loc[opo_n]['opo_titulo']
12
+ link = opo.loc[opo_n]['link']
13
+ summary = opo.loc[opo_n]['facebook-bart-large-cnn_results']
14
+
15
+ display_text = f"**{title}**\n\nURL:\n{link}\n\nSUMMARY:\n{summary}"
16
+
17
+ return display_text
18
+
19
+ opo_n_one = random.randrange(len(opo))
20
+ opo_n_two = random.randrange(len(opo))
21
+ opo_n_three = random.randrange(len(opo))
22
+ opo_n_four = random.randrange(len(opo))
23
 
24
+ evaluated = []
25
+
26
+ def predict_next(option, nota):
27
  global userID
28
+ global opo_n_one
29
+ global opo_n_two
30
+ global opo_n_three
31
+ global opo_n_four
32
  global evaluated
33
  global opo
34
  global simulation
35
 
36
+ selected = [opo_n_one, opo_n_two, opo_n_three, opo_n_four][int(option)-1]
37
+
38
+ simulation = simulation.append({'userID': userID, 'itemID': selected, 'rating': nota}, ignore_index=True)
39
+ evaluated.append(selected)
40
 
41
  from surprise import Reader
42
  reader = Reader(rating_scale=(1, 5))
 
56
  if i not in evaluated:
57
  items.append(i)
58
  est.append(svdpp.predict(userID, i).est)
59
+
60
+ opo_n_one = items[est.index(sorted(est)[-1])]
61
+ opo_n_two = items[est.index(sorted(est)[-2])]
62
+ opo_n_three = items[est.index(sorted(est)[-3])]
63
+ opo_n_four = items[est.index(sorted(est)[-4])]
64
+
65
+ 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)
66
+
67
 
68
  with gr.Blocks() as demo:
69
+ with gr.Row():
70
+ one_opo = gr.Textbox(build_display_text(opo_n_one), label='Oportunidade 1')
71
+ two_opo = gr.Textbox(build_display_text(opo_n_two), label='Oportunidade 2')
72
+
73
+ with gr.Row():
74
+ three_opo = gr.Textbox(build_display_text(opo_n_three), label='Oportunidade 3')
75
+ four_opo = gr.Textbox(build_display_text(opo_n_four), label='Oportunidade 4')
76
+
77
+ with gr.Row():
78
+ option = gr.Radio(['1', '2', '3', '4'], label='Opção', value = '1')
79
+
80
+ with gr.Row():
81
+ nota = gr.Slider(1,5,step=1,label="Nota 1")
82
+
83
+ with gr.Row():
84
+ confirm = gr.Button("Confirmar")
85
 
86
+ confirm.click(fn=predict_next,
87
+ inputs=[option, nota],
88
+ outputs=[one_opo, two_opo, three_opo, four_opo])
89
 
90
+ if __name__ == "__main__":
91
+ demo.launch()