FLUXor を無料で実行する方法: ステップバイステップ ガイド

PHPz
リリース: 2024-09-10 06:33:02
オリジナル
380 人が閲覧しました

Flux.1 は、Black Forest Labs によって提供された、市場で最新のテキストから画像への変換モデルです。複雑な説明を処理し、細部まで精細な高画質画像を生成するテキスト記述から高画質画像を生成できる最先端モデルです。

Flux.1 の背後にいるのは誰ですか?

Flux.1 は、Stability AI の元従業員のグループによって設立された会社、Black Forest Labs によって開発されました。

どのように機能するのでしょうか?

ランダムな開始点から徐々にノイズを除去して画像を作成する安定拡散などの他の拡散モデルとは異なり、Flux.1 は、より直接的なアプローチをとる「フロー マッチング」と呼ばれる技術を使用して画像を生成し、必要な正確な変換を学習します。ノイズをリアルな画像に変換します。これにより、一般的な拡散モデルよりも少ない手順で高速に高品質の画像を生成できます。

また、この異なるアプローチにより、Flux.1 は以下のようなテキストを含む画像を処理できます。

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

モダンで洗練されたラップトップのフォトリアリスティックな画像。Web ページが開いており、クリーンでミニマルなデザインで「codestackme」というテキストが表示されています。ノートパソコンは、柔らかい照明が当たる白い机の上に置き、画面の輝きと金属製の筐体の微妙な反射を強調する必要があります。全体的な雰囲気は、革新性と技術の進歩の感覚を伝える、プロフェッショナルで魅力的なものである必要があります。

Flux.1 用の適切なプロンプトを作成するにはどうすればよいですか?

Flux.1 の傑出した機能の 1 つは、ユーザーフレンドリーなプロンプト メカニズムです。 CLIP (OpenAI 製) および T5 (GoogleAI 製) テキスト エンコーダの統合により、モデルは高度なニュアンスで説明を解釈できます。 CLIP はテキストとビジュアル コンテンツの位置合わせに優れており、T5 は構造化テキスト入力を処理するモデルの機能を強化します。これらを組み合わせることで、Flux.1 はユーザーが提供する詳細なプロンプトに厳密に一致する画像を生成できるようになります。

Flux.1にはどのような種類のモデルがありますか?

Flux.1 には、Schnell、Dev、Pro の 3 つの異なるバージョンがあります。

  • Schnell は、速度と効率が最適化された最速のモデルです。 Apache 2.0 ライセンスに基づいてリリースされているため、商用利用が許可されています。
  • Dev は、より柔軟で実験的なフレームワークを提供し、モデルの特定の機能を微調整またはカスタマイズしたい開発者や研究者に焦点を当てています。非営利ライセンスでリリースされました。
  • Pro は、最も高度でリソースを大量に消費するバージョンです。これは高解像度の出力を提供し、より複雑な画像を生成できますが、Black Forest Labs API を通じてのみ利用可能です。

Flux.1を無料で使うには?

金銭的な負担をかけずに Flux.1 の機能を探索することに興味がある人にとって、リソース プロバイダーとして modal.com を使用することは実行可能なオプションです。 Modal.com では、毎月 30 ドルの計算能力許容量を提供しており、これにより毎月多数のイメージの生成をサポートできます。価格とサービスの詳細については、Modal.com Pricing をご覧ください。

この推奨事項はプラットフォームによって後援または承認されていません。

まず、GitHub 認証情報を使用してログインし、modal.com でアカウントを作成する必要があります。

次に、Modal CLI をインストールする必要があります。 Python がコンピュータにインストールされていることを確認してください。 Python がセットアップされたら、ターミナルを開いてコマンド pip install modal を実行します。インストールが完了したら、モーダル セットアップを実行して、CLI をモーダル アカウントにリンクします。

この GitHub リポジトリをコンピュータに複製して、複製されたディレクトリに移動します。

セキュリティのため、API_KEY という名前の環境変数を使用してモーダル ダッシュボードに flux.1-secret というシークレットを作成し、それにランダムな文字列を割り当てます。

最後に、ターミナルで modaldeploy app.py --name flux1 を実行してサービスをデプロイします。デプロイが成功すると、モーダルは Web サービスにアクセスするための 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>
ログイン後にコピー

コードを理解する

app.py ファイルを分析してみましょう。このファイルは、モーダルのプラットフォームを使用して Flux.1 画像生成サービスを実行するために重要です。セットアップと機能の内訳は次のとおりです:

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 を無料で実行する方法: ステップバイステップ ガイドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:dev.to
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!