Skip to content

Commit 281ce27

Browse files
committed
text-classification
1 parent c489845 commit 281ce27

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl https://router.huggingface.co/hf-inference/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english \
2+
-X POST \
3+
-d '{"inputs": "I like you. I love you"}' \
4+
-H 'Content-Type: application/json' \
5+
-H 'Authorization: Bearer api_token'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { InferenceClient } from "@huggingface/inference";
2+
3+
const client = new InferenceClient("api_token");
4+
5+
const output = await client.textClassification({
6+
model: "distilbert/distilbert-base-uncased-finetuned-sst-2-english",
7+
inputs: "I like you. I love you",
8+
provider: "hf-inference",
9+
});
10+
11+
console.log(output);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from huggingface_hub import InferenceClient
2+
3+
client = InferenceClient(
4+
provider="hf-inference",
5+
api_key="api_token",
6+
)
7+
8+
result = client.text_classification(
9+
inputs="I like you. I love you",
10+
model="distilbert/distilbert-base-uncased-finetuned-sst-2-english",
11+
)
12+
13+
print(result)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
async function query(data) {
2+
const response = await fetch(
3+
"https://router.huggingface.co/hf-inference/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english",
4+
{
5+
headers: {
6+
Authorization: "Bearer api_token",
7+
"Content-Type": "application/json",
8+
},
9+
method: "POST",
10+
body: JSON.stringify(data),
11+
}
12+
);
13+
const result = await response.json();
14+
return result;
15+
}
16+
17+
query({"inputs": "I like you. I love you"}).then((response) => {
18+
console.log(JSON.stringify(response));
19+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import requests
2+
3+
API_URL = "https://router.huggingface.co/hf-inference/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english"
4+
headers = {"Authorization": "Bearer api_token"}
5+
6+
def query(payload):
7+
response = requests.post(API_URL, headers=headers, json=payload)
8+
return response.json()
9+
10+
output = query({
11+
"inputs": "I like you. I love you",
12+
})

0 commit comments

Comments
 (0)