Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
| 1914 |
-
logger.info(
|
| 1915 |
-
|
| 1916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1917 |
selected_image = None
|
| 1918 |
-
|
| 1919 |
-
|
| 1920 |
-
if i % 2 == 0 and image_count_3d < max_images_per_api:
|
| 1921 |
-
|
| 1922 |
-
if
|
| 1923 |
-
selected_image =
|
| 1924 |
image_count_3d += 1
|
| 1925 |
-
|
| 1926 |
-
|
| 1927 |
-
|
| 1928 |
-
|
|
|
|
|
|
|
| 1929 |
image_count_flux += 1
|
| 1930 |
-
|
|
|
|
| 1931 |
if selected_image and os.path.exists(selected_image):
|
| 1932 |
try:
|
| 1933 |
-
|
| 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:
|