Spaces:
Sleeping
Sleeping
File size: 1,170 Bytes
9e02238 bc300ed 9e02238 bc300ed 9e02238 bc300ed 9e02238 bc300ed 9e02238 bc300ed 9e02238 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr
# ๋ชจ๋ธ ๋ก๋ (๋ก์ปฌ์ ์์ ๊ฒฝ์ฐ ํ๊น
ํ์ด์ค์์ ์๋ ๋ค์ด๋ก๋๋จ)
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
revision="fp16" if torch.cuda.is_available() else None,
use_safetensors=True
)
# GPU ์ฌ์ฉ ๊ฐ๋ฅํ๋ฉด ์ด๋
if torch.cuda.is_available():
pipe = pipe.to("cuda")
else:
pipe = pipe.to("cpu")
# ์์ฑ ํจ์
def generate_image(prompt):
result = pipe(prompt, guidance_scale=7.5)
image = result.images[0]
return image
# Gradio ์ธํฐํ์ด์ค
demo = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์", placeholder="์: A fantasy landscape with flying whales"),
outputs=gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง"),
title="๐ผ๏ธ Text to Image Generator (Stable Diffusion)",
description="ํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด ์ธ๊ณต์ง๋ฅ์ด ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค. ๋ชจ๋ธ: runwayml/stable-diffusion-v1-5"
)
# ์คํ
if __name__ == "__main__":
demo.launch()
|