>  기사  >  백엔드 개발  >  FLUXor Free를 실행하는 방법: 단계별 가이드

FLUXor Free를 실행하는 방법: 단계별 가이드

PHPz
PHPz원래의
2024-09-10 06:33:02377검색

Flux.1은 Black Forest Labs에서 출시한 최신 텍스트-이미지 변환 모델입니다. 복잡한 설명을 다루는 텍스트 설명부터 세세한 디테일까지 고퀄리티의 이미지를 생성할 수 있는 최첨단 모델입니다.

Flux.1 뒤에는 누가 있습니까?

Flux.1은 Stability AI의 전 직원 그룹이 만든 회사인 Black Forest Labs에서 개발했습니다.

어떻게 작동하나요?

임의의 시작점에서 점차적으로 노이즈를 제거하여 이미지를 생성하는 Stable Diffusion과 같은 다른 확산 모델과 달리 Flux.1은 보다 직접적인 접근 방식을 취하는 "흐름 매칭"이라는 기술을 사용하여 이미지를 생성하고, 필요한 정확한 변환을 학습합니다. 노이즈를 사실적인 이미지로 변환합니다. 이를 통해 일반적인 확산 모델보다 더 빠르고 적은 단계로 고품질 이미지를 생성할 수 있습니다.

또한 이러한 다른 접근 방식을 통해 Flux.1은 아래와 같이 내부에 텍스트가 있는 이미지를 처리할 수 있습니다.

How to Run FLUXor Free: A Step-by-Step Guide

깨끗하고 미니멀한 디자인에 "codestackme"이라는 텍스트가 표시된 웹페이지가 열려 있는 현대적이고 세련된 노트북의 사실적인 이미지. 노트북은 화면의 빛과 금속 케이스의 미묘한 반사를 강조하면서 부드러운 조명이 있는 흰색 책상 위에 놓아야 합니다. 전체적인 분위기는 전문적이고 매력적이어야 하며 혁신과 기술 발전의 느낌을 전달해야 합니다.

Flux.1에 대한 좋은 프롬프트를 작성하는 방법은 무엇입니까?

Flux.1의 뛰어난 기능 중 하나는 사용자 친화적인 프롬프트 메커니즘입니다. CLIP(OpenAI) 및 T5(GoogleAI) 텍스트 인코더를 통합하면 모델이 설명을 높은 수준의 뉘앙스로 해석할 수 있습니다. CLIP은 텍스트를 시각적 콘텐츠에 맞게 정렬하는 데 탁월한 반면, T5는 구조화된 텍스트 입력을 처리하는 모델의 기능을 향상시킵니다. Flux.1은 이를 통해 사용자가 제공한 세부 프롬프트와 거의 일치하는 이미지를 생성할 수 있습니다.

Flux.1에는 어떤 유형의 모델이 있습니까?

Flux.1은 Schnell, Dev, Pro의 세 가지 버전으로 제공됩니다.

  • 슈넬은 속도와 효율성에 최적화된 가장 빠른 모델입니다. Apache 2.0 라이센스에 따라 출시되었으므로 상업적 사용이 허용됩니다.
  • Dev는 보다 유연하고 실험적인 프레임워크를 제공하며, 모델의 특정 기능을 미세 조정하거나 사용자 정의하려는 개발자와 연구에 중점을 둡니다. 비상업적 라이센스로 출시되었습니다.
  • Pro는 가장 발전된 리소스 집약적 버전입니다. 더 높은 해상도의 출력을 제공하고 더 복잡한 이미지를 생성할 수 있지만 Black Forest Labs API를 통해서만 사용할 수 있습니다.

Flux.1을 무료로 사용하는 방법은 무엇입니까?

금전적 부담 없이 Flux.1의 기능을 탐색하는 데 관심이 있는 사람들에게는 modal.com을 리소스 공급자로 사용하는 것이 실행 가능한 옵션입니다. Modal.com은 매달 수많은 이미지 생성을 지원할 수 있는 30달러의 월간 컴퓨팅 파워 허용량을 제공합니다. Modal.com 가격에서 가격 및 서비스에 대해 자세히 알아볼 수 있습니다.

이 추천은 플랫폼에서 후원하거나 보증하지 않습니다.

시작하려면 먼저 GitHub 자격 증명을 사용하여 로그인하여 modal.com에 계정을 만들어야 합니다.

다음으로 Modal CLI를 설치해야 합니다. Python이 컴퓨터에 설치되어 있는지 확인하십시오. Python이 설정되면 터미널을 열고 pip install modal 명령을 실행합니다. 설치가 완료되면 모달 설정을 실행하여 CLI를 모달 계정과 연결하세요.

이 GitHub 저장소를 컴퓨터에 복제하고 복제된 디렉터리로 이동하세요.

보안을 위해 모달 대시보드에 API_KEY라는 환경 변수를 사용하여 flux.1-secret이라는 비밀을 생성하고 임의의 문자열을 할당하세요.

마지막으로 터미널에서 modal install app.py --name flux1을 실행하여 서비스를 배포합니다. 성공적으로 배포되면 모달은 웹 서비스에 액세스하기 위한 URL을 제공합니다.

✓ Created objects.
├── ? Created mount PythonPackage:app
├── ? Created function Model.build.
├── ? Created function Model.*.
├── ? Created function Model._inference.
└── ? Created web function Model.web_inference => <PUBLIC_URL>
✓ App deployed in 3.206s! ?

서비스를 이용하려면 제공된 PUBLIC URL로 GET 요청을 하세요. 앞서 헤더에 설정한 x-api-key를 포함하고 쿼리 매개변수에 프롬프트를 인코딩합니다. 쿼리 매개변수를 통해 원하는 이미지 크기를 지정할 수도 있습니다. 요청을 구성하는 방법의 예는 다음과 같습니다.

curl -H "x-api-key: <API_KEY>" <PUBLIC_URL>?width=<WIDTH>&height=<HEIGHT>&prompt=<PROMPT>

코드 이해

Modal 플랫폼을 사용하여 Flux.1 이미지 생성 서비스를 실행하는 데 중요한 app.py 파일을 분석해 보겠습니다. 설정 및 기능은 다음과 같습니다.

import modal

image = modal.Image.debian_slim(python_version="3.10").apt_install(
    "libglib2.0-0", 
    "libsm6", 
    "libxrender1", 
    "libxext6", 
    "ffmpeg", 
    "libgl1",
    "git"
).pip_install(
    "git+https://github.com/huggingface/diffusers.git",
    "invisible_watermark",
    "transformers",
    "accelerate",
    "safetensors",
    "sentencepiece",
)

이 블록은 OS, 필요한 라이브러리 및 Python 패키지를 지정하여 애플리케이션에 대한 Docker 이미지를 정의합니다. 이 환경은 Flux.1 모델 및 관련 유틸리티의 실행을 지원합니다.

app = modal.App('flux1')

with image.imports():
    import os
    import io
    import torch
    from diffusers import FluxPipeline
    from fastapi import Response, Header

Here, we initialize our app and import necessary Python libraries within the context of our previously defined Docker image. These imports are essential for image processing and handling web requests.

@app.cls(gpu=modal.gpu.A100(), container_idle_timeout=15, image=image, timeout=120, secrets=[modal.Secret.from_name("flux.1-secret")])
class Model:
    @modal.build()
    def build(self):
        from huggingface_hub import snapshot_download

        snapshot_download("black-forest-labs/FLUX.1-schnell")

    @modal.enter()
    def enter(self):
        print("Loading model...")
        self.pipeline = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to('cuda')
        print("Model loaded!")

    def inference(self, prompt: str, width: int = 1440, height: int = 1440):
        print("Generating image...")
        image = self.pipeline(
            prompt, 
            output_type='pil', 
            width=width, 
            height=height, 
            num_inference_steps=8,
            generator=torch.Generator("cpu").manual_seed(
                torch.randint(0, 1000000, (1,)).item()
            )
        ).images[0]

        print("Image generated!")

        byte_stream = io.BytesIO()
        image.save(byte_stream, format="PNG")

        return byte_stream.getvalue()

    @modal.web_endpoint(docs=True)
    def web_inference(self, prompt: str, width: int = 1440, height: int = 1440, x_api_key: str = Header(None)):
        api_key = os.getenv("API_KEY")
        if x_api_key != api_key:
            return Response(content="Unauthorized", status_code=401)

        image = self.inference(prompt, width, height)
        return Response(content=image, media_type="image/png")

This section defines the main functionality of our service:

  • @modal.build(): Downloads the model when the application builds.
  • @modal.enter(): Loads the model into GPU memory the first time the service is invoked.
  • @modal.web_endpoint(): Serves as the web endpoint for our service using FastAPI.

If you just want to run it as a local service, you can add @modal.method() and define it as following inside the class.

        @modal.method()
    def _inference(self, prompt: str, width: int = 1440, height: int = 1440):
        return self.inference(prompt, width, height)

And outside it, define a local entry point

@app.local_entrypoint()
def main(prompt: str = "A beautiful sunset over the mountains"):
    image_bytes = Model()._inference.remote(prompt)

    with open("output.png", "wb") as f:
        f.write(image_bytes)

Local entry point will run locally on your machine calling the _inference method remotely, so you still using the modal’s service, without exposing it to the internet.

Conclusion

Flux.1 is not just another tech breakthrough - it's a game-changer for anyone who's ever dreamed of bringing their ideas to life visually. Imagine being able to describe a scene in words and watch as it materializes into a stunning, detailed image right before your eyes. That's the magic of Flux.1. It's like having a super-talented artist at your fingertips, ready to paint your thoughts with incredible precision. Whether you're an artist looking to speed up your creative process, a designer in need of quick visual concepts, or just someone who loves playing with new tech, Flux.1 opens up a world of possibilities. It's not about replacing human creativity - it's about enhancing it, making the journey from imagination to reality smoother and more exciting than ever before.

위 내용은 FLUXor Free를 실행하는 방법: 단계별 가이드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.