Skip to content

samfe37/stable-diffusion-api-server

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

426 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI Art ๋ชจ๋ธ์ธ Stable Diffusion์„ ์‰ฝ๊ณ  ํŽธ๋ฆฌํ•˜๊ฒŒ ์ด์šฉํ•˜๊ธฐ

Stable Diffusion ๋ชจ๋ธ์„ ์ด์šฉํ•˜๋ฉด ํ…์ŠคํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฐฝ์กฐ์ ์ธ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Amazon์—์„œ๋Š” SageMaker JumpStart์„ ์ด์šฉํ•˜์—ฌ ๋จธ์‹ ๋Ÿฌ๋‹(ML)์„ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์‚ฌ์ „ํ•™์Šต(pre-trained)๋œ ๋ชจ๋ธ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ๋Š”๋ฐ, 2022๋…„ 10์›” ๋ถ€ํ„ฐ Stable Diffusion ๋ชจ๋ธ์„ ์ถ”๊ฐ€์ ์œผ๋กœ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด Stable Diffusion ์ด๋ฏธ์ง€๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ฆ‰์‹œ Servingํ•  ์ˆ˜ ์žˆ๋„๋ก SageMaker Endpoint๋„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. SageMaker Endpoint๋Š” ํŠธ๋ž˜ํ”ฝ์ด ์ฆ๊ฐ€ํ•  ๋•Œ๋Š” ์ž๋™์œผ๋กœ Scale out ํ•˜๋ฏ€๋กœ, ํŠธ๋ž˜ํ”ฝ ๋ณ€๋™์ด ์‹ฌํ• ๋•Œ์—๋„ ํšจ์œจ์ ์œผ๋กœ ์ธํ”„๋ผ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ IAM ๊ธฐ๋ฐ˜์˜ ๊ฐ•ํ™”๋œ ๋ณด์•ˆ์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Stable Diffusion ์˜ˆ์ œ

Stable Diffusion Keywords์—์„œ๋Š” keywords์— ๋”ฐ๋ฅธ Stable Diffusion์˜ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

"The Legend of Zelda landscape atmospheric, hyper realistic, 8k, epic composition, cinematic, octane render, artstation landscape vista photography by Carr Clifton & Galen Rowell, 16K resolution, Landscape veduta photo by Dustin Lefevre & tdraw, 8k resolution, detailed landscape painting by Ivan Shishkin, DeviantArt, Flickr, rendered in Enscape, Miyazaki, Nausicaa Ghibli, Breath of The Wild, 4k detailed post processing, artstation, rendering by octane, unreal engine"

JumpStart์—์„œ ์ œ๊ณตํ•œ Stable Diffusion Endpoint์‚ฌ์šฉ์‹œ ์ฃผ์˜์‚ฌํ•ญ

SageMaker Endpoint๋กœ JumpStart์—์„œ ์ œ๊ณตํ•œ Stable Diffusion ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ์š”์ฒญํ•  ๋•Œ ์–ป์–ด์ง„ ์‘๋‹ต(Response)์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. JSON ์‘๋‹ต์—๋Š” "generated_image" ํ•„๋“œ๋กœ ์ด๋ฏธ์ง€์˜ RGB ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํด๋ผ์ด์–ธํŠธ์—์„œ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๋ฏธ์ง€ ํฌ๋งท์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ, SageMaker Endpoint๋กœ Stable Diffusion ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ์š”์ฒญ(Request)ํ•  ๋•Œ์—๋Š” IAM ์ธ์ฆ์„ ํ•˜์—ฌ์•ผ ํ•˜๋ฏ€๋กœ, ํด๋ผ์ด์–ธํŠธ๋Š” ๋ฏผ๊ฐํ•œ ์ •๋ณด์ธ IAM Credential์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์•ผ ํ•˜๊ณ , AWS SDK๋ฅผ ํ†ตํ•ด API ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์›น๋ธŒ๋ผ์šฐ์ € ๋˜๋Š” ๋ชจ๋ฐ”์ผ์•ฑ์—์„œ๋Š” IAM ์ธ์ฆ ๊ธฐ๋ฐ˜์˜ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค. ์ด์™€ ๊ฐ™์€ ์ด์œ ๋กœ ๋ณธ ๊ฒŒ์‹œ๊ธ€์—์„œ๋Š” SageMaker Endpoint์— ๋Œ€ํ•œ IAM ์ธ์ฆ ๋ฐ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋ณ€ํ™˜์„ ์œ„ํ•ด API Gateway์™€ Lambda๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

{
    "generated_image": [
        [[221,145,108],[237,141,98],[249,154,111],..]
        ...
    ],
    "prompt": "{
        predictions":[{
            "prompt": "astronaut on a horse", 
            "width": 768, 
            "height": 512,
            "num_images_per_prompt": 1, 
            "num_inference_steps": 50, 
            "guidance_scale": 7.5
        }]
    }
}

์ œ์•ˆ๋œ Stable Diffusion Architecture

์ „์ฒด์ ์ธ Architecture๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. SageMaker๋Š” JumpStart๋กœ ์ œ๊ณต๋˜๋Š” Stable Diffusion ๋ชจ๋ธ์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์„œ ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ๋กœ ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Lambda๋Š” IAM ์ธ์ฆ์„ ํ†ตํ•ด SageMaker Endpoint๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์ „๋‹ฌํ•œ ํ…์ŠคํŠธ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•˜๊ณ , ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์˜ ์ •๋ณด๋ฅผ image map ํ˜•ํƒœ๋กœ ์–ป์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก image map์€ S3์— JPEG ํฌ๋งท์œผ๋กœ ์ €์žฅ๋˜๋Š”๋ฐ, CloudFront ๋„๋ฉ”์ธ ์ •๋ณด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€์— ๋Œ€ํ•œ URL์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. API Gateway๋Š” ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ Restful API๋กœ ๋ฐ›์•„์„œ Lambda์— ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ์ „๋‹ฌํ•˜๊ณ , Lambda๊ฐ€ ์ƒ์„ฑํ•œ URL ์ด๋ฏธ์ง€ ์ •๋ณด๋ฅผ ์‚ฌ์šฉ์ž์—๊ฒŒ ์‘๋‹ต์œผ๋กœ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ์ „์ฒด ์„œ๋น„์Šค๋“ค์˜ ๋ฐฐํฌ๋Š” AWS CDK๋ฅผ ์ด์šฉํ•˜๊ณ , docker container ์ด๋ฏธ์ง€๋Š” ECR๋กœ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

SageMaker Endpoint๋กœ ์ถ”๋ก (Inference)์„ ์š”์ฒญ ๋ฐฉ๋ฒ•

Lambda์—์„œ Sagemaker Endpoint๋กœ ์ถ”๋ก (Inference) ์š”์ฒญ์‹œ์— ์•„๋ž˜์™€ ๊ฐ™์ด "ContentType"๊ณผ "Accept"์„ ์ง€์ •ํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

"ContentType": "application/json",
"Accept": "application/json",

์ด๋•Œ Request์˜ Body์—๋Š” ์•„๋ž˜ ํฌ๋งท์œผ๋กœ Stable Diffusion์— ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. width, height๋กœ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•˜๋Š”๋ฐ 8๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. num_images_per_prompt์€ ํ•œ๋ฒˆ์— ์ƒ์„ฑ๋˜๋Š” ์ด๋ฏธ์ง€์˜ ๊ฐฏ์ˆ˜์ด๊ณ , num_inference_steps๋Š” ์ด๋ฏธ์ง€ ์ƒ์„ฑ์‹œ denoising ๋‹จ๊ณ„๋ฅผ ์˜๋ฏธํ•˜๋Š”๋ฐ ์ˆซ์ž๋ฅผ ๋†’์ด๋ฉด ๋” ๋†’์€ ํ’ˆ์งˆ์˜ ์ด๋ฏธ์ง€๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. guidance_scale์€ prompt์— ๊ฐ€๊นŒ์šด ์ •๋„๋ฅผ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.

{
    predictions":[{
        "prompt": "astronaut on a horse",
        "width": 768,
        "height": 512,
        "num_images_per_prompt": 1,
        "num_inference_steps": 50,
        "guidance_scale": 7.5
    }]
}

lambda_function.py์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์š”์ฒญ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. Python์˜ boto3์„ ์ด์šฉํ•ด SageMaker Endpoint์— ์š”์ฒญ(request)์„ ์ „๋‹ฌํ•˜๋Š”๋ฐ, ContentType์€ "application/json"์ด๊ณ , Accept ํ—ค๋”๋กœ๋Š” "Accept='application/json" ๋˜๋Š” "Accept='application/json;jpeg"์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

import boto3

runtime = boto3.Session().client('sagemaker-runtime')
response = runtime.invoke_endpoint(EndpointName=endpoint, ContentType='application/json', Accept='application/json;jpeg', Body=json.dumps(payload))

RGB ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ™˜ํ•˜์—ฌ S3์— ์—…๋กœ๋“œ ํ•˜๋Š” ๊ฒฝ์šฐ

SageMaker Endpoint์— query์‹œ์— Accept์„ "application/json"์œผ๋กœ ํ•˜๋Š” ๊ฒฝ์šฐ์— RGB๋กœ ๋œ text๋ฐ์ดํ„ฐ๊ฐ€ ๋‚ด๋ ค์˜ต๋‹ˆ๋‹ค. ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋Š” JSON์˜ "Body"์™€ "generated_image"๋กœ ๋ถ€ํ„ฐ ์ถ”์ถœํ•œ ํ›„์—, PIL(pillow)๊ณผ numpy ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ S3์— ์ €์žฅํ• ์ˆ˜ ์žˆ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ lambda_function.py์˜ ์ฝ”๋“œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

from PIL import Image
import numpy as np

def parse_response(query_response):
    response_dict = json.loads(query_response)
    return response_dict["generated_images"], response_dict["prompt"]
    
response_payload = response['Body'].read().decode('utf-8')
generated_image, prompt = parse_response(response_payload)
        
image = Image.fromarray(np.uint8(generated_images[0]))
buffer = io.BytesIO()
image.save(buffer, "jpeg")
buffer.seek(0)
            
s3 = boto3.client('s3')
s3.upload_fileobj(buffer, mybucket, mykey, ExtraArgs={ "ContentType": "image/jpeg"})

๊ทธ๋Ÿฐ๋ฐ, Lambda์—์„œ pillow, numpy ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ "pip install --target=[lambda ํด๋”] pillow numpy"์™€ ๊ฐ™์ด ์„ค์น˜ํ•œ ํ›„ ์••์ถ•ํ•ด์„œ ์˜ฌ๋ฆฌ๋ฉด layer๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ์•ผ ํ•˜๋ฏ€๋กœ, docker container๋ฅผ ์ด์šฉํ•˜์—ฌ pillow, numpy์™€ ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ์˜ Dockerfile์˜ ์˜ˆ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

FROM amazon/aws-lambda-python:3.8

RUN pip3 install --upgrade pip
RUN python -m pip install joblib awsiotsdk

RUN pip install numpy pillow

WORKDIR /var/task/lambda

COPY lambda_function.py /var/task

COPY . .

CMD ["lambda_function.lambda_handler"]

JPEG๋กœ encoding๋œ ์ด๋ฏธ์ง€๋ฅผ S3์— ์—…๋กœ๋“œ ํ•˜๋Š” ๊ฒฝ์šฐ

Acceptํ—ค๋”๋ฅผ "application/json;jpeg"๋กœ ์„ค์ •ํ•˜๋ฉด SageMaker Endpoint๊ฐ€ base64๋กœ encoding๋œ JPEG ์ด๋ฏธ์ง€๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ base64 decoding ํ›„์— ์ธ๋ฉ”๋ชจ๋ฆฌ ๋ฐ”์ด๋„ˆ๋ฆฌ ์ŠคํŠธ๋ฆผ์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ S3๋กœ ์—…๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

response_payload = response['Body'].read().decode('utf-8')
generated_image, prompt = parse_response(response_payload)

import base64
img_str = base64.b64decode(generated_image)
buffer = io.BytesIO(img_str)  
s3.upload_fileobj(buffer, mybucket, mykey, ExtraArgs={"ContentType": "image/jpeg"})

