@huggingface/inference 3.6.0 → 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +240 -71
- package/dist/index.js +240 -60
- package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/src/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/src/providers/cerebras.d.ts.map +1 -1
- package/dist/src/providers/cohere.d.ts.map +1 -1
- package/dist/src/providers/fal-ai.d.ts +6 -16
- package/dist/src/providers/fal-ai.d.ts.map +1 -1
- package/dist/src/providers/fireworks-ai.d.ts.map +1 -1
- package/dist/src/providers/hf-inference.d.ts.map +1 -1
- package/dist/src/providers/hyperbolic.d.ts.map +1 -1
- package/dist/src/providers/nebius.d.ts.map +1 -1
- package/dist/src/providers/novita.d.ts.map +1 -1
- package/dist/src/providers/openai.d.ts.map +1 -1
- package/dist/src/providers/replicate.d.ts.map +1 -1
- package/dist/src/providers/sambanova.d.ts.map +1 -1
- package/dist/src/providers/together.d.ts.map +1 -1
- package/dist/src/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/src/snippets/templates.exported.d.ts +2 -0
- package/dist/src/snippets/templates.exported.d.ts.map +1 -0
- package/dist/src/tasks/cv/textToVideo.d.ts.map +1 -1
- package/dist/src/types.d.ts +4 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/test/InferenceClient.spec.d.ts.map +1 -1
- package/package.json +10 -15
- package/src/lib/makeRequestOptions.ts +3 -1
- package/src/providers/black-forest-labs.ts +6 -2
- package/src/providers/cerebras.ts +6 -2
- package/src/providers/cohere.ts +6 -2
- package/src/providers/fal-ai.ts +85 -3
- package/src/providers/fireworks-ai.ts +6 -2
- package/src/providers/hf-inference.ts +6 -2
- package/src/providers/hyperbolic.ts +6 -2
- package/src/providers/nebius.ts +6 -2
- package/src/providers/novita.ts +5 -2
- package/src/providers/openai.ts +6 -2
- package/src/providers/replicate.ts +6 -2
- package/src/providers/sambanova.ts +6 -2
- package/src/providers/together.ts +6 -2
- package/src/snippets/getInferenceSnippets.ts +6 -24
- package/src/snippets/templates.exported.ts +72 -0
- package/src/tasks/cv/textToVideo.ts +5 -21
- package/src/types.ts +5 -2
- package/dist/browser/index.cjs +0 -1652
- package/dist/browser/index.js +0 -1652
- package/src/snippets/templates/js/fetch/basic.jinja +0 -19
- package/src/snippets/templates/js/fetch/basicAudio.jinja +0 -19
- package/src/snippets/templates/js/fetch/basicImage.jinja +0 -19
- package/src/snippets/templates/js/fetch/textToAudio.jinja +0 -41
- package/src/snippets/templates/js/fetch/textToImage.jinja +0 -19
- package/src/snippets/templates/js/fetch/zeroShotClassification.jinja +0 -22
- package/src/snippets/templates/js/huggingface.js/basic.jinja +0 -11
- package/src/snippets/templates/js/huggingface.js/basicAudio.jinja +0 -13
- package/src/snippets/templates/js/huggingface.js/basicImage.jinja +0 -13
- package/src/snippets/templates/js/huggingface.js/conversational.jinja +0 -11
- package/src/snippets/templates/js/huggingface.js/conversationalStream.jinja +0 -19
- package/src/snippets/templates/js/huggingface.js/textToImage.jinja +0 -11
- package/src/snippets/templates/js/huggingface.js/textToVideo.jinja +0 -10
- package/src/snippets/templates/js/openai/conversational.jinja +0 -13
- package/src/snippets/templates/js/openai/conversationalStream.jinja +0 -22
- package/src/snippets/templates/python/fal_client/textToImage.jinja +0 -11
- package/src/snippets/templates/python/huggingface_hub/basic.jinja +0 -4
- package/src/snippets/templates/python/huggingface_hub/basicAudio.jinja +0 -1
- package/src/snippets/templates/python/huggingface_hub/basicImage.jinja +0 -1
- package/src/snippets/templates/python/huggingface_hub/conversational.jinja +0 -6
- package/src/snippets/templates/python/huggingface_hub/conversationalStream.jinja +0 -8
- package/src/snippets/templates/python/huggingface_hub/documentQuestionAnswering.jinja +0 -5
- package/src/snippets/templates/python/huggingface_hub/imageToImage.jinja +0 -6
- package/src/snippets/templates/python/huggingface_hub/importInferenceClient.jinja +0 -6
- package/src/snippets/templates/python/huggingface_hub/textToImage.jinja +0 -5
- package/src/snippets/templates/python/huggingface_hub/textToVideo.jinja +0 -4
- package/src/snippets/templates/python/openai/conversational.jinja +0 -13
- package/src/snippets/templates/python/openai/conversationalStream.jinja +0 -15
- package/src/snippets/templates/python/requests/basic.jinja +0 -7
- package/src/snippets/templates/python/requests/basicAudio.jinja +0 -7
- package/src/snippets/templates/python/requests/basicImage.jinja +0 -7
- package/src/snippets/templates/python/requests/conversational.jinja +0 -9
- package/src/snippets/templates/python/requests/conversationalStream.jinja +0 -16
- package/src/snippets/templates/python/requests/documentQuestionAnswering.jinja +0 -13
- package/src/snippets/templates/python/requests/imageToImage.jinja +0 -15
- package/src/snippets/templates/python/requests/importRequests.jinja +0 -10
- package/src/snippets/templates/python/requests/tabular.jinja +0 -9
- package/src/snippets/templates/python/requests/textToAudio.jinja +0 -23
- package/src/snippets/templates/python/requests/textToImage.jinja +0 -14
- package/src/snippets/templates/python/requests/zeroShotClassification.jinja +0 -8
- package/src/snippets/templates/python/requests/zeroShotImageClassification.jinja +0 -14
- package/src/snippets/templates/sh/curl/basic.jinja +0 -7
- package/src/snippets/templates/sh/curl/basicAudio.jinja +0 -5
- package/src/snippets/templates/sh/curl/basicImage.jinja +0 -5
- package/src/snippets/templates/sh/curl/conversational.jinja +0 -7
- package/src/snippets/templates/sh/curl/conversationalStream.jinja +0 -7
- package/src/snippets/templates/sh/curl/zeroShotClassification.jinja +0 -5
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
async function query(data) {
|
|
2
|
-
const response = await fetch(
|
|
3
|
-
"{{ fullUrl }}",
|
|
4
|
-
{
|
|
5
|
-
headers: {
|
|
6
|
-
Authorization: "{{ authorizationHeader }}",
|
|
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: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
18
|
-
console.log(JSON.stringify(response));
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
async function query(data) {
|
|
2
|
-
const response = await fetch(
|
|
3
|
-
"{{ fullUrl }}",
|
|
4
|
-
{
|
|
5
|
-
headers: {
|
|
6
|
-
Authorization: "{{ authorizationHeader }}",
|
|
7
|
-
"Content-Type": "audio/flac"
|
|
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: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
18
|
-
console.log(JSON.stringify(response));
|
|
19
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
async function query(data) {
|
|
2
|
-
const response = await fetch(
|
|
3
|
-
"{{ fullUrl }}",
|
|
4
|
-
{
|
|
5
|
-
headers: {
|
|
6
|
-
Authorization: "{{ authorizationHeader }}",
|
|
7
|
-
"Content-Type": "image/jpeg"
|
|
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: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
18
|
-
console.log(JSON.stringify(response));
|
|
19
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{% if model.library_name == "transformers" %}
|
|
2
|
-
async function query(data) {
|
|
3
|
-
const response = await fetch(
|
|
4
|
-
"{{ fullUrl }}",
|
|
5
|
-
{
|
|
6
|
-
headers: {
|
|
7
|
-
Authorization: "{{ authorizationHeader }}",
|
|
8
|
-
"Content-Type": "application/json",
|
|
9
|
-
},
|
|
10
|
-
method: "POST",
|
|
11
|
-
body: JSON.stringify(data),
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
const result = await response.blob();
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
query({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
19
|
-
// Returns a byte object of the Audio wavform. Use it directly!
|
|
20
|
-
});
|
|
21
|
-
{% else %}
|
|
22
|
-
async function query(data) {
|
|
23
|
-
const response = await fetch(
|
|
24
|
-
"{{ fullUrl }}",
|
|
25
|
-
{
|
|
26
|
-
headers: {
|
|
27
|
-
Authorization: "{{ authorizationHeader }}",
|
|
28
|
-
"Content-Type": "application/json",
|
|
29
|
-
},
|
|
30
|
-
method: "POST",
|
|
31
|
-
body: JSON.stringify(data),
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
const result = await response.json();
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
query({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
39
|
-
console.log(JSON.stringify(response));
|
|
40
|
-
});
|
|
41
|
-
{% endif %}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
async function query(data) {
|
|
2
|
-
const response = await fetch(
|
|
3
|
-
"{{ fullUrl }}",
|
|
4
|
-
{
|
|
5
|
-
headers: {
|
|
6
|
-
Authorization: "{{ authorizationHeader }}",
|
|
7
|
-
"Content-Type": "application/json",
|
|
8
|
-
},
|
|
9
|
-
method: "POST",
|
|
10
|
-
body: JSON.stringify(data),
|
|
11
|
-
}
|
|
12
|
-
);
|
|
13
|
-
const result = await response.blob();
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
query({ inputs: {{ providerInputs.asObj.inputs }} }).then((response) => {
|
|
18
|
-
// Use image
|
|
19
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
async function query(data) {
|
|
2
|
-
const response = await fetch(
|
|
3
|
-
"{{ fullUrl }}",
|
|
4
|
-
{
|
|
5
|
-
headers: {
|
|
6
|
-
Authorization: "{{ authorizationHeader }}",
|
|
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({
|
|
18
|
-
inputs: {{ providerInputs.asObj.inputs }},
|
|
19
|
-
parameters: { candidate_labels: ["refund", "legal", "faq"] }
|
|
20
|
-
}).then((response) => {
|
|
21
|
-
console.log(JSON.stringify(response));
|
|
22
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const output = await client.{{ methodName }}({
|
|
6
|
-
model: "{{ model.id }}",
|
|
7
|
-
inputs: {{ inputs.asObj.inputs }},
|
|
8
|
-
provider: "{{ provider }}",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
console.log(output);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const data = fs.readFileSync({{inputs.asObj.inputs}});
|
|
6
|
-
|
|
7
|
-
const output = await client.{{ methodName }}({
|
|
8
|
-
data,
|
|
9
|
-
model: "{{ model.id }}",
|
|
10
|
-
provider: "{{ provider }}",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
console.log(output);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const data = fs.readFileSync({{inputs.asObj.inputs}});
|
|
6
|
-
|
|
7
|
-
const output = await client.{{ methodName }}({
|
|
8
|
-
data,
|
|
9
|
-
model: "{{ model.id }}",
|
|
10
|
-
provider: "{{ provider }}",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
console.log(output);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const chatCompletion = await client.chatCompletion({
|
|
6
|
-
provider: "{{ provider }}",
|
|
7
|
-
model: "{{ model.id }}",
|
|
8
|
-
{{ inputs.asTsString }}
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
console.log(chatCompletion.choices[0].message);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
let out = "";
|
|
6
|
-
|
|
7
|
-
const stream = await client.chatCompletionStream({
|
|
8
|
-
provider: "{{ provider }}",
|
|
9
|
-
model: "{{ model.id }}",
|
|
10
|
-
{{ inputs.asTsString }}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
for await (const chunk of stream) {
|
|
14
|
-
if (chunk.choices && chunk.choices.length > 0) {
|
|
15
|
-
const newContent = chunk.choices[0].delta.content;
|
|
16
|
-
out += newContent;
|
|
17
|
-
console.log(newContent);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const image = await client.textToImage({
|
|
6
|
-
provider: "{{ provider }}",
|
|
7
|
-
model: "{{ model.id }}",
|
|
8
|
-
inputs: {{ inputs.asObj.inputs }},
|
|
9
|
-
parameters: { num_inference_steps: 5 },
|
|
10
|
-
});
|
|
11
|
-
/// Use the generated image (it's a Blob)
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { InferenceClient } from "@huggingface/inference";
|
|
2
|
-
|
|
3
|
-
const client = new InferenceClient("{{ accessToken }}");
|
|
4
|
-
|
|
5
|
-
const image = await client.textToVideo({
|
|
6
|
-
provider: "{{ provider }}",
|
|
7
|
-
model: "{{ model.id }}",
|
|
8
|
-
inputs: {{ inputs.asObj.inputs }},
|
|
9
|
-
});
|
|
10
|
-
// Use the generated video (it's a Blob)
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
|
|
3
|
-
const client = new OpenAI({
|
|
4
|
-
baseURL: "{{ baseUrl }}",
|
|
5
|
-
apiKey: "{{ accessToken }}",
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
const chatCompletion = await client.chat.completions.create({
|
|
9
|
-
model: "{{ providerModelId }}",
|
|
10
|
-
{{ inputs.asTsString }}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
console.log(chatCompletion.choices[0].message);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
|
|
3
|
-
const client = new OpenAI({
|
|
4
|
-
baseURL: "{{ baseUrl }}",
|
|
5
|
-
apiKey: "{{ accessToken }}",
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
let out = "";
|
|
9
|
-
|
|
10
|
-
const stream = await client.chat.completions.create({
|
|
11
|
-
provider: "{{ provider }}",
|
|
12
|
-
model: "{{ model.id }}",
|
|
13
|
-
{{ inputs.asTsString }}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
for await (const chunk of stream) {
|
|
17
|
-
if (chunk.choices && chunk.choices.length > 0) {
|
|
18
|
-
const newContent = chunk.choices[0].delta.content;
|
|
19
|
-
out += newContent;
|
|
20
|
-
console.log(newContent);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model="{{ model.id }}")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
output = client.{{ methodName }}({{ inputs.asObj.inputs }}, model="{{ model.id }}")
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from openai import OpenAI
|
|
2
|
-
|
|
3
|
-
client = OpenAI(
|
|
4
|
-
base_url="{{ baseUrl }}",
|
|
5
|
-
api_key="{{ accessToken }}"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
completion = client.chat.completions.create(
|
|
9
|
-
model="{{ providerModelId }}",
|
|
10
|
-
{{ inputs.asPythonString }}
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
print(completion.choices[0].message)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from openai import OpenAI
|
|
2
|
-
|
|
3
|
-
client = OpenAI(
|
|
4
|
-
base_url="{{ baseUrl }}",
|
|
5
|
-
api_key="{{ accessToken }}"
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
stream = client.chat.completions.create(
|
|
9
|
-
model="{{ providerModelId }}",
|
|
10
|
-
{{ inputs.asPythonString }}
|
|
11
|
-
stream=True,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
for chunk in stream:
|
|
15
|
-
print(chunk.choices[0].delta.content, end="")
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
def query(payload):
|
|
2
|
-
response = requests.post(API_URL, headers=headers, json=payload, stream=True)
|
|
3
|
-
for line in response.iter_lines():
|
|
4
|
-
if not line.startswith(b"data:"):
|
|
5
|
-
continue
|
|
6
|
-
if line.strip() == b"data: [DONE]":
|
|
7
|
-
return
|
|
8
|
-
yield json.loads(line.decode("utf-8").lstrip("data:").rstrip("/n"))
|
|
9
|
-
|
|
10
|
-
chunks = query({
|
|
11
|
-
{{ providerInputs.asJsonString }},
|
|
12
|
-
"stream": True,
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
for chunk in chunks:
|
|
16
|
-
print(chunk["choices"][0]["delta"]["content"], end="")
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
def query(payload):
|
|
2
|
-
with open(payload["image"], "rb") as f:
|
|
3
|
-
img = f.read()
|
|
4
|
-
payload["image"] = base64.b64encode(img).decode("utf-8")
|
|
5
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6
|
-
return response.json()
|
|
7
|
-
|
|
8
|
-
output = query({
|
|
9
|
-
"inputs": {
|
|
10
|
-
"image": "{{ inputs.asObj.image }}",
|
|
11
|
-
"question": "{{ inputs.asObj.question }}",
|
|
12
|
-
},
|
|
13
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
def query(payload):
|
|
2
|
-
with open(payload["inputs"], "rb") as f:
|
|
3
|
-
img = f.read()
|
|
4
|
-
payload["inputs"] = base64.b64encode(img).decode("utf-8")
|
|
5
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
6
|
-
return response.content
|
|
7
|
-
|
|
8
|
-
image_bytes = query({
|
|
9
|
-
{{ providerInputs.asJsonString }}
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
# You can access the image with PIL.Image for example
|
|
13
|
-
import io
|
|
14
|
-
from PIL import Image
|
|
15
|
-
image = Image.open(io.BytesIO(image_bytes))
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{% if model.library_name == "transformers" %}
|
|
2
|
-
def query(payload):
|
|
3
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
4
|
-
return response.content
|
|
5
|
-
|
|
6
|
-
audio_bytes = query({
|
|
7
|
-
"inputs": {{ providerInputs.asObj.inputs }},
|
|
8
|
-
})
|
|
9
|
-
# You can access the audio with IPython.display for example
|
|
10
|
-
from IPython.display import Audio
|
|
11
|
-
Audio(audio_bytes)
|
|
12
|
-
{% else %}
|
|
13
|
-
def query(payload):
|
|
14
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
15
|
-
return response.json()
|
|
16
|
-
|
|
17
|
-
audio, sampling_rate = query({
|
|
18
|
-
"inputs": {{ providerInputs.asObj.inputs }},
|
|
19
|
-
})
|
|
20
|
-
# You can access the audio with IPython.display for example
|
|
21
|
-
from IPython.display import Audio
|
|
22
|
-
Audio(audio, rate=sampling_rate)
|
|
23
|
-
{% endif %}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{% if provider == "hf-inference" %}
|
|
2
|
-
def query(payload):
|
|
3
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
4
|
-
return response.content
|
|
5
|
-
|
|
6
|
-
image_bytes = query({
|
|
7
|
-
"inputs": {{ providerInputs.asObj.inputs }},
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
# You can access the image with PIL.Image for example
|
|
11
|
-
import io
|
|
12
|
-
from PIL import Image
|
|
13
|
-
image = Image.open(io.BytesIO(image_bytes))
|
|
14
|
-
{% endif %}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
def query(data):
|
|
2
|
-
with open(data["image_path"], "rb") as f:
|
|
3
|
-
img = f.read()
|
|
4
|
-
payload={
|
|
5
|
-
"parameters": data["parameters"],
|
|
6
|
-
"inputs": base64.b64encode(img).decode("utf-8")
|
|
7
|
-
}
|
|
8
|
-
response = requests.post(API_URL, headers=headers, json=payload)
|
|
9
|
-
return response.json()
|
|
10
|
-
|
|
11
|
-
output = query({
|
|
12
|
-
"image_path": {{ providerInputs.asObj.inputs }},
|
|
13
|
-
"parameters": {"candidate_labels": ["cat", "dog", "llama"]},
|
|
14
|
-
})
|