openfree commited on
Commit
a7df2d2
ยท
verified ยท
1 Parent(s): 84b7bf2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -21
app.py CHANGED
@@ -651,7 +651,12 @@ EXAMPLE_PROMPTS: dict[str, str] = {
651
  }
652
  STYLE_KEYS = list(EXAMPLE_PROMPTS.keys())
653
 
654
-
 
 
 
 
 
655
 
656
  # ------------------------------------------------------------------
657
  # 2) generate_flux_prompt ํ•จ์ˆ˜ ์ „์ฒด โ˜… ์ˆ˜์ • ์™„๋ฃŒ
@@ -1908,39 +1913,57 @@ def create_advanced_ppt_from_content(
1908
  pass
1909
  except Exception as e:
1910
  logger.error(f"Failed to add conclusion image: {e}")
1911
-
1912
  elif visual_type[0] == 'diverse_images':
1913
- # ๋‹ค์–‘ํ•œ ์Šฌ๋ผ์ด๋“œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ (API๋ณ„ ์ œํ•œ ํ™•์ธ)
1914
- logger.info(f"Generating diverse images for slide {i+1} (3D: {image_count_3d}/{max_images_per_api}, FLUX: {image_count_flux}/{max_images_per_api})")
1915
- prompt_3d, prompt_photo = generate_diverse_prompt(slide_title, slide_content, i)
1916
-
 
 
 
 
 
 
 
 
 
 
1917
  selected_image = None
1918
-
1919
- # API๋ณ„ ์ œํ•œ์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
1920
- if i % 2 == 0 and image_count_3d < max_images_per_api:
1921
- image_3d = generate_ai_image_via_3d_api(prompt_3d)
1922
- if image_3d:
1923
- selected_image = image_3d
1924
  image_count_3d += 1
1925
- elif image_count_flux < max_images_per_api:
1926
- image_photo = generate_flux_image_via_api(prompt_photo)
1927
- if image_photo:
1928
- selected_image = image_photo
 
 
1929
  image_count_flux += 1
1930
-
 
1931
  if selected_image and os.path.exists(selected_image):
1932
  try:
1933
- pic = slide.shapes.add_picture(
1934
  selected_image,
1935
  Inches(5.2), Inches(1.5),
1936
  width=Inches(4.3), height=Inches(3.0)
1937
  )
1938
  visual_added = True
1939
-
1940
- if selected_image:
1941
- os.unlink(selected_image)
1942
  except Exception as e:
1943
  logger.error(f"Failed to add slide image: {e}")
 
 
 
 
 
 
 
 
1944
 
1945
  # ์‹œ๊ฐ์  ์š”์†Œ๊ฐ€ ์ถ”๊ฐ€๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ํ”Œ๋ ˆ์ด์Šคํ™€๋” ์ถ”๊ฐ€
1946
  if not visual_added:
 
651
  }
652
  STYLE_KEYS = list(EXAMPLE_PROMPTS.keys())
653
 
654
+ def pick_flux_style(slide_idx: int) -> str:
655
+ """
656
+ ์Šฌ๋ผ์ด๋“œ ๋ฒˆํ˜ธ(i)๋ฅผ 6๊ฐ€์ง€ FLUX ์Šคํƒ€์ผ ํ‚ค
657
+ ('Product Design' โ€ฆ 'Flowchart') ์ค‘ ํ•˜๋‚˜๋กœ ๋งคํ•‘ํ•œ๋‹ค.
658
+ """
659
+ return STYLE_KEYS[slide_idx % len(STYLE_KEYS)]
660
 
661
  # ------------------------------------------------------------------
662
  # 2) generate_flux_prompt ํ•จ์ˆ˜ ์ „์ฒด โ˜… ์ˆ˜์ • ์™„๋ฃŒ
 
1913
  pass
1914
  except Exception as e:
1915
  logger.error(f"Failed to add conclusion image: {e}")
1916
+
1917
  elif visual_type[0] == 'diverse_images':
1918
+ # --- FLUX ๋‹ค์ด์–ด๊ทธ๋žจ(6-style) & 3D ์ด๋ฏธ์ง€ ์ƒ์„ฑ ---
1919
+ logger.info(
1920
+ f"Generating FLUX diagram-style image for slide {i+1} "
1921
+ f"(3D {image_count_3d}/{max_images_per_api}, "
1922
+ f"FLUX {image_count_flux}/{max_images_per_api})"
1923
+ )
1924
+
1925
+ # 3D-API์šฉ(๊ทธ๋ฆผยท์ผ๋Ÿฌ์ŠคํŠธ) ํ”„๋กฌํ”„ํŠธ๋Š” ๊ทธ๋Œ€๋กœ
1926
+ prompt_3d, _ = generate_diverse_prompt(slide_title, slide_content, i)
1927
+
1928
+ # โšก FLUX-API์šฉ ํ”„๋กฌํ”„ํŠธ: 6๊ฐ€์ง€ ๋‹ค์ด์–ด๊ทธ๋žจ ๊ตฌ๋„ ์ค‘ ํ•˜๋‚˜ ์„ ํƒ
1929
+ style_key = pick_flux_style(i) # โ† โ‘  ์ƒˆ ํ•จ์ˆ˜ ์‚ฌ์šฉ
1930
+ prompt_flux = generate_flux_prompt(slide_title, slide_content, style_key)
1931
+
1932
  selected_image = None
1933
+
1934
+ # 3D-API ๋จผ์ € ์‹œ๋„ (์ง์ˆ˜ ์Šฌ๋ผ์ด๋“œ ์šฐ์„ ์ด๋ผ๋Š” ๊ธฐ์กด ์ •์ฑ… ์œ ์ง€)
1935
+ if (i % 2 == 0) and (image_count_3d < max_images_per_api):
1936
+ img_3d = generate_ai_image_via_3d_api(prompt_3d)
1937
+ if img_3d:
1938
+ selected_image = img_3d
1939
  image_count_3d += 1
1940
+
1941
+ # FLUX-API (๋‹ค์ด์–ด๊ทธ๋žจ ์Šคํƒ€์ผ) ์‹œ๋„
1942
+ if (selected_image is None) and (image_count_flux < max_images_per_api):
1943
+ img_flux = generate_flux_image_via_api(prompt_flux)
1944
+ if img_flux:
1945
+ selected_image = img_flux
1946
  image_count_flux += 1
1947
+
1948
+ # ์Šฌ๋ผ์ด๋“œ์— ์‚ฝ์ž…
1949
  if selected_image and os.path.exists(selected_image):
1950
  try:
1951
+ slide.shapes.add_picture(
1952
  selected_image,
1953
  Inches(5.2), Inches(1.5),
1954
  width=Inches(4.3), height=Inches(3.0)
1955
  )
1956
  visual_added = True
 
 
 
1957
  except Exception as e:
1958
  logger.error(f"Failed to add slide image: {e}")
1959
+ finally:
1960
+ # ์ž„์‹œ ํŒŒ์ผ ์ •๋ฆฌ
1961
+ try:
1962
+ os.unlink(selected_image)
1963
+ except:
1964
+ pass
1965
+
1966
+
1967
 
1968
  # ์‹œ๊ฐ์  ์š”์†Œ๊ฐ€ ์ถ”๊ฐ€๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ํ”Œ๋ ˆ์ด์Šคํ™€๋” ์ถ”๊ฐ€
1969
  if not visual_added: