Spaces:
Runtime error
Runtime error
| 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) | |