seawolf2357 commited on
Commit
78a8f9f
·
verified ·
1 Parent(s): c4d1de2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -56,25 +56,26 @@ model = model.cuda()
56
  # 번역 모델 초기화
57
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
58
 
 
 
 
 
59
  # FLUX 모델 설정
60
- device = "cpu" # 초기에 CPU에 로드
61
- dtype = torch.float32 # float32 사용
62
 
63
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype)
 
64
 
65
- # 메모리 사용량 최적화
66
  if torch.cuda.is_available():
67
- pipe.enable_sequential_cpu_offload()
68
- pipe.enable_attention_slicing(1)
69
 
70
  @spaces.GPU(duration=300)
71
- def infer_t2i(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
72
  if randomize_seed:
73
  seed = random.randint(0, MAX_SEED)
74
- generator = torch.Generator().manual_seed(seed)
75
-
76
- # 추론 시 GPU 사용 (가능한 경우)
77
- device = "cuda" if torch.cuda.is_available() else "cpu"
78
 
79
  with torch.no_grad():
80
  image = pipe(
@@ -235,7 +236,7 @@ with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
235
  t2i_randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
236
  with gr.Row():
237
  t2i_width = gr.Slider(label='Width', minimum=256, maximum=MAX_IMAGE_SIZE, step=64, value=1024)
238
- t2i_height = gr.Slider(label='Height', minimum=256, maximum=MAX_IMAGE_SIZE, step=64, value=1024)
239
  with gr.Row():
240
  t2i_guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=20.0, step=0.1, value=5.0)
241
  t2i_num_inference_steps = gr.Slider(label='Inference Steps', minimum=1, maximum=100, step=1, value=28)
 
56
  # 번역 모델 초기화
57
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
58
 
59
+
60
+ import torch
61
+ from diffusers import DiffusionPipeline
62
+
63
  # FLUX 모델 설정
64
+ device = "cuda" if torch.cuda.is_available() else "cpu"
65
+ dtype = torch.float16 if torch.cuda.is_available() else torch.float32
66
 
67
  pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype)
68
+ pipe = pipe.to(device)
69
 
70
+ # 메모리 최적화 (GPU 사용 시에만 적용)
71
  if torch.cuda.is_available():
72
+ pipe.enable_attention_slicing()
 
73
 
74
  @spaces.GPU(duration=300)
75
+ def infer_t2i(prompt, seed=42, randomize_seed=False, width=1024, height=576, guidance_scale=5.0, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
76
  if randomize_seed:
77
  seed = random.randint(0, MAX_SEED)
78
+ generator = torch.Generator(device=device).manual_seed(seed)
 
 
 
79
 
80
  with torch.no_grad():
81
  image = pipe(
 
236
  t2i_randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
237
  with gr.Row():
238
  t2i_width = gr.Slider(label='Width', minimum=256, maximum=MAX_IMAGE_SIZE, step=64, value=1024)
239
+ t2i_height = gr.Slider(label='Height', minimum=256, maximum=MAX_IMAGE_SIZE, step=64, value=576)
240
  with gr.Row():
241
  t2i_guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=20.0, step=0.1, value=5.0)
242
  t2i_num_inference_steps = gr.Slider(label='Inference Steps', minimum=1, maximum=100, step=1, value=28)