Skip to content

Commit

Permalink
Update js/src/lib/inferenceSnippets/servePython.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Mishig <[email protected]>
  • Loading branch information
Vaibhavs10 and mishig25 authored Oct 16, 2023
1 parent 9aee67e commit 944ca1f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions js/src/lib/inferenceSnippets/servePython.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import io
from PIL import Image
image = Image.open(io.BytesIO(image_bytes))`;

if (ModelData.library_name === "transformers") {
export const snippetTextToAudio = (model: ModelData): string =>
`def query(payload):
export const snippetTextToAudio = (model: ModelData): string => {
if (ModelData.library_name === "transformers") {
return `def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.content
audio_bytes = query({
Expand All @@ -53,18 +53,17 @@ audio_bytes = query({
# You can access the audio with IPython.display for example
from IPython.display import Audio
Audio(audio_bytes)`;
} else {
export const snippetTextToAudio = (model: ModelData): string =>
`def query(payload):
Audio(audio_bytes)`
}else{
return `def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": ${getModelInputSnippet(model)},
})`;
})`
}
}

export const pythonSnippets: Partial<Record<PipelineType, (model: ModelData) => string>> = {
// Same order as in js/src/lib/interfaces/Types.ts
"text-classification": snippetBasic,
Expand Down

0 comments on commit 944ca1f

Please sign in to comment.