Using Saagie Hugging Face Model Server Via API

You can use Saagie Hugging Face Model Server directly in your code to deploy and predict Hugging Face deep learning models for text classification using our API.

Before you begin:
  1. Create the Saagie HF ModelServer TextCLF app in your project by clicking Install an app from your project’s The Apps page icon is a PC screen with a star in the middle. Apps page.
    Your app appears in the project’s app library.

  2. Create the $SHF_API project environment variable. Its value must be the URL of the Saagie model deployer, http://app-<YOUR_APP_ID>:8080. Where the value for <YOUR_APP_ID> can be found in the URL of your app page (a)

    add on hugging face app id

    You can use the breadcrumb trail to navigate more easily. From your app, go back one menu level and click settings env vars a Environment variables  Create project variable.

  3. Create a new job in Bash, for example, and make a curl query to deploy and predict your text. Your code must include the environment variable created earlier.

    Example 1. Curl query to deploy and predict a text
    MODEL='j-hartmann/emotion-english-distilroberta-base:main'
    LABEL='anger|disgust|fear|joy|neutral|sadness|surprise'
    curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d\'{"model_dir":"'$MODEL'", "label":"'$LABEL'"}' $SHF_API"/deploy"
    curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d\'{"inputs":["Good Movie, best of the year", "Highly recommended","very bad", "worst movie"]}' $SHF_API"/predict"

    The expected result must be as follows:

    {"response":"j-hartmann/emotion-english-distilroberta-base:main is deployed."}
    
    [{"label":"joy","score":0.89230877161026},
    {"label":"neutral","score":0.8408186435699463},
    {"label":"disgust","score":0.6104941368103027},
    {"label":"disgust","score":0.9444230198860168}]
    You can adapt the code for use with other Saagie technologies.