In [ ]:
#imports
import requests
import json

#API Endpoint 
url = 'http://api.alpes.ai/snn/'
TOKEN = 'Token 512f7ac837da42b97f613d789819ff93537bee6b'
In [ ]:
# Train upload
api_method = 'dataupload'
files = {'file': (open('../data/train.csv', 'rb').read())}
params = {'file_type': 'csv'}
headers = {'authorization': TOKEN}
r = requests.post(url+api_method,files=files,headers=headers,params=params)
train_file_upload = json.loads(r.text)
print "Uploaded train file name:", train_file_upload
In [ ]:
# Train
api_method = 'train'
headers = {'authorization': TOKEN}
params = {
            'uplodedfileid': train_file_upload['filename'],
            'no_of_initial_planes':3,
            'min_trainpoints_to_be_covered':0.98,
            'epoch':1
        }
r = requests.post(url+api_method,params=params,headers=headers)
training_task =  json.loads(r.text)
print "Train status id:", training_task
In [ ]:
# Train Status
import ast

api_method = 'job_status/'
api_endpoint = url +api_method+training_task['job_id']

job_info = requests.get(api_endpoint)
response = json.loads(job_info.text)
train_model = ast.literal_eval(response['result'])['model']

print "Training status:", response
print "trained model name:", train_model
In [ ]:
# Test upload
api_method = 'dataupload'

files = {'file': (open('../data/test.csv', 'rb').read())}
params = {'file_type': 'csv'}
headers = {'authorization': TOKEN}

r = requests.post(url+api_method,files=files,headers=headers,params=params)
test_file = json.loads(r.text)
print "Uploaded test file name:", test_file
In [ ]:
# Test

api_method = 'test'
headers = {'authorization': TOKEN}
params = {'uplodedfileid': test_file['filename'],'model':train_model,'kvalue': 3,'nbest': 0.1}
r = requests.post(url+api_method,params=params,headers=headers)
testing_task = json.loads(r.text)
print "Testing status id:", testing_task
In [ ]:
# Test Status

api_method = 'job_status/'
api_endpoint = url +api_method+testing_task['job_id']

job_info = requests.get(api_endpoint)
response = json.loads(job_info.text)
print "Testing status:", response
In [ ]:
# Predict
api_method = 'predict'
headers = {'authorization': TOKEN}
params = {'model':train_model,'kvalue': 3,'nbest': 0.1}
data = {'test_features':'16.2,6.9,9.3,379,91,105,60,7.1,3.6,3.5,1'}
r = requests.post(url+api_method,params=params,json=data,headers=headers)
print "Predicted label:", json.loads(r.text)
In [ ]:
# Predict Closest
api_method = 'predictclosest'
headers = {'authorization': TOKEN}
params = {'model':train_model,'kvalue': 3,'nbest': 0.1}
data = {'test_features':'16.2,6.9,9.3,379,91,105,60,7.1,3.6,3.5,1'}
r = requests.post(url+api_method,params=params,json=data,headers=headers)
print "Predicted label:", json.loads(r.text)
In [ ]:
# File upload for incremental train

api_method = 'dataupload'
files = {'file': (open('../data/incremental_train.csv', 'rb').read())}
params = {'file_type': 'csv'}
headers = {'authorization': TOKEN}
r = requests.post(url+api_method,files=files,headers=headers,params=params)
incr_train_file = json.loads(r.text)
print "Incremental train file name:", incr_train_file
In [ ]:
# Incremental Train

api_method = 'inctrain'
headers = {'authorization': TOKEN}
params = {'uplodedfileid': incr_train_file['filename'], 'model': train_model,'min_trainpoints_to_be_covered':0.9}
r = requests.post(url+api_method,params=params,headers=headers)
inc_training_task  = json.loads(r.text)
print "Incremental train status id:", inc_training_task
In [ ]:
# Incremental train status

api_method = 'job_status/'
api_endpoint = url +api_method+inc_training_task['job_id']

job_info = requests.get(api_endpoint)
response = json.loads(job_info.text)
print "Testing status:", response