Skip to content

Instantly share code, notes, and snippets.

@sophwats
Created November 24, 2020 15:28
Show Gist options
  • Save sophwats/4e30b065cc39aa6555a88599274664c2 to your computer and use it in GitHub Desktop.
Save sophwats/4e30b065cc39aa6555a88599274664c2 to your computer and use it in GitHub Desktop.
interact with model service
DEFAULT_BASE_URL = "http://seldon-deployment-example-sklearn-iris-predictor-ml-mon.apps.cluster-d038.d038.example.opentlc.com%s"
import requests
from urllib.parse import urlencode
import json
def score_text(text, url = None):
url = (url or (DEFAULT_BASE_URL % "/api/v1.0/predictions"))
print(url)
payload = '{"data": {"ndarray":[[5.964,4.006,2.081,1.031]]}}'
print(payload)
headers = {'content-type': 'application/json'}
response = requests.request("POST", url, data=payload, headers=headers)
print(payload)
print(response)
return json.loads(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment