openfree commited on
Commit
267d71c
1 Parent(s): ef3fbda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -24,7 +24,7 @@ import warnings
24
  huggingface_token = os.getenv("HUGGINFACE_TOKEN")
25
 
26
  # 번역 모델 로드
27
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
28
 
29
  #Load prompts for randomization
30
  df = pd.read_csv('prompts.csv', header=None)
@@ -40,12 +40,12 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
40
 
41
  # 공통 FLUX 모델 로드
42
  base_model = "black-forest-labs/FLUX.1-dev"
43
- pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype, device_map="balanced").to(device)
44
-
45
 
46
  # LoRA를 위한 설정
47
- taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
48
- good_vae = AutoencoderKL.from_pretrained(base_model, subfolder="vae", torch_dtype=dtype).to(device)
49
 
50
  # Image-to-Image 파이프라인 설정
51
  pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
@@ -56,14 +56,12 @@ pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
56
  tokenizer=pipe.tokenizer,
57
  text_encoder_2=pipe.text_encoder_2,
58
  tokenizer_2=pipe.tokenizer_2,
59
- torch_dtype=dtype,
60
- device_map="balanced"
61
- ).to(device)
62
 
63
  controlnet = FluxControlNetModel.from_pretrained(
64
  "jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
65
- ).to(device)
66
-
67
 
68
  # Upscale 파이프라인 설정 (기존 pipe 재사용)
69
  pipe_upscale = FluxControlNetPipeline(
@@ -74,9 +72,13 @@ pipe_upscale = FluxControlNetPipeline(
74
  scheduler=pipe.scheduler,
75
  safety_checker=pipe.safety_checker,
76
  feature_extractor=pipe.feature_extractor,
77
- controlnet=controlnet,
78
- device_map="balanced"
79
- ).to(device)
 
 
 
 
80
 
81
 
82
 
 
24
  huggingface_token = os.getenv("HUGGINFACE_TOKEN")
25
 
26
  # 번역 모델 로드
27
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device=0 if torch.cuda.is_available() else -1)
28
 
29
  #Load prompts for randomization
30
  df = pd.read_csv('prompts.csv', header=None)
 
40
 
41
  # 공통 FLUX 모델 로드
42
  base_model = "black-forest-labs/FLUX.1-dev"
43
+ pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype)
44
+ pipe.to(device) # 여기서 한 번만 device로 이동
45
 
46
  # LoRA를 위한 설정
47
+ taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype)
48
+ good_vae = AutoencoderKL.from_pretrained(base_model, subfolder="vae", torch_dtype=dtype)
49
 
50
  # Image-to-Image 파이프라인 설정
51
  pipe_i2i = AutoPipelineForImage2Image.from_pretrained(
 
56
  tokenizer=pipe.tokenizer,
57
  text_encoder_2=pipe.text_encoder_2,
58
  tokenizer_2=pipe.tokenizer_2,
59
+ torch_dtype=dtype
60
+ )
 
61
 
62
  controlnet = FluxControlNetModel.from_pretrained(
63
  "jasperai/Flux.1-dev-Controlnet-Upscaler", torch_dtype=torch.bfloat16
64
+ )
 
65
 
66
  # Upscale 파이프라인 설정 (기존 pipe 재사용)
67
  pipe_upscale = FluxControlNetPipeline(
 
72
  scheduler=pipe.scheduler,
73
  safety_checker=pipe.safety_checker,
74
  feature_extractor=pipe.feature_extractor,
75
+ controlnet=controlnet
76
+ )
77
+
78
+ # 모든 파이프라인을 device로 이동
79
+ pipe_i2i.to(device)
80
+ controlnet.to(device)
81
+ pipe_upscale.to(device)
82
 
83
 
84