Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
machineuser commited on
Commit ·
ab9170f
1
Parent(s): 76bddde
Sync widgets demo
Browse filesFiles changed (4)
1.python_generated43 unmodified lines44454647484943 unmodified lines"license": "MIT","devDependencies": {"@types/node": "^20.11.5","quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgz"}}43 unmodified lines44454647484943 unmodified lines"license": "MIT","devDependencies": {"@types/node": "^20.11.5","quicktype-core": "https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz"}}
8 unmodified lines910111213141516172 unmodified lines1891901911921931941951961971988 unmodified linesspecifier: ^20.11.5version: 20.11.5quicktype-core:specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgzversion: '@github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgz'packages:172 unmodified linesengines: {node: '>= 14'}dev: true'@github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgz':resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.15/packages/quicktype-core/quicktype-core-18.0.15.tgz}name: quicktype-coreversion: 18.0.15dependencies:'@glideapps/ts-necessities': 2.1.3'@types/urijs': 1.19.258 unmodified lines910111213141516172 unmodified lines1891901911921931941951961971988 unmodified linesspecifier: ^20.11.5version: 20.11.5quicktype-core:specifier: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgzversion: '@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz'packages:172 unmodified linesengines: {node: '>= 14'}dev: true'@github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz':resolution: {tarball: https://github.com/huggingface/quicktype/raw/pack-18.0.17/packages/quicktype-core/quicktype-core-18.0.17.tgz}name: quicktype-coreversion: 18.0.17dependencies:'@glideapps/ts-necessities': 2.1.3'@types/urijs': 1.19.25
13 unmodified lines14151617181942 unmodified lines626364656667686970109 unmodified lines18018118218318413 unmodified lines`;const rootDirFinder = function (): string {let currentPath = path.normalize(import.meta.url);42 unmodified lines"prefer-const-values": true,"prefer-unknown": true,"explicit-unions": true,},});}/*** quicktype is unable to generate "top-level array types" that are defined in the output spec: https://github.com/glideapps/quicktype/issues/2481* We have to use the TypeScript API to generate those types when required.109 unmodified linesconsole.log(" 🩹 Post-processing the generated code");await postProcessOutput(`${dirPath}/inference.ts`, outputSpec);}console.debug("✅ All done!");13 unmodified lines1415161718192021222324252627282942 unmodified lines727374757677787980818283848586878889909192939495109 unmodified lines20520620720820921021121221321421521621721821922022113 unmodified lines`;const PYTHON_HEADER_FILE = `# Inference code generated from the JSON schema spec in @huggingface/tasks.## See:# - script: https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-codegen.ts# - specs: https://github.com/huggingface/huggingface.js/tree/main/packages/tasks/src/tasks.`;const PYTHON_DIR = "./.python_generated";const rootDirFinder = function (): string {let currentPath = path.normalize(import.meta.url);42 unmodified lines"prefer-const-values": true,"prefer-unknown": true,"explicit-unions": true,"runtime-typecheck": false,},});}async function generatePython(inputData: InputData): Promise<SerializedRenderResult> {return await quicktype({inputData,lang: "python",alphabetizeProperties: true,rendererOptions: {"just-types": true,"nice-property-names": true,"python-version": "3.7",},});}/*** quicktype is unable to generate "top-level array types" that are defined in the output spec: https://github.com/glideapps/quicktype/issues/2481* We have to use the TypeScript API to generate those types when required.109 unmodified linesconsole.log(" 🩹 Post-processing the generated code");await postProcessOutput(`${dirPath}/inference.ts`, outputSpec);console.debug(" 🏭 Generating Python code");{const { lines } = await generatePython(inputData);const pythonFilename = `${task}.py`.replace(/-/g, "_");const pythonPath = `${PYTHON_DIR}/${pythonFilename}`;await fs.mkdir(PYTHON_DIR, { recursive: true });await fs.writeFile(pythonPath, [PYTHON_HEADER_FILE, ...lines].join(`\n`), {flag: "w+",encoding: "utf-8",});}}console.debug("✅ All done!");
packages/tasks/.gitignoreAdded+1
packages/tasks/package.json+1-1
packages/tasks/pnpm-lock.yaml+5-5
packages/tasks/scripts/inference-codegen.ts+37