Skip to content

Instantly share code, notes, and snippets.

@ianpaul
Created June 6, 2021 07:23
Show Gist options
  • Save ianpaul/720b9a3212287a7b65430e58ddc53dfc to your computer and use it in GitHub Desktop.
Save ianpaul/720b9a3212287a7b65430e58ddc53dfc to your computer and use it in GitHub Desktop.
Use a binary classification model on Hugging Face to determine whether a statement in English is positive or negative.
#!/bin/bash
read -p "Hello! Give me something to work with! A sentence or tweet will do. " sentence
# now let's do some curl magic
curl --fail --silent --show-error -X POST -H "Authorization: Bearer HUGGINGFACE_API_KEY" -H "Content-Type: application/json" -d '{"inputs": "'"$sentence"'"}' https://api-inference.huggingface.co/models/YOUR_USERNAME/PROJECT_URL | jq '.[0] | map(.) | if .[0].score < .[1].score then "positive" else "negative" end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment