seokhyun119 commited on
Commit
cff38af
·
1 Parent(s): f9db119

4컷 이미지 생성 모델

Browse files
Files changed (1) hide show
  1. manual_4cut_comic.py +41 -0
manual_4cut_comic.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline
2
+ import torch
3
+ from PIL import Image
4
+ import os
5
+
6
+ # 이미지 생성 파이프라인
7
+ image_gen = StableDiffusionPipeline.from_pretrained(
8
+ "CompVis/stable-diffusion-v1-4",
9
+ torch_dtype=torch.float16,
10
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
11
+
12
+ def generate_comic_manual(cuts, output_dir="comic_outputs"):
13
+ """
14
+ cuts: 4개의 텍스트(컷 설명)가 담긴 리스트
15
+ """
16
+ if len(cuts) != 4:
17
+ raise ValueError("정확히 4개의 컷 설명을 입력해주세요.")
18
+
19
+ os.makedirs(output_dir, exist_ok=True)
20
+
21
+ image_paths = []
22
+ for i, cut in enumerate(cuts):
23
+ print(f"컷 {i+1}: {cut}")
24
+ image = image_gen(cut).images[0]
25
+ path = os.path.join(output_dir, f"cut_{i+1}.png")
26
+ image.save(path)
27
+ image_paths.append(path)
28
+
29
+ print(f"\n✅ 저장 완료! 총 {len(image_paths)}장의 컷이 생성되었습니다.")
30
+ return image_paths
31
+
32
+ # 사용 예시
33
+ if __name__ == "__main__":
34
+ cuts = [
35
+ "A cat launches in a rocket into space",
36
+ "A cat arrives on an alien planet",
37
+ "The cat meets a robot friend",
38
+ "The cat returns to Earth and writes in a diary"
39
+ ]
40
+
41
+ generate_comic_manual(cuts)