diff --git a/js/src/lib/inferenceSnippets/servePython.ts b/js/src/lib/inferenceSnippets/servePython.ts index bb11ee3a5..44b8ccb04 100644 --- a/js/src/lib/inferenceSnippets/servePython.ts +++ b/js/src/lib/inferenceSnippets/servePython.ts @@ -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({ @@ -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 string>> = { // Same order as in js/src/lib/interfaces/Types.ts "text-classification": snippetBasic,