Kims12 commited on
Commit
23c68d9
·
verified ·
1 Parent(s): 286eab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -210,9 +210,19 @@ def generate_with_images(prompt, images, variation_index=0):
210
  logger.info("응답에서 이미지 추출 성공")
211
  if not image_found:
212
  return None, f"API에서 이미지를 생성하지 못했습니다. 응답 텍스트: {result_text}"
 
 
213
  result_img = Image.open(temp_path)
214
  if result_img.mode == "RGBA":
215
- result_img = result_img.convert("RGB")
 
 
 
 
 
 
 
 
216
  return result_img, f"이미지가 성공적으로 생성되었습니다. {result_text}"
217
  except Exception as e:
218
  logger.exception("이미지 생성 중 오류 발생:")
 
210
  logger.info("응답에서 이미지 추출 성공")
211
  if not image_found:
212
  return None, f"API에서 이미지를 생성하지 못했습니다. 응답 텍스트: {result_text}"
213
+
214
+ # 여기서 이미지를 JPG로 변환합니다
215
  result_img = Image.open(temp_path)
216
  if result_img.mode == "RGBA":
217
+ result_img = result_img.convert("RGB") # RGBA를 RGB로 변환 (JPG는 알파 채널을 지원하지 않음)
218
+
219
+ # 이미지를 JPG로 저장
220
+ jpg_temp = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False).name
221
+ result_img.save(jpg_temp, format="JPEG", quality=95)
222
+
223
+ # JPG 이미지를 다시 로드
224
+ result_img = Image.open(jpg_temp)
225
+
226
  return result_img, f"이미지가 성공적으로 생성되었습니다. {result_text}"
227
  except Exception as e:
228
  logger.exception("이미지 생성 중 오류 발생:")