Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
•
767bfd8
1
Parent(s):
54baff5
Sync widgets demo
Browse files
packages/tasks/src/snippets/inputs.ts
CHANGED
@@ -79,6 +79,8 @@ const inputsTextToAudio = () => `"liquid drum and bass, atmospheric synths, airy
|
|
79 |
|
80 |
const inputsAutomaticSpeechRecognition = () => `"sample1.flac"`;
|
81 |
|
|
|
|
|
82 |
const modelInputSnippets: {
|
83 |
[key in PipelineType]?: (model: ModelData) => string;
|
84 |
} = {
|
@@ -105,6 +107,7 @@ const modelInputSnippets: {
|
|
105 |
"token-classification": inputsTokenClassification,
|
106 |
translation: inputsTranslation,
|
107 |
"zero-shot-classification": inputsZeroShotClassification,
|
|
|
108 |
};
|
109 |
|
110 |
// Use noWrap to put the whole snippet on a single line (removing new lines and tabulations)
|
|
|
79 |
|
80 |
const inputsAutomaticSpeechRecognition = () => `"sample1.flac"`;
|
81 |
|
82 |
+
const inputsZeroShotImageClassification = () => `"cats.jpg"`;
|
83 |
+
|
84 |
const modelInputSnippets: {
|
85 |
[key in PipelineType]?: (model: ModelData) => string;
|
86 |
} = {
|
|
|
107 |
"token-classification": inputsTokenClassification,
|
108 |
translation: inputsTranslation,
|
109 |
"zero-shot-classification": inputsZeroShotClassification,
|
110 |
+
"zero-shot-image-classification": inputsZeroShotImageClassification,
|
111 |
};
|
112 |
|
113 |
// Use noWrap to put the whole snippet on a single line (removing new lines and tabulations)
|
packages/tasks/src/snippets/python.ts
CHANGED
@@ -12,6 +12,22 @@ output = query({
|
|
12 |
"parameters": {"candidate_labels": ["refund", "legal", "faq"]},
|
13 |
})`;
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
export const snippetBasic = (model: ModelData): string =>
|
16 |
`def query(payload):
|
17 |
response = requests.post(API_URL, headers=headers, json=payload)
|
@@ -71,7 +87,7 @@ Audio(audio, rate=sampling_rate)`;
|
|
71 |
}
|
72 |
};
|
73 |
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = {
|
74 |
-
// Same order as in
|
75 |
"text-classification": snippetBasic,
|
76 |
"token-classification": snippetBasic,
|
77 |
"table-question-answering": snippetBasic,
|
@@ -92,9 +108,10 @@ export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) =>
|
|
92 |
"audio-to-audio": snippetFile,
|
93 |
"audio-classification": snippetFile,
|
94 |
"image-classification": snippetFile,
|
95 |
-
"image-to-text": snippetFile,
|
96 |
"object-detection": snippetFile,
|
97 |
"image-segmentation": snippetFile,
|
|
|
|
|
98 |
};
|
99 |
|
100 |
export function getPythonInferenceSnippet(model: ModelData, accessToken: string): string {
|
|
|
12 |
"parameters": {"candidate_labels": ["refund", "legal", "faq"]},
|
13 |
})`;
|
14 |
|
15 |
+
export const snippetZeroShotImageClassification = (model: ModelData): string =>
|
16 |
+
`def query(data):
|
17 |
+
with open(data["image_path"], "rb") as f:
|
18 |
+
img = f.read()
|
19 |
+
payload={
|
20 |
+
"parameters": data["parameters"],
|
21 |
+
"inputs": base64.b64encode(img).decode("utf-8")
|
22 |
+
}
|
23 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
24 |
+
return response.json()
|
25 |
+
|
26 |
+
output = query({
|
27 |
+
"image_path": ${getModelInputSnippet(model)},
|
28 |
+
"parameters": {"candidate_labels": ["cat", "dog", "llama"]},
|
29 |
+
})`;
|
30 |
+
|
31 |
export const snippetBasic = (model: ModelData): string =>
|
32 |
`def query(payload):
|
33 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
87 |
}
|
88 |
};
|
89 |
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = {
|
90 |
+
// Same order as in tasks/src/pipelines.ts
|
91 |
"text-classification": snippetBasic,
|
92 |
"token-classification": snippetBasic,
|
93 |
"table-question-answering": snippetBasic,
|
|
|
108 |
"audio-to-audio": snippetFile,
|
109 |
"audio-classification": snippetFile,
|
110 |
"image-classification": snippetFile,
|
|
|
111 |
"object-detection": snippetFile,
|
112 |
"image-segmentation": snippetFile,
|
113 |
+
"image-to-text": snippetFile,
|
114 |
+
"zero-shot-image-classification": snippetZeroShotImageClassification,
|
115 |
};
|
116 |
|
117 |
export function getPythonInferenceSnippet(model: ModelData, accessToken: string): string {
|