Buckets:

mishig's picture
download
raw
30.5 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Các pipeline Stable Diffusion&quot;,&quot;local&quot;:&quot;stable-diffusion-pipelines&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Mẹo&quot;,&quot;local&quot;:&quot;tips&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Khám phá sự đánh đổi giữa tốc độ và chất lượng&quot;,&quot;local&quot;:&quot;explore-tradeoff-between-speed-and-quality&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Tái sử dụng các thành phần pipeline để tiết kiệm bộ nhớ&quot;,&quot;local&quot;:&quot;reuse-pipeline-components-to-save-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Tạo demo web bằng gradio&quot;,&quot;local&quot;:&quot;create-web-demos-using-gradio&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/yxSHiGDF.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/CPfOwUO_.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/BYe-f74j.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/D32hXVzh.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DqpuBF3n.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dyp9xKq8.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/12.PfUcB_MD.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dk44y1gU.js" rel="modulepreload">
<!--17yjmkr--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Stable Diffusion pipelines&quot;,&quot;local&quot;:&quot;stable-diffusion-pipelines&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Tips&quot;,&quot;local&quot;:&quot;tips&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Explore tradeoff between speed and quality&quot;,&quot;local&quot;:&quot;explore-tradeoff-between-speed-and-quality&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Reuse pipeline components to save memory&quot;,&quot;local&quot;:&quot;reuse-pipeline-components-to-save-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Create web demos using gradio&quot;,&quot;local&quot;:&quot;create-web-demos-using-gradio&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="stable-diffusion-pipelines" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#stable-diffusion-pipelines"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Các pipeline Stable Diffusion<!----></span></h1><!--]--><!----> <div class="flex flex-wrap space-x-1"><img alt="LoRA" src="https://img.shields.io/badge/LoRA-d8b4fe?style=flat"/></div> <p>Stable Diffusion là mô hình khuếch tán tiềm ẩn (latent diffusion) từ văn bản sang hình ảnh do các nhà nghiên cứu và kỹ sư từ <a href="https://github.com/CompVis" rel="nofollow">CompVis</a>, <a href="https://stability.ai/" rel="nofollow">Stability AI</a> và <a href="https://laion.ai/" rel="nofollow">LAION</a> tạo ra. Khuếch tán tiềm ẩn áp dụng quá trình khuếch tán trên không gian tiềm ẩn có số chiều thấp hơn để giảm độ phức tạp về bộ nhớ và tính toán. Loại mô hình khuếch tán cụ thể này được đề xuất trong <a href="https://huggingface.co/papers/2112.10752" rel="nofollow">High-Resolution Image Synthesis with Latent Diffusion Models</a> bởi Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer.</p> <p>Stable Diffusion được huấn luyện trên các ảnh 512x512 từ một tập con của bộ dữ liệu LAION-5B. Mô hình này sử dụng text encoder CLIP ViT-L/14 đã đóng băng để điều kiện hóa mô hình dựa trên các text prompt. Với UNet 860M và text encoder 123M, mô hình tương đối nhẹ và có thể chạy trên các GPU dành cho người tiêu dùng.</p> <p>Để biết thêm chi tiết về cách Stable Diffusion hoạt động và cách nó khác biệt so với mô hình latent diffusion cơ bản, hãy xem <a href="https://stability.ai/blog/stable-diffusion-announcement" rel="nofollow">thông báo</a> của Stability AI và <a href="https://huggingface.co/blog/stable_diffusion#how-does-stable-diffusion-work" rel="nofollow">bài viết trên blog</a> của chúng tôi để có thêm thông tin kỹ thuật.</p> <p>Bạn có thể tìm thấy mã nguồn gốc của Stable Diffusion v1.0 tại <a href="https://github.com/CompVis/stable-diffusion" rel="nofollow">CompVis/stable-diffusion</a> và Stable Diffusion v2.0 tại Stability-AI/stablediffusion, cùng với các script gốc cho các tác vụ khác nhau. Các checkpoint chính thức bổ sung cho các phiên bản và tác vụ khác nhau của Stable Diffusion có thể được tìm thấy trên các tổ chức <a href="https://huggingface.co/CompVis" rel="nofollow">CompVis</a> và <a href="https://huggingface.co/stabilityai" rel="nofollow">Stability AI</a> trên Hub. Hãy khám phá các tổ chức này để tìm checkpoint phù hợp nhất cho trường hợp sử dụng của bạn!</p> <p>Bảng dưới đây tóm tắt các pipeline Stable Diffusion khả dụng, các tác vụ được hỗ trợ và một demo tương tác:</p> <div class="flex justify-center"><div class="rounded-xl border border-gray-200"><table class="min-w-full divide-y-2 divide-gray-200 bg-white text-sm"><thead><tr><th class="px-4 py-2 font-medium text-gray-900 text-left">Pipeline</th><th class="px-4 py-2 font-medium text-gray-900 text-left">Các tác vụ được hỗ trợ</th><th class="px-4 py-2 font-medium text-gray-900 text-left">🤗 Space</th></tr></thead><tbody class="divide-y divide-gray-200"><tr><td class="px-4 py-2 text-gray-700"><a href="./text2img">StableDiffusion</a></td><td class="px-4 py-2 text-gray-700">text-to-image</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/stabilityai/stable-diffusion"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./img2img">StableDiffusionImg2Img</a></td><td class="px-4 py-2 text-gray-700">image-to-image</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/huggingface/diffuse-the-rest"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./inpaint">StableDiffusionInpaint</a></td><td class="px-4 py-2 text-gray-700">inpainting</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/stable-diffusion-v1-5/stable-diffusion-inpainting"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./depth2img">StableDiffusionDepth2Img</a></td><td class="px-4 py-2 text-gray-700">depth-to-image</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/radames/stable-diffusion-depth2img"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./image_variation">StableDiffusionImageVariation</a></td><td class="px-4 py-2 text-gray-700">biến thể hình ảnh</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/lambdalabs/stable-diffusion-image-variations"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700">StableDiffusionPipelineSafe (không còn được hỗ trợ; không có trang tài liệu)</td><td class="px-4 py-2 text-gray-700">chuyển văn bản thành ảnh đã lọc</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/AIML-TUDA/unsafe-vs-safe-stable-diffusion"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./stable_diffusion_2">StableDiffusion2</a></td><td class="px-4 py-2 text-gray-700">tạo ảnh từ văn bản, inpainting, tạo ảnh từ độ sâu, siêu phân giải</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/stabilityai/stable-diffusion"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./stable_diffusion_xl">StableDiffusionXL</a></td><td class="px-4 py-2 text-gray-700">chuyển văn bản thành hình ảnh, chuyển hình ảnh thành hình ảnh</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/RamAnanth1/stable-diffusion-xl"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./latent_upscale">StableDiffusionLatentUpscale</a></td><td class="px-4 py-2 text-gray-700">super-resolution</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/huggingface-projects/stable-diffusion-latent-upscaler"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./upscale">StableDiffusionUpscale</a></td><td class="px-4 py-2 text-gray-700">super-resolution</td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./ldm3d_diffusion">StableDiffusionLDM3D</a></td><td class="px-4 py-2 text-gray-700">tạo ảnh màu từ văn bản, tạo ảnh độ sâu từ văn bản, tạo ảnh toàn cảnh từ văn bản</td><td class="px-4 py-2"><a href="https://huggingface.co/spaces/r23/ldm3d-space"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue"/></a></td></tr><tr><td class="px-4 py-2 text-gray-700"><a href="./ldm3d_diffusion">StableDiffusionUpscaleLDM3D</a></td><td class="px-4 py-2 text-gray-700">ldm3d siêu phân giải</td></tr></tbody></table></div></div> <!--[1--><h2 class="relative group"><a id="tips" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#tips"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Mẹo<!----></span></h2><!--]--><!----> <p>Để giúp bạn tận dụng tối đa các pipeline của Stable Diffusion, dưới đây là một số mẹo để cải thiện hiệu suất và khả năng sử dụng. Các mẹo này áp dụng cho tất cả các pipeline của Stable Diffusion.</p> <!--[2--><h3 class="relative group"><a id="explore-tradeoff-between-speed-and-quality" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#explore-tradeoff-between-speed-and-quality"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Khám phá sự đánh đổi giữa tốc độ và chất lượng<!----></span></h3><!--]--><!----> <p><a href="/docs/diffusers/main/vi/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> sử dụng <a href="/docs/diffusers/main/vi/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a> theo mặc định, nhưng 🤗 Diffusers cung cấp nhiều scheduler khác (một số nhanh hơn hoặc cho chất lượng đầu ra tốt hơn) tương thích. Ví dụ, nếu bạn muốn sử dụng <a href="/docs/diffusers/main/vi/api/schedulers/euler#diffusers.EulerDiscreteScheduler">EulerDiscreteScheduler</a> thay vì mặc định:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline, EulerDiscreteScheduler
pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-comment"># or</span>
euler_scheduler = EulerDiscreteScheduler.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, subfolder=<span class="hljs-string">&quot;scheduler&quot;</span>)
pipeline = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, scheduler=euler_scheduler)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="reuse-pipeline-components-to-save-memory" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#reuse-pipeline-components-to-save-memory"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Tái sử dụng các thành phần pipeline để tiết kiệm bộ nhớ<!----></span></h3><!--]--><!----> <p>Để tiết kiệm bộ nhớ và sử dụng cùng các thành phần cho nhiều pipeline khác nhau, hãy dùng phương thức <code>.components</code> để tránh nạp trọng số vào RAM nhiều hơn một lần.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> (
StableDiffusionPipeline,
StableDiffusionImg2ImgPipeline,
StableDiffusionInpaintPipeline,
)
text2img = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
img2img = StableDiffusionImg2ImgPipeline(**text2img.components)
inpaint = StableDiffusionInpaintPipeline(**text2img.components)
<span class="hljs-comment"># now you can use text2img(...), img2img(...), inpaint(...) just like the call methods of each respective pipeline</span><!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="create-web-demos-using-gradio" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#create-web-demos-using-gradio"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Tạo demo web bằng gradio<!----></span></h3><!--]--><!----> <p>Các pipeline Stable Diffusion được hỗ trợ tự động trong <a href="https://github.com/gradio-app/gradio/" rel="nofollow">Gradio</a>, một thư viện giúp việc tạo các ứng dụng machine learning trên web đẹp mắt và thân thiện với người dùng trở nên dễ dàng. Trước tiên, hãy đảm bảo bạn đã cài đặt Gradio:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-sh "><!---->pip install -U gradio<!----></pre></div><!----> <p>Sau đó, hãy tạo một demo web xung quanh bất kỳ pipeline nào dựa trên Stable Diffusion. Ví dụ, bạn có thể tạo một pipeline tạo ảnh chỉ với một dòng mã bằng cách sử dụng hàm <a href="https://www.gradio.app/docs/interface#interface-from-pipeline" rel="nofollow"><code>Interface.from_pipeline</code></a> của Gradio:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr
pipe = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
gr.Interface.from_pipeline(pipe).launch()<!----></pre></div><!----> <p>mở ra một giao diện kéo-thả trực quan trong trình duyệt của bạn:</p> <p><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/gradio-panda.png"/></p> <p>Tương tự, bạn có thể tạo một demo cho pipeline image-to-image với:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Đã sao chép</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionImg2ImgPipeline
<span class="hljs-keyword">import</span> gradio <span class="hljs-keyword">as</span> gr
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(<span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>)
gr.Interface.from_pipeline(pipe).launch()<!----></pre></div><!----> <p>Mặc định, bản demo web chạy trên một máy chủ cục bộ. Nếu bạn muốn chia sẻ với người khác, bạn có thể tạo một liên kết công khai tạm thời bằng cách đặt <code>share=True</code> trong <code>launch()</code>. Hoặc, bạn có thể lưu trữ demo của mình trên <a href="https://huggingface.co/spaces" rel="nofollow">Hugging Face Spaces</a><a href="https://huggingface.co/spaces" rel="nofollow">https://huggingface.co/spaces</a> để có một liên kết vĩnh viễn.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/stable_diffusion/overview.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_gxjg5b = {
base: "/docs/diffusers/main/en",
assets: "/docs/diffusers/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js"),
import("/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 12],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
30.5 kB
·
Xet hash:
0734c25707c5595f1b0c09fc605c50a275f55fe4c55bdf9e7a3be0f911144f47

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.