Spaces:
Runtime error
Runtime error
Thomas G. Lopes commited on
Commit ·
36ed2d0
1
Parent(s): 55b300a
fix ci
Browse files4 unmodified lines567891011121314151617181920212242 unmodified lines656667686970712 unmodified lines747576777879804 unmodified lines8586878889909113 unmodified lines10510610710810911011111211311411511611711811912085 unmodified lines20620720820921021121210 unmodified lines2232242252262272282291 unmodified line2312322332342352362374 unmodified linesimport http from "highlight.js/lib/languages/http";import javascript from "highlight.js/lib/languages/javascript";import python from "highlight.js/lib/languages/python";import { createEventDispatcher, onDestroy } from "svelte";import { token } from "$lib/stores/token";import type { InferenceProvider } from "@huggingface/inference";import IconCopyCode from "../Icons/IconCopyCode.svelte";import {getInferenceSnippet,type GetInferenceSnippetReturn,type InferenceSnippetLanguage,} from "./inferencePlaygroundUtils";import { keys, fromEntries, entries } from "$lib/utils/object";import IconExternal from "../Icons/IconExternal.svelte";hljs.registerLanguage("javascript", javascript);hljs.registerLanguage("python", python);42 unmodified linesreturn [lang, 0];}));$: selectedSnippet = snippetsByLang[lang][selectedSnippetIdxByLang[lang]]!;type InstallInstructions = {title: string;2 unmodified lines};$: installInstructions = (function getInstallInstructions(): InstallInstructions | undefined {if (lang === "javascript") {const isHugging = selectedSnippet.client.includes("hugging");const toInstall = isHugging ? "@huggingface/inference" : "openai";const docs = isHugging? "https://huggingface.co/docs/huggingface.js/inference/README"4 unmodified linesdocs,};} else if (lang === "python") {const isHugging = selectedSnippet.client.includes("hugging");const toInstall = isHugging ? "huggingface_hub" : "openai";const docs = isHugging? "https://huggingface.co/docs/huggingface_hub/guides/inference"13 unmodified linesreturn "YOUR_HF_TOKEN";}function highlight(code: string, language: InferenceSnippetLanguage) {return hljs.highlight(code, { language: language === "curl" ? "http" : language }).value;}function copy(el: HTMLElement, _content: string) {let timeout: Timer;let content = _content;function update(_content: string) {content = _content;}function onClick() {85 unmodified lines<preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-xs dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(installInstructions.content,selectedSnippet.language)}</pre>{/if}10 unmodified lines</label><buttonclass="flex items-center gap-x-2 rounded-md border bg-white px-1.5 py-0.5 text-sm shadow-xs transition dark:border-gray-800 dark:bg-gray-800"use:copy={selectedSnippet.content}><IconCopyCode classNames="text-xs" /> Copy code</button>1 unmodified line</div><preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-xs dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(selectedSnippet.content,selectedSnippet.language ?? lang)}</pre></div>4 unmodified lines567891011121314151617181920212242 unmodified lines656667686970712 unmodified lines747576777879804 unmodified lines8586878889909113 unmodified lines10510610710810911011111211311411511611711811912012185 unmodified lines20720820921021121221310 unmodified lines2242252262272282292301 unmodified line2322332342352362372384 unmodified linesimport http from "highlight.js/lib/languages/http";import javascript from "highlight.js/lib/languages/javascript";import python from "highlight.js/lib/languages/python";import { createEventDispatcher } from "svelte";import { token } from "$lib/stores/token";import { entries, fromEntries, keys } from "$lib/utils/object";import type { InferenceProvider } from "@huggingface/inference";import IconCopyCode from "../Icons/IconCopyCode.svelte";import IconExternal from "../Icons/IconExternal.svelte";import {getInferenceSnippet,type GetInferenceSnippetReturn,type InferenceSnippetLanguage,} from "./inferencePlaygroundUtils";hljs.registerLanguage("javascript", javascript);hljs.registerLanguage("python", python);42 unmodified linesreturn [lang, 0];}));$: selectedSnippet = snippetsByLang[lang][selectedSnippetIdxByLang[lang]];type InstallInstructions = {title: string;2 unmodified lines};$: installInstructions = (function getInstallInstructions(): InstallInstructions | undefined {if (lang === "javascript") {const isHugging = selectedSnippet?.client.includes("hugging");const toInstall = isHugging ? "@huggingface/inference" : "openai";const docs = isHugging? "https://huggingface.co/docs/huggingface.js/inference/README"4 unmodified linesdocs,};} else if (lang === "python") {const isHugging = selectedSnippet?.client.includes("hugging");const toInstall = isHugging ? "huggingface_hub" : "openai";const docs = isHugging? "https://huggingface.co/docs/huggingface_hub/guides/inference"13 unmodified linesreturn "YOUR_HF_TOKEN";}function highlight(code?: string, language?: InferenceSnippetLanguage) {if (!code || !language) return "";return hljs.highlight(code, { language: language === "curl" ? "http" : language }).value;}function copy(el: HTMLElement, _content?: string) {let timeout: ReturnType<typeof setTimeout>;let content = _content ?? "";function update(_content?: string) {content = _content ?? "";}function onClick() {85 unmodified lines<preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-xs dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(installInstructions.content,selectedSnippet?.language)}</pre>{/if}10 unmodified lines</label><buttonclass="flex items-center gap-x-2 rounded-md border bg-white px-1.5 py-0.5 text-sm shadow-xs transition dark:border-gray-800 dark:bg-gray-800"use:copy={selectedSnippet?.content}><IconCopyCode classNames="text-xs" /> Copy code</button>1 unmodified line</div><preclass="overflow-x-auto rounded-lg border border-gray-200/80 bg-white px-4 py-6 text-sm shadow-xs dark:border-gray-800 dark:bg-gray-800/50">{@html highlight(selectedSnippet?.content,selectedSnippet?.language)}</pre></div>
src/lib/components/InferencePlayground/InferencePlaygroundCodeSnippets.svelte+17-16