Created
December 10, 2019 18:56
-
-
Save aballah-chamakh/9693222617245279202cbba0a150e2b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
# endpoints | |
base_end_point = 'http://127.0.0.1/api/' | |
token_end_point = base_end_point+'token' | |
sa_endpoint = base_end_point+'/make_sa_inference' | |
# credentials | |
username = 'ElonMusk' | |
password = 'ilovenasa' | |
# Authentication | |
credential = {'username':username, | |
'password':password} | |
headers = {'Content-Type':'application/json'} | |
r1 = requests.post(token_end_point,data=json.dumps(credential),headers=headers) | |
token = r1.json()['access'] | |
headers['Authorization'] = 'Bearer '+token | |
# Analyse some text | |
text_to_analyze = 'I love blogging' | |
json_data = json.dumps({'text':text_to_analyze}) | |
r2 = requests.post(sa_endpoint,data=json_data,headers=headers) | |
result = r2.json()['result'] | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment