Spaces:
Sleeping
Sleeping
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() | |