seawolf2357 commited on
Commit
52428d9
·
verified ·
1 Parent(s): 0ca8900

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -54,11 +54,12 @@ model = model.cuda()
54
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
55
 
56
  # FLUX 모델 설정
57
- dtype = torch.bfloat16
58
  device = "cuda" if torch.cuda.is_available() else "cpu"
59
 
 
 
60
 
61
- pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16, device_map="auto")
62
 
63
  MAX_SEED = np.iinfo(np.int32).max
64
  MAX_IMAGE_SIZE = 2048
@@ -67,17 +68,16 @@ MAX_IMAGE_SIZE = 2048
67
  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)):
68
  if randomize_seed:
69
  seed = random.randint(0, MAX_SEED)
70
- generator = torch.Generator().manual_seed(seed)
71
  with torch.cuda.amp.autocast():
72
- image = pipe.to("cuda")(
73
- prompt = prompt,
74
- width = width,
75
- height = height,
76
- num_inference_steps = num_inference_steps,
77
- generator = generator,
78
  guidance_scale=guidance_scale
79
  ).images[0]
80
- pipe.to("cpu")
81
  torch.cuda.empty_cache()
82
  return image, seed
83
 
 
54
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
55
 
56
  # FLUX 모델 설정
57
+ dtype = torch.float16 # bfloat16 대신 float16 사용
58
  device = "cuda" if torch.cuda.is_available() else "cpu"
59
 
60
+ pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype)
61
+ pipe = pipe.to(device)
62
 
 
63
 
64
  MAX_SEED = np.iinfo(np.int32).max
65
  MAX_IMAGE_SIZE = 2048
 
68
  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)):
69
  if randomize_seed:
70
  seed = random.randint(0, MAX_SEED)
71
+ generator = torch.Generator(device=device).manual_seed(seed)
72
  with torch.cuda.amp.autocast():
73
+ image = pipe(
74
+ prompt=prompt,
75
+ width=width,
76
+ height=height,
77
+ num_inference_steps=num_inference_steps,
78
+ generator=generator,
79
  guidance_scale=guidance_scale
80
  ).images[0]
 
81
  torch.cuda.empty_cache()
82
  return image, seed
83