stability-ai
Version:
Node SDK for Stability AI REST API
71 lines • 3.09 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.stableFast3D = void 0;
const axios_1 = __importDefault(require("axios"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const form_data_1 = __importDefault(require("form-data"));
const util_1 = require("../../util");
const error_1 = require("../../error");
const Util = __importStar(require("../../util"));
const RESOURCE = '3d';
var Endpoint;
(function (Endpoint) {
Endpoint["STABLE_FAST_3D"] = "stable-fast-3d";
})(Endpoint || (Endpoint = {}));
/**
* Stability AI 3D Stable Fast 3D (v2beta)
*
* @param image - Local filepath or public URL of the image to make 3D
* @param options - Stable Fast 3D Options
*/
async function stableFast3D(...args) {
const [image, options] = args;
const imagePath = new Util.ImagePath(image);
const formData = {
image: fs_extra_1.default.createReadStream(await imagePath.filepath()),
};
if (options === null || options === void 0 ? void 0 : options.textureResolution)
formData.texture_resolution = options.textureResolution;
if (options === null || options === void 0 ? void 0 : options.foregroundRatio)
formData.foreground_ratio = options.foregroundRatio;
const response = await axios_1.default.postForm(Util.makeUrl(util_1.APIVersion.V2_BETA, RESOURCE, Endpoint.STABLE_FAST_3D), axios_1.default.toFormData(formData, new form_data_1.default()), {
validateStatus: undefined,
responseType: 'arraybuffer',
headers: {
...this.authHeaders,
},
});
imagePath.cleanup();
if (response.status === 200) {
return Util.processArrayBufferResponse(response.data, 'glb', 'v2beta_3d_stable_fast_3d');
}
throw new error_1.StabilityAIError(response.status, 'Failed: 3D Stable Fast 3D', response.data);
}
exports.stableFast3D = stableFast3D;
//# sourceMappingURL=stable-fast-3d.js.map
;