Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
machineuser
commited on
Commit
•
0a75df8
1
Parent(s):
58b8b64
Sync widgets demo
Browse files
packages/tasks/src/snippets/inputs.ts
CHANGED
@@ -31,6 +31,12 @@ const inputsTableQuestionAnswering = () =>
|
|
31 |
}
|
32 |
}`;
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
const inputsQuestionAnswering = () =>
|
35 |
`{
|
36 |
"question": "What is my name?",
|
@@ -91,6 +97,7 @@ const modelInputSnippets: {
|
|
91 |
"audio-classification": inputsAudioClassification,
|
92 |
"automatic-speech-recognition": inputsAutomaticSpeechRecognition,
|
93 |
conversational: inputsConversational,
|
|
|
94 |
"feature-extraction": inputsFeatureExtraction,
|
95 |
"fill-mask": inputsFillMask,
|
96 |
"image-classification": inputsImageClassification,
|
|
|
31 |
}
|
32 |
}`;
|
33 |
|
34 |
+
const inputsVisualQuestionAnswering = () =>
|
35 |
+
`{
|
36 |
+
"image": "cat.png",
|
37 |
+
"question": "What is in this image?"
|
38 |
+
}`;
|
39 |
+
|
40 |
const inputsQuestionAnswering = () =>
|
41 |
`{
|
42 |
"question": "What is my name?",
|
|
|
97 |
"audio-classification": inputsAudioClassification,
|
98 |
"automatic-speech-recognition": inputsAutomaticSpeechRecognition,
|
99 |
conversational: inputsConversational,
|
100 |
+
"document-question-answering": inputsVisualQuestionAnswering,
|
101 |
"feature-extraction": inputsFeatureExtraction,
|
102 |
"fill-mask": inputsFillMask,
|
103 |
"image-classification": inputsImageClassification,
|
packages/tasks/src/snippets/python.ts
CHANGED
@@ -94,6 +94,19 @@ from IPython.display import Audio
|
|
94 |
Audio(audio, rate=sampling_rate)`;
|
95 |
}
|
96 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = {
|
98 |
// Same order as in tasks/src/pipelines.ts
|
99 |
"text-classification": snippetBasic,
|
@@ -120,6 +133,7 @@ export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) =>
|
|
120 |
"tabular-classification": snippetTabular,
|
121 |
"object-detection": snippetFile,
|
122 |
"image-segmentation": snippetFile,
|
|
|
123 |
"image-to-text": snippetFile,
|
124 |
"zero-shot-image-classification": snippetZeroShotImageClassification,
|
125 |
};
|
|
|
94 |
Audio(audio, rate=sampling_rate)`;
|
95 |
}
|
96 |
};
|
97 |
+
|
98 |
+
export const snippetDocumentQuestionAnswering = (model: ModelData): string =>
|
99 |
+
`def query(payload):
|
100 |
+
with open(payload["image"], "rb") as f:
|
101 |
+
img = f.read()
|
102 |
+
payload["image"] = base64.b64encode(img).decode("utf-8")
|
103 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
104 |
+
return response.json()
|
105 |
+
|
106 |
+
output = query({
|
107 |
+
"inputs": ${getModelInputSnippet(model)},
|
108 |
+
})`;
|
109 |
+
|
110 |
export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = {
|
111 |
// Same order as in tasks/src/pipelines.ts
|
112 |
"text-classification": snippetBasic,
|
|
|
133 |
"tabular-classification": snippetTabular,
|
134 |
"object-detection": snippetFile,
|
135 |
"image-segmentation": snippetFile,
|
136 |
+
"document-question-answering": snippetDocumentQuestionAnswering,
|
137 |
"image-to-text": snippetFile,
|
138 |
"zero-shot-image-classification": snippetZeroShotImageClassification,
|
139 |
};
|