Profile
Welcome, Sensei!
Selamat datang di kode Putu Xml

📄 Paste ID: iuo61xxd

Dibuat oleh Putu Xml • Bahasa: js • 8/3/2025, 3:31:42 AM
const axios = require('axios');

const texttoimage = async (
  prompt = '',
  negativePrompt = '',
  sampler = 'Euler a',
  width = 832,
  height = 1216,
  cfg = 0.55,
  denoise = 1.5,
  seed = 0,
  hiresFix = true,
  steps = 6,
  batchSize = 25
) => {
  const samplers = [
    'DPM++ 2M Karras',
    'DPM++ SDE Karras',
    'DPM++ 2M SDE Karras',
    'Euler',
    'Euler a',
    'DDIM'
  ];

  if (!samplers.includes(sampler)) throw new Error('Invalid sampler');

  const sessionHash = Math.random().toString(36).slice(2);
  const base = 'https://frogleo-anime-ai-generator.hf.space/gradio_api';

  const payload = {
    data: [
      prompt,
      negativePrompt,
      width,
      height,
      sampler,
      cfg,
      denoise,
      seed,
      hiresFix,
      steps,
      batchSize
    ],
    event_data: null,
    fn_index: 0,
    trigger_id: 29,
    session_hash: sessionHash
  };

  await axios.post(`${base}/queue/join`, payload, {
    headers: { 'Content-Type': 'application/json' }
  });

  const endpoint = `${base}/queue/data?session_hash=${sessionHash}`;
  const start = Date.now();
  const timeout = 180000;

  while (Date.now() - start < timeout) {
    const { data: raw } = await axios.get(endpoint);
    const chunks = raw.split('\n\n');

    for (const chunk of chunks) {
      if (chunk.startsWith('data:')) {
        const json = JSON.parse(chunk.slice(6));
        if (json.msg === 'process_completed') {
          const url = json.output?.data?.[0]?.url;
          if (!url) throw new Error('no image url found');
          return url;
        }
        if (json.msg === 'queue_full') {
          throw new Error('queue full');
        }
      }
    }

    await new Promise(r => setTimeout(r, 2000));
  }

  throw new Error('timeout');
};

// Cara menggunakan 
texttoimage('masterpiece, miku', 'bad hands', 'DPM++ 2M SDE Karras')
🔗 View Raw
✅ Copied!