const axios = require('axios');

const handler = async (m, { text, command, conn }) => { const payloads = { prompt: ${text}, // your imagination go here width: 512, // 512-1024 height: 768, // 512-1024 Steps: 25, // max 50 steps model_id: 't-anime-v4', // default dream_shaper sampler: 'DPM++ 2M SDE karras', // 2M SDE karras seed: null, // pass null or remove to get random seed cfg: 7.5, // max 15< image_num: 1, // max 4 negative_prompt: 'ugly', // something you don't want to appear in the image safety_checker: 'no', // set 'no' to replace nsfw image

	/* Another optional parameter */
	enhance_prompt: 'yes', // if 'yes' will add another prompt
	multi_lingual: 'yes', // pass 'yes' if you want to use other than the English language
	clip_skip: 2,
	panorama: 'no', // pass 'yes' if you want a panorama image
	Lora_model: 'more_details', // use loaded Lora_model
	hiresFix: 'no', // otherwise pass 'no'
	Lora_strength: 1, // default 1
	embeddings_model: '',
	webhook: null, // will send post about generating progress
};

m.reply('_Preparing Stable diffusion..._');

try {
	const { data } = await axios.request({
		baseURL: 'https://api.itsrose.life',
		url: '/image/diffusion/txt2img',
		method: 'POST',
		params: {
			apikey: `${global.rose}`,
		},
		data: payloads,
	});

	const { status, message, result } = data;

	if (!status) {
		// something wrong with your payloads
		return m.reply(message); // see the message
	}
	const { images, metadata, generation_time } = result;
	const second = result.generation_time.toFixed();
	const model = metadata.model_id;
	const schedule = metadata.scheduler;
	const w = metadata.W;
	const h = metadata.H;
	const cfg = metadata.guidance_scale;
	const step = metadata.steps;
	const seed = metadata.seed;
	const streng = metadata.clip_skip;

	const medata = `*Generating Time*: ${second} second

prompt: ${text} model_id: ${model} scheduler: ${schedule} W: ${w} H: ${h} guidance_scale: ${cfg} steps: ${step} seed: ${seed} clip_skip: ${streng}`; await m.reply(medata);

	for (const image of images) {
		await new Promise((resolve) => {
			setTimeout(async () => {
				await conn.sendMessage(m.chat, { image: { url: image } });
				resolve();
			}, generation_time * 1000);
		});
	}
} catch (e) {
	m.reply(`Failed sending images: ${e.response.data}`);
}

};

handler.command = handler.help = ['txt2img']; handler.tags = ['internet']; handler.register = true; handler.limit = true;

module.exports = handler;

Generate Images from Text using Stable Diffusion API

原文地址: https://www.cveoy.top/t/topic/impY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录