내가 시험삼아 뽑아본것. 문장형인데 꽤 말 잘 알아듣네. 손꾸락이나 이런건 나중에 네거프롬같은걸로 어케되겠지.

A medieval female adventurer parties with her companions in a tavern.

중세 여성 모험가가 선술집에서 동료들과 파티를 벌이고 있습니다.


1. https://platform.stability.ai/

에서 본인 API키 발급 (가입하면 25크레딧 = 짤 3개 뽑을수있다함)



2. 아래 내용들 복사해서 메모장에 붙여넣고 저장한 뒤, html로 확장자 변경해서 api키, 프롬프트 입력해서 이미지 생성해보기



<!DOCTYPE html>

<html lang="ko">

<head>

  <meta charset="UTF-8">

  <title>Image Fetch with User Inputs</title>

</head>

<body>

  <label for="apiKey">API Key:</label>

  <input type="text" id="apiKey" placeholder="API키 (sk-어쩌구)" style="width: 300px;">

  <br><br>

  <label for="promptInput">Prompt:</label>

  <input type="text" id="promptInput" placeholder="프롬프트 (예시: A red apple is on the desk)" style="width: 300px;">

  <br><br>

  <button id="fetchImage">이미지 생성 (누르고 몇초 기다려야함)</button>

  <img id="displayImage" src="" alt="Generated Image" style="width:100%; max-width:600px; height:auto;">

  <script>

    document.getElementById('fetchImage').addEventListener('click', async () => {

      const apiKey = document.getElementById('apiKey').value;

      const prompt = document.getElementById('promptInput').value;


      if (!apiKey || !prompt) {

        alert('API Key와 Prompt를 입력해주세요.');

        return;

      }


      const formData = new FormData();

      formData.append('prompt', prompt);

      formData.append('output_format', "jpeg");


      try {

        const response = await fetch('https://api.stability.ai/v2beta/stable-image/generate/sd3', {

          method: 'POST',

          body: formData,

          headers: {

            'Authorization': `Bearer ${apiKey}`, 

            'Accept': 'image/*'

          },

        });


        if (response.ok) {

          const blob = await response.blob();

          const imageUrl = URL.createObjectURL(blob);

          document.getElementById('displayImage').src = imageUrl;

        } else {

          throw new Error(`HTTP error! status: ${response.status}`);

        }

      } catch (e) {

        console.error('Failed to fetch image:', e);

        alert('이미지를 가져오는 데 실패했습니다: ' + e.message);

      }

    });

  </script>

</body>

</html>