AWS CDK๋ฅผ ์ด์šฉํ•œ ๋ฐฐํฌ ์ค€๋น„

CDK ๋ฐฐํฌ ์ค€๋น„์—์„œ๋Š” CDK๋กœ S3, Lambda, API Gateway, CloudFront๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

๋ฐฐํฌํ•˜๊ธฐ

Stable Diffusion์„ ์œ„ํ•œ SageMaker Endpoint ์ƒ์„ฑ

Stable Diffusion Endpoint ์ƒ์„ฑ์— ๋”ฐ๋ผ SageMaker JumpStart์—์„œ Stable Diffusion Endpoint ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

CDK๋กœ ์ถ”๋ก  ์ธํ”„๋ผ ๊ตฌ์ถ•ํ•˜๊ธฐ

์ถ”๋ก ์„ ์œ„ํ•œ ์ธํ”„๋ผ์—๋Š” API Gateway, S3, Lambda, CloudFront๊ฐ€ ์žˆ์œผ๋ฉฐ, AWS CDK๋กœ ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค. ์ƒ์„ธํ•œ ๋ฐฐํฌ์ •๋ณด๋Š” cdk-stable-diffusion-stack.ts์„ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค. Cloud9์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•˜์—ฌ Cloud9 console์—์„œ Create environment๋ฅผ ์„ ํƒํ•œ ํ›„์— ์•„๋ž˜์ฒ˜๋Ÿผ Name์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” "Stabel Diffusion"์ด๋ผ๊ณ  ์ž…๋ ฅํ•˜์˜€์Šต๋‹ˆ๋‹ค. ์ดํ›„ ๋‚˜๋จธ์ง€๋Š” ๋ชจ๋‘ ๊ทธ๋Œ€๋กœ ์œ ์ง€ํ•˜๊ณ  [Create]๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

noname

Cloud9์ด ์ƒ์„ฑ๋œ ํ›„์— [Open]์„ ์„ ํƒํ•˜์—ฌ ์ง„์ž…ํ•œ ํ›„ ์•„๋ž˜์ฒ˜๋Ÿผ ํ„ฐ๋ฏธ๋„์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์ดํ›„ ์•„๋ž˜์™€ ๊ฐ™์ด ๊ด€๋ จ ์ฝ”๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.

git clone https://github.com/kyopark2014/stable-diffusion-api-server

์ธํ”„๋ผ ์ƒ์„ฑ์‹œ SageMaker์˜ Endpoint ์ •๋ณด๊ฐ€ ํ•„์š”ํ•˜๋ฏ€๋กœ, ์•„๋ž˜์™€ ๊ฐ™์ด ์ขŒ์ธก ํŒŒ์ผํƒ์ƒ‰๊ธฐ์—์„œ "cdk-stable-diffusion/lib/cdk-stable-diffusion-stack.ts"๋ฅผ ์„ ํƒํ•˜์—ฌ ์ด์ „ ๋‹จ๊ณ„์—์„œ ๋ณต์‚ฌํ•œ Endpoint์˜ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

noname

CDK ํด๋”(cdk-stable-diffusion)๋กœ ์ด๋™ํ•˜์—ฌ "aws-cdk-lib"์™€ "path" ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ npm์œผ๋กœ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ, "aws-cdk-lib"์€ CDK 2.0 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

cd cdk-stable-diffusion && npm install aws-cdk-lib path

์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์ „์ฒด ์ธํ”„๋ผ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

cdk deploy

CDK๋กœ ์ธํ”„๋ผ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์น˜๋œ ์ธํ”„๋ผ์˜ ์ •๋ณด๋ฅผ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ appUrl์€ Browser์—์„œ query๋ฌธ์„ ์ด์šฉํ•ด API๋ฅผ ํ˜ธ์ถœํ• ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ณ , curlUrl์€ shell์—์„œ ํ…Œ์ŠคํŠธ ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

noname

์‹ค์ œ ์˜ˆ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

CdkStableDiffusionStack.WebUrl = https://1r9dqh4f37.execute-api.ap-northeast-2.amazonaws.com/dev/text2image?prompt=astronaut
CdkStableDiffusionStack.curlUrl = curl -X POST https://1r9dqh4f37.execute-api.ap-northeast-2.amazonaws.com/dev/text2image -H "Content-Type: application/json" -d '{"text":"astronaut on a horse"}'

Browser์—์„œ ์š”์ฒญํ•  ๊ฒฝ์šฐ

Browser์—์„œ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. prompt์— ์ฟผ๋ฆฌํ•  ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

https://1r9dqh4f37.execute-api.ap-northeast-2.amazonaws.com/dev/text2image?prompt=astronaut on a horse

์ด๋•Œ์˜ ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

image

Curl๋กœ ์š”์ฒญํ•  ๊ฒฝ์šฐ

curl ๋ช…๋ น์–ด๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

curl -X POST https://1r9dqh4f37.execute-api.ap-northeast-2.amazonaws.com/dev/text2image -H "Content-Type: application/json" -d '{"text":"astronaut on a horse"}'

์ถ”๋ก ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ์˜ ์˜ˆ์ž…๋‹ˆ๋‹ค. "body"์— ์ถ”๋ก ์˜ ๊ฒฐ๊ณผ๋กœ ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์˜ URL์ด ์žˆ์Šต๋‹ˆ๋‹ค.

{"statusCode": 200, "body": "https://d283dvdglbetjo.cloudfront.net/img_20230208-014926"}

Postman์œผ๋กœ ์‹คํ–‰ํ•  ๊ฒฝ์šฐ

์•„๋ž˜์™€ ๊ฐ™์ด POST ๋ฐฉ์‹์„ ์„ ํƒํ•˜๊ณ  URL์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

[Body] - [raw] ์—์„œ JSON ํ˜•ํƒœ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

{
   "text": "astronaut on a horse"
}

[Headers]์— ์•„๋ž˜์™€ ๊ฐ™์ด Conten-Type์œผ๋กœ application/json์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

์ดํ›„ [Sent]๋ฅผ ์„ ํƒํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

Examples

์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋Š” ํ…์ŠคํŠธ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด์„œ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•˜์—ฌ ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

  • ukrainian girl with blue and yellow clothes near big ruined building, concept art, trending on artstation, highly detailed, intricate, sharp focus, digital art, 8 k

image

  • a portrait of a korean woman that is a representation of korean culture, buenos aires, fantasy, intricate, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha

image

  • "I see trees of green Red roses too. I see them bloom for me and you. And I think to myself. What a wonderful world" (Louis Armstrong's What a Wonderful World song!)

image

a young blonde male jedi with short hair standing still looking at the sunset concept art by Doug Chiang cinematic, realistic painting, high definition, concept art, portait image, path tracing, serene landscape, high quality, highly detailed, 8K, soft colors, warm colors, turbulent sea, high coherence, anatomically correct, hyperrealistic, concept art, defined face, five fingers, symmetrical

image

the eye of the storm, atmospheric, hyper realistic, 8k, epic composition, cinematic, octane render, artstation landscape vista photography by Carr Clifton & Galen Rowell, 16K resolution, Landscape veduta photo by Dustin Lefevre & tdraw, 8k resolution, detailed landscape painting by Ivan Shishkin, DeviantArt, Flickr, rendered in Enscape, Miyazaki, Nausicaa Ghibli, Breath of The Wild, 4k detailed post processing, artstation, rendering by octane!

image

Reference

Generate images from text with the stable diffusion model on Amazon SageMaker JumpStart

Amazon SageMaker JumpStart๋กœ ์‚ฌ์ „ ๊ตฌ์ถ•๋œ ๋ชจ๋ธ๊ณผ ๊ธฐ๊ณ„ ํ•™์Šต ์†”๋ฃจ์…˜ ์•ก์„ธ์Šค ๋‹จ์ˆœํ™”

Introduction to JumpStart - Text to Image

SageMaker Endpoint (Single Model Endpoint)

Build and automatize the management of your Sagemaker Studio Users using AWS CDK

Deploying SageMaker Endpoints With CloudFormation

Running Serverless ML on AWS Lambda

Deploy Stable Diffusion Models On Amazon SageMaker Endpoint

About

It describes how to provide the stable diffusion function using api server.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 99.1%
  • Other 0.9%