First endpoint
-
Write the handler. Warmup runs once when the worker starts. The handler runs once per request.
import surframodel = None@surfra.warmupdef load():global modelmodel = load_model()@surfra.handlerdef predict(request: surfra.Request):prompt = request.input["prompt"]surfra.progress(0.2, "generating")return {"text": model.generate(prompt)} -
Build an image that includes this file and the SDK. The container command is the Surfra worker.
CMD ["python", "-m", "surfra.worker"]Set
SURFRA_ENTRYPOINTto the path of the handler file. The autoscaler sets that variable, along with the replica token, when it starts the container. -
Publish the app. The name is the stable id. Deploying the same name again updates it.
import surfraapp = surfra.App("hello-model")app.deploy(image="ghcr.io/example/hello-model:latest",entrypoint="python -m surfra.worker",autoscale={"min_replicas": 0,"max_replicas": 1,"gpu": "rtx4090","providers": [{"provider": "runpod", "gpu": "rtx4090", "priority": 1, "num_workers": 1},],},)
request.input is the JSON object the caller sent. Return a JSON-serializable value. surfra.progress(fraction, message) reports a fraction from 0 to 1 while the handler is running.
