ScienceOps | ScienceBox

Hello World


All of these examples assume you have access to a Yhat instance (either through the public sandbox or enterprise) and a Yhat username and apikey.

To signup for the sandbox version of ScienceOps, go here

You'll also need to have the Yhat client library installed $ pip install -U yhat.

Deploying Your First Model

from yhat import Yhat, YhatModel , preprocess

class HelloWorld(YhatModel):
    @preprocess(in_type=dict, out_type=dict)
    def execute(self, data):
        me = data['name']
        greeting = "Hello " + str(me) + "!"
        return { "greeting": greeting }

yh = Yhat("YOUR_USERNAME", "YOUR_APIKEY", "http://cloud.yhathq.com/")
yh.deploy  ("HelloWorld", HelloWorld, globals())

Great! You just deployed your first model. Now let's actually use it.

Calling Your First Model

This is your connection to the ŷhat server.

yh = Yhat("YOUR_USERNAME", "YOUR_APIKEY", "http://cloud.yhathq.com/")
yh.predict ("HelloWorld", {"name": "Hank"})

Calling from curl

$ curl -X POST --user YOUR_USERNAME:YOUR_APIKEY \
    -H "Content-Type: application/json" \
    --data '{"name": "Hank"}' \
    http://cloud.yhathq.com/YOUR_USERNAME/models/HelloWorld/