-
Notifications
You must be signed in to change notification settings - Fork 1
/
modelUpload.py
61 lines (44 loc) · 1.65 KB
/
modelUpload.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
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
import requests
import uuid
import random
import os
from pathlib import Path
from os.path import dirname, abspath
import json
title = random.choice(["Linear Regression", "Ordinal Regression"])
author = random.choice( ["Mitesh", "Ashish", "Shashi"])
idval = uuid.uuid4();# random.randrange(10, 100, 2)
import sys
def getMetrics():
obj = None;
try:
with open("metrics.json","r") as m:
obj = json.load(m)
except:
pass
return json.dumps(obj);
def getDataSetUrl():
val = None
with open("dataset.json",'r') as f:
val = json.load(f)
return val
input_datUrl = getDataSetUrl()
pythonVer = sys.version[:5]
requirementsList = open('requirements.txt').readlines()
requirements = ' '.join([req.split()[0] for req in requirementsList])
description = 'Python v'+pythonVer+' '+requirements
modelUploadBase = "https://52.165.161.123:8000/user/ashkuma/notebooks/demo/"
directory = "testmlrepo"
fileName = "/SampleModelGeneratorScriptCopy.ipynb"
filePath = modelUploadBase + directory + fileName
tags = "price prediction, prediction"
metrics = getMetrics();
payload = [('fileName','model'+str(uuid.uuid4())),('id',str(idval)),('author',author),('title',title),('description',description),('link',filePath),('tags',tags),
('trainingData',input_datUrl),('metrics',metrics)]
from urllib.parse import urlencode
params = urlencode(payload)
f = open('azdevopsdemo.pkl','rb')
MODEL_UPLOAD_URL = "https://functionappdemoazure.azurewebsites.net/api/LayoutBlobStorageTrigger"
Hit_url = MODEL_UPLOAD_URL+'?'+params
headers = {'Content-Type': 'application/json'}
requests.post(Hit_url, headers=headers, data=f.read())