Spaces:
Build error
Build error
Commit
·
4ca8af8
1
Parent(s):
731dfa2
Upload app.py
Browse files
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('
|
6 |
-
simulation = pd.read_csv('
|
7 |
userID = max(simulation['userID']) + 1
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
13 |
global userID
|
14 |
-
global
|
|
|
|
|
|
|
15 |
global evaluated
|
16 |
global opo
|
17 |
global simulation
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
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 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
-
inputs=nota,
|
53 |
-
outputs=
|
54 |
|
55 |
-
|
|
|
|
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()
|