-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get_Request_REST_API.py
31 lines (27 loc) · 1006 Bytes
/
Get_Request_REST_API.py
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
import requests
def Get_Embeddings_Sentences_API(textoflink):
listofsentences_embeddings = []
try:
session = requests.Session()
session.headers.update(
{'Authorization': 'Token ?'})
resultAPi = session.post('http://127.0.0.1:9000/v1/beta/api/embeddings_sentences/',
data={'text': textoflink})
print(resultAPi.content)
if resultAPi.status_code == 200:
listofsentences_embeddings = resultAPi.json()
else:
listofsentences_embeddings = {'error':'Status code is: '+str(resultAPi.status_code)}
except Exception as e:
print(str(e))
pass
return listofsentences_embeddings
listres = Get_Embeddings_Sentences_API("amin is good boy.")
print(listres)
# if 'error' not in listres:
# for key in listres['Embeddings']:
# for i in key.items():
# print("sentence :",i[0])
# print("embbedding :", i[1])
# else:
# print(listres)