Spaces:
Sleeping
Sleeping
File size: 1,219 Bytes
cff38af |
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 38 39 40 41 42 |
from diffusers import StableDiffusionPipeline
import torch
from PIL import Image
import os
# ์ด๋ฏธ์ง ์์ฑ ํ์ดํ๋ผ์ธ
image_gen = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
torch_dtype=torch.float16,
).to("cuda" if torch.cuda.is_available() else "cpu")
def generate_comic_manual(cuts, output_dir="comic_outputs"):
"""
cuts: 4๊ฐ์ ํ
์คํธ(์ปท ์ค๋ช
)๊ฐ ๋ด๊ธด ๋ฆฌ์คํธ
"""
if len(cuts) != 4:
raise ValueError("์ ํํ 4๊ฐ์ ์ปท ์ค๋ช
์ ์
๋ ฅํด์ฃผ์ธ์.")
os.makedirs(output_dir, exist_ok=True)
image_paths = []
for i, cut in enumerate(cuts):
print(f"์ปท {i+1}: {cut}")
image = image_gen(cut).images[0]
path = os.path.join(output_dir, f"cut_{i+1}.png")
image.save(path)
image_paths.append(path)
print(f"\nโ
์ ์ฅ ์๋ฃ! ์ด {len(image_paths)}์ฅ์ ์ปท์ด ์์ฑ๋์์ต๋๋ค.")
return image_paths
# ์ฌ์ฉ ์์
if __name__ == "__main__":
cuts = [
"A cat launches in a rocket into space",
"A cat arrives on an alien planet",
"The cat meets a robot friend",
"The cat returns to Earth and writes in a diary"
]
generate_comic_manual(cuts)
|