File size: 2,811 Bytes
719d8e1 4c9434f 541cc21 719d8e1 541cc21 0ce4f4a 541cc21 26db684 be0847e 7c6a4b6 be0847e 541cc21 7b3c0d1 1e33f6d 719d8e1 541cc21 719d8e1 7713cdb 5ac5547 541cc21 adbb24e 4800f16 584580a e150cde 584580a b17d3a8 584580a b17d3a8 584580a b17d3a8 584580a adbb24e 541cc21 605f0dd 719d8e1 360311b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
from flask import Flask
from flask import request
from flask import render_template
from flask import redirect
from flask import jsonify
from flask import send_from_directory
import json
import numpy as np
import moduli
#from hugchat import hugchat
#from hugchat.login import Login
from numpy.linalg import norm
import datetime
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text
from functools import wraps
import os
import pickle
model_url = "./hub_model/"
hub_layer = hub.load(model_url)
app = Flask(__name__)
def support_jsonp(func):
"""Wraps JSONified output for JSONP requests."""
@wraps(func)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
resp = func(*args, **kwargs)
resp.set_data('{}({})'.format(
str(callback),
resp.get_data(as_text=True)
))
resp.mimetype = 'application/javascript'
return resp
else:
return func(*args, **kwargs)
return decorated_function
@app.route("/")
def flask_app():
return '<br>' \
'<h3><a href="http://18.102.72.47:5000" target="_blank">Hai acceso il server! Bene!😉 Adesso vai alla pagina La7 DEMO!!</a></h3>' \
@app.route('/broadcast_labels',methods=['POST','GET'])
@support_jsonp
def broadcast_labels():
#if request.method == 'GET':
s=request.args.get('S')
dati=moduli.la7_labels(s)
output=dati
response = jsonify(output)
return response
@app.route('/requestsSearch',methods=['POST','GET'])
@support_jsonp
def tasksSearch():
domanda=request.args.get('frase').strip()
s=request.args.get('S').strip()
path=s
#dati=moduli.la7_Search(s,domanda,hub_layer)
print('domanda',domanda)
dati=[]
with open ('static/dati/'+str(path)+'/db_relatori_finale_emb', 'rb') as fp:
word = pickle.load(fp)
word_orig=np.array(word)
message_embeddings = hub_layer(domanda)[0].numpy()
ris=[]
for n,w in enumerate(word):
contesto_embeddings=np.array(w[6])
cosine = np.dot(message_embeddings,contesto_embeddings)/(norm(message_embeddings)*norm(contesto_embeddings))
ris.append(cosine)
ris_sort=np.argsort(ris)[::-1]
l=0
for n in ris_sort:
if l==0:
testo=str(word[n][5])
testo_chi=str(word[n][2])+':'+str(word[n][1])
else:
testo=testo+' '+word[n][5]
testo_chi=testo_chi+' --- '+str(word[n][2])+' '+str(word[n][1])
l=len(testo)
if l>800:
break
d={}
d['text']=str(testo)
d['chi']=str(testo_chi)
dati.append(d)
output=dati
response = jsonify(output)
return response
if __name__ == "__main__":
app.run(host='0.0.0.0', port=7860) |