Update app.py
Browse files
app.py
CHANGED
@@ -61,10 +61,42 @@ def broadcast_labels():
|
|
61 |
def tasksSearch():
|
62 |
domanda=request.args.get('frase').strip()
|
63 |
s=request.args.get('S').strip()
|
64 |
-
dati=
|
65 |
output=dati
|
66 |
response = jsonify(output)
|
67 |
return response
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
if __name__ == "__main__":
|
70 |
app.run(host='0.0.0.0', port=7860)
|
|
|
61 |
def tasksSearch():
|
62 |
domanda=request.args.get('frase').strip()
|
63 |
s=request.args.get('S').strip()
|
64 |
+
dati=la7_Search(s,domanda,hub_layer)
|
65 |
output=dati
|
66 |
response = jsonify(output)
|
67 |
return response
|
68 |
+
|
69 |
+
def la7_Search(path,domanda,hub_layer):
|
70 |
+
dati=[]
|
71 |
+
with open ('static/dati/'+str(path)+'/db_relatori_finale_emb', 'rb') as fp:
|
72 |
+
word = pickle.load(fp)
|
73 |
+
word_orig=np.array(word)
|
74 |
+
message_embeddings = hub_layer(domanda)[0].numpy()
|
75 |
+
ris=[]
|
76 |
+
for n,w in enumerate(word):
|
77 |
+
contesto_embeddings=np.array(w[6])
|
78 |
+
cosine = np.dot(message_embeddings,contesto_embeddings)/(norm(message_embeddings)*norm(contesto_embeddings))
|
79 |
+
ris.append(cosine)
|
80 |
+
ris_sort=np.argsort(ris)[::-1]
|
81 |
+
l=0
|
82 |
+
for n in ris_sort:
|
83 |
+
if l==0:
|
84 |
+
testo=str(word[n][5])
|
85 |
+
testo_chi=str(word[n][2])+':'+str(word[n][1])
|
86 |
+
else:
|
87 |
+
testo=testo+' '+word[n][5]
|
88 |
+
testo_chi=testo_chi+' --- '+str(word[n][2])+' '+str(word[n][1])
|
89 |
+
l=len(testo)
|
90 |
+
if l>800:
|
91 |
+
break
|
92 |
+
|
93 |
+
d={}
|
94 |
+
d['text']=str(testo)
|
95 |
+
d['chi']=str(testo_chi)
|
96 |
+
dati.append(d)
|
97 |
+
return dati
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
if __name__ == "__main__":
|
102 |
app.run(host='0.0.0.0', port=7860)
|