Spaces:
Build error
Build error
vitorbborges
commited on
Commit
•
1acbc7e
1
Parent(s):
e14d889
Upload app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,56 @@
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
-
|
4 |
|
5 |
opo = pd.read_csv('oportunidades.csv')
|
6 |
simulation = pd.read_csv('simulation1.csv')
|
|
|
7 |
|
8 |
opo_n = random.randrange(len(opo))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
with gr.Blocks() as demo:
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
1 |
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))
|
24 |
+
|
25 |
+
from surprise import Dataset
|
26 |
+
data = Dataset.load_from_df(simulation[['userID', 'itemID', 'rating']], reader)
|
27 |
+
trainset = data.build_full_trainset()
|
28 |
+
|
29 |
+
from surprise import SVDpp
|
30 |
+
svdpp = SVDpp()
|
31 |
+
svdpp.fit(trainset)
|
32 |
+
|
33 |
+
items = list()
|
34 |
+
est = list()
|
35 |
+
|
36 |
+
for i in range(len(opo)):
|
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 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|