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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import replicate
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
import json
|
6 |
+
import asyncio
|
7 |
+
import concurrent.futures
|
8 |
+
from io import BytesIO
|
9 |
+
from PIL import Image
|
10 |
+
from typing import List, Tuple, Dict
|
11 |
+
import zipfile
|
12 |
+
from datetime import datetime
|
13 |
+
import time
|
14 |
+
import traceback
|
15 |
+
import base64
|
16 |
+
from pptx import Presentation
|
17 |
+
from pptx.util import Inches, Pt
|
18 |
+
from pptx.dml.color import RGBColor
|
19 |
+
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
|
20 |
+
from pptx.enum.shapes import MSO_SHAPE
|
21 |
+
import PyPDF2
|
22 |
+
import pandas as pd
|
23 |
+
import chardet
|
24 |
+
|
25 |
+
# νκ²½ λ³μμμ ν ν° κ°μ Έμ€κΈ°
|
26 |
+
REPLICATE_API_TOKEN = os.getenv("RAPI_TOKEN")
|
27 |
+
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN")
|
28 |
+
BRAVE_API_TOKEN = os.getenv("BAPI_TOKEN")
|
29 |
+
|
30 |
+
# λμμΈ ν
λ§ μ μ
|
31 |
+
DESIGN_THEMES = {
|
32 |
+
"λ―Έλλ© λΌμ΄νΈ": {
|
33 |
+
"name": "Minimal Light",
|
34 |
+
"description": "λ°κ³ κΉ¨λν λ―Έλλ© λμμΈ",
|
35 |
+
"background": RGBColor(250, 250, 252),
|
36 |
+
"title_color": RGBColor(33, 37, 41),
|
37 |
+
"subtitle_color": RGBColor(52, 58, 64),
|
38 |
+
"text_color": RGBColor(73, 80, 87),
|
39 |
+
"accent_color": RGBColor(0, 123, 255),
|
40 |
+
"box_fill": RGBColor(255, 255, 255),
|
41 |
+
"box_opacity": 0.95,
|
42 |
+
"shadow": True,
|
43 |
+
"gradient": False
|
44 |
+
},
|
45 |
+
"λͺ¨λ κ·ΈλΌλμΈνΈ": {
|
46 |
+
"name": "Modern Gradient",
|
47 |
+
"description": "λΆλλ¬μ΄ κ·ΈλΌλμΈνΈμ νλμ λλ",
|
48 |
+
"background": RGBColor(245, 247, 250),
|
49 |
+
"title_color": RGBColor(25, 42, 86),
|
50 |
+
"subtitle_color": RGBColor(68, 85, 102),
|
51 |
+
"text_color": RGBColor(85, 102, 119),
|
52 |
+
"accent_color": RGBColor(103, 58, 183),
|
53 |
+
"box_fill": RGBColor(249, 250, 251),
|
54 |
+
"box_opacity": 0.9,
|
55 |
+
"shadow": True,
|
56 |
+
"gradient": True
|
57 |
+
},
|
58 |
+
"λ€ν¬ μλ κ°μ€": {
|
59 |
+
"name": "Dark Elegance",
|
60 |
+
"description": "μΈλ ¨λ λ€ν¬ λͺ¨λ λμμΈ",
|
61 |
+
"background": RGBColor(25, 25, 35),
|
62 |
+
"title_color": RGBColor(240, 240, 245),
|
63 |
+
"subtitle_color": RGBColor(200, 200, 210),
|
64 |
+
"text_color": RGBColor(170, 170, 180),
|
65 |
+
"accent_color": RGBColor(0, 188, 212),
|
66 |
+
"box_fill": RGBColor(35, 35, 45),
|
67 |
+
"box_opacity": 0.85,
|
68 |
+
"shadow": False,
|
69 |
+
"gradient": False
|
70 |
+
},
|
71 |
+
"λ€μ΄μ² κ·Έλ¦°": {
|
72 |
+
"name": "Nature Green",
|
73 |
+
"description": "μμ° μΉνμ μΈ κ·Έλ¦° ν
λ§",
|
74 |
+
"background": RGBColor(242, 248, 244),
|
75 |
+
"title_color": RGBColor(27, 67, 50),
|
76 |
+
"subtitle_color": RGBColor(45, 106, 79),
|
77 |
+
"text_color": RGBColor(64, 125, 98),
|
78 |
+
"accent_color": RGBColor(76, 175, 80),
|
79 |
+
"box_fill": RGBColor(255, 255, 255),
|
80 |
+
"box_opacity": 0.92,
|
81 |
+
"shadow": True,
|
82 |
+
"gradient": False
|
83 |
+
},
|
84 |
+
"μ½νΌλ μ΄νΈ λΈλ£¨": {
|
85 |
+
"name": "Corporate Blue",
|
86 |
+
"description": "μ λ¬Έμ μΈ λΉμ¦λμ€ μ€νμΌ",
|
87 |
+
"background": RGBColor(244, 247, 252),
|
88 |
+
"title_color": RGBColor(13, 71, 161),
|
89 |
+
"subtitle_color": RGBColor(25, 118, 210),
|
90 |
+
"text_color": RGBColor(42, 63, 84),
|
91 |
+
"accent_color": RGBColor(33, 150, 243),
|
92 |
+
"box_fill": RGBColor(255, 255, 255),
|
93 |
+
"box_opacity": 0.95,
|
94 |
+
"shadow": True,
|
95 |
+
"gradient": False
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
# μ€νμΌ μ μ (νμ§μ μ’
λ£ μ¬λΌμ΄λ μ€νμΌ μΆκ°)
|
100 |
+
STYLE_TEMPLATES = {
|
101 |
+
"Title Slide (Hero)": {
|
102 |
+
"name": "Title Slide",
|
103 |
+
"description": "Impactful hero image for title slide",
|
104 |
+
"use_case": "νμ§, νμ΄ν",
|
105 |
+
"example": "A dramatic wide-angle view of a modern glass skyscraper reaching into clouds with golden sunset lighting, symbolizing growth and ambition. Ultra-realistic photography style, cinematic composition, lens flare, professional corporate aesthetic"
|
106 |
+
},
|
107 |
+
"Thank You Slide": {
|
108 |
+
"name": "Thank You",
|
109 |
+
"description": "Elegant closing slide design",
|
110 |
+
"use_case": "λ§μ§λ§ μΈμ¬",
|
111 |
+
"example": "Abstract elegant background with soft gradient from deep blue to purple, golden particles floating like celebration confetti, subtle light rays, with space for 'Thank You' text. Minimalist, professional, warm feeling"
|
112 |
+
},
|
113 |
+
"3D Style (Pixar-like)": {
|
114 |
+
"name": "3D Style",
|
115 |
+
"description": "Pixar-esque 3D render with volumetric lighting",
|
116 |
+
"use_case": "νμ§, λΉμ , λ―Έλ 컨μ
",
|
117 |
+
"example": "A fluffy ginger cat wearing a tiny spacesuit, floating amidst a vibrant nebula in a 3D render. The cat is gazing curiously at a swirling planet with rings made of candy. Background is filled with sparkling stars and colorful gas clouds, lit with soft, volumetric lighting. Style: Pixar-esque, highly detailed, playful. Colors: Deep blues, purples, oranges, and pinks. Rendered in Octane, 8k resolution."
|
118 |
+
},
|
119 |
+
"Elegant SWOT Quadrant": {
|
120 |
+
"name": "SWOT Analysis",
|
121 |
+
"description": "Flat-design 4-grid layout with minimal shadows",
|
122 |
+
"use_case": "νν© λΆμ, μ λ΅ νκ°",
|
123 |
+
"example": "Elegant SWOT quadrant: flat-design 4-grid on matte-white backdrop, thin pastel separators, top-left 'Strengths' panel shows glowing shield icon and subtle motif, top-right 'Weaknesses' panel with cracked chain icon in soft crimson, bottom-left 'Opportunities' panel with sunrise-over-horizon icon in optimistic teal, bottom-right 'Threats' panel with storm-cloud & lightning icon in deep indigo, minimal shadows, no text, no watermark, 16:9, 4K"
|
124 |
+
},
|
125 |
+
"Colorful Mind Map": {
|
126 |
+
"name": "Mind Map",
|
127 |
+
"description": "Hand-drawn educational style with vibrant colors",
|
128 |
+
"use_case": "λΈλ μΈμ€ν λ°, μμ΄λμ΄ μ 리",
|
129 |
+
"example": "A handrawn colorful mind map diagram: educational style, vibrant colors, clear hierarchy, golden ratio layout. Central concept with branching sub-topics, each branch with unique color coding, organic flowing connections, doodle-style icons for each node"
|
130 |
+
},
|
131 |
+
"Business Workflow": {
|
132 |
+
"name": "Business Process",
|
133 |
+
"description": "End-to-end business workflow with clear phases",
|
134 |
+
"use_case": "νλ‘μΈμ€ μ€λͺ
, λ¨κ³λ³ μ§ν",
|
135 |
+
"example": "A detailed hand-drawn diagram illustrating an end-to-end business workflow with Market Analysis, Strategy Development, Product Design, Implementation, and Post-Launch Review phases. Clear directional arrows, iconography for each component, vibrant educational yet professional style"
|
136 |
+
},
|
137 |
+
"Industrial Design": {
|
138 |
+
"name": "Product Design",
|
139 |
+
"description": "Sleek industrial design concept sketch",
|
140 |
+
"use_case": "μ ν μκ°, 컨μ
λμμΈ",
|
141 |
+
"example": "A sleek industrial design concept: Curved metallic body with minimal bezel, Touchscreen panel for settings, Modern matte black finish, Hand-drawn concept sketch style with annotations and dimension lines"
|
142 |
+
},
|
143 |
+
"3D Bubble Chart": {
|
144 |
+
"name": "Bubble Chart",
|
145 |
+
"description": "Clean 3D bubble visualization",
|
146 |
+
"use_case": "λΉκ΅ λΆμ, ν¬μ§μ
λ",
|
147 |
+
"example": "3-D bubble chart on clean white 2Γ2 grid, quadrant titles hidden, four translucent spheres in lime, azure, amber, magenta, gentle depth-of-field, modern consulting aesthetic, no text, 4K"
|
148 |
+
},
|
149 |
+
"Timeline Ribbon": {
|
150 |
+
"name": "Timeline",
|
151 |
+
"description": "Horizontal ribbon timeline with cyber-futuristic vibe",
|
152 |
+
"use_case": "μΌμ , λ‘λλ§΅, λ§μΌμ€ν€",
|
153 |
+
"example": "Horizontal ribbon timeline, milestone pins glowing hot pink on charcoal, year markers as circles, faint motion streaks, cyber-futuristic vibe, no text, 1920Γ1080"
|
154 |
+
},
|
155 |
+
"Risk Heat Map": {
|
156 |
+
"name": "Heat Map",
|
157 |
+
"description": "Risk assessment heat map with gradient colors",
|
158 |
+
"use_case": "리μ€ν¬ λΆμ, μ°μ μμ",
|
159 |
+
"example": "Risk Heat Map: square grid, smooth gradient from mint to fire-red, cells beveled, simple legend strip hidden, long subtle shadow, sterile white frame, no text"
|
160 |
+
},
|
161 |
+
"Pyramid/Funnel": {
|
162 |
+
"name": "Funnel Chart",
|
163 |
+
"description": "Multi-layer gradient funnel visualization",
|
164 |
+
"use_case": "λ¨κ³λ³ μΆμ, ν΅μ¬ λμΆ",
|
165 |
+
"example": "Pyramid / Funnel: 5-layer gradient funnel narrowing downwards, top vivid sky-blue, mid mint-green, bottom sunset-orange, glass reflection, minimal background, no text"
|
166 |
+
},
|
167 |
+
"KPI Dashboard": {
|
168 |
+
"name": "Dashboard",
|
169 |
+
"description": "Dark-mode analytics dashboard with sci-fi interface",
|
170 |
+
"use_case": "μ±κ³Ό μ§ν, μ€μ λμ보λ",
|
171 |
+
"example": "KPI Dashboard: Dark-mode analytic dashboard, three glass speedometers glowing neon lime, two sparkline charts under, black glass background, sci-fi interface, no text, 4K"
|
172 |
+
},
|
173 |
+
"Value Chain": {
|
174 |
+
"name": "Value Chain",
|
175 |
+
"description": "Horizontal value chain with industrial look",
|
176 |
+
"use_case": "κ°μΉ μ¬μ¬, λΉμ¦λμ€ λͺ¨λΈ",
|
177 |
+
"example": "Value Chain Diagram: Horizontal value chain blocks, steel-blue gradient bars with subtle bevel, small gear icons above each segment, sleek industrial look, shadow cast, no text"
|
178 |
+
},
|
179 |
+
"Gantt Chart": {
|
180 |
+
"name": "Gantt Chart",
|
181 |
+
"description": "Hand-drawn style Gantt chart with playful colors",
|
182 |
+
"use_case": "νλ‘μ νΈ μΌμ , μμ
κ΄λ¦¬",
|
183 |
+
"example": "Gantt Chart: Hand-drawn style Gantt bars sketched with vibrant markers on dotted grid notebook page, sticky-note color palette, playful yet organized, perspective tilt, no text"
|
184 |
+
},
|
185 |
+
"Mobile App Mockup": {
|
186 |
+
"name": "App Mockup",
|
187 |
+
"description": "Clean wireframe for mobile app design",
|
188 |
+
"use_case": "μ±/μΉ UI, νλ©΄ μ€κ³",
|
189 |
+
"example": "MOCKUP DESIGN: A clean hand-drawn style wireframe for a mobile app with Title screen, Login screen, Dashboard with sections, Bottom navigation bar, minimalist design with annotations"
|
190 |
+
},
|
191 |
+
"Flowchart": {
|
192 |
+
"name": "Flowchart",
|
193 |
+
"description": "Vibrant flowchart with minimalistic icons",
|
194 |
+
"use_case": "μμ¬κ²°μ , νλ‘μΈμ€ νλ¦",
|
195 |
+
"example": "FLOWCHART DESIGN: A hand-drawn style flowchart, vibrant colors, minimalistic icons showing process flow from START to END with decision points, branches, and clear directional arrows"
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
# PPT ν
νλ¦Ώ μ μ (λμ μΌλ‘ μ¬λΌμ΄λ μ μ‘°μ κ°λ₯)
|
200 |
+
PPT_TEMPLATES = {
|
201 |
+
"λΉμ¦λμ€ μ μμ": {
|
202 |
+
"description": "ν¬μ μ μΉ, μ¬μ
μ μμ©",
|
203 |
+
"core_slides": [
|
204 |
+
{"title": "λͺ©μ°¨", "style": "Flowchart", "prompt_hint": "νλ μ ν
μ΄μ
ꡬ쑰"},
|
205 |
+
{"title": "λ¬Έμ μ μ", "style": "Colorful Mind Map", "prompt_hint": "νμ¬ μμ₯μ λ¬Έμ μ "},
|
206 |
+
{"title": "νν© λΆμ", "style": "Elegant SWOT Quadrant", "prompt_hint": "κ°μ , μ½μ , κΈ°ν, μν"},
|
207 |
+
{"title": "μ루μ
", "style": "Industrial Design", "prompt_hint": "μ ν/μλΉμ€ 컨μ
"},
|
208 |
+
{"title": "νλ‘μΈμ€", "style": "Business Workflow", "prompt_hint": "μ€ν λ¨κ³"},
|
209 |
+
{"title": "μΌμ ", "style": "Timeline Ribbon", "prompt_hint": "μ£Όμ λ§μΌμ€ν€"}
|
210 |
+
],
|
211 |
+
"optional_slides": [
|
212 |
+
{"title": "μμ₯ κ·λͺ¨", "style": "3D Bubble Chart", "prompt_hint": "μμ₯ κΈ°νμ μ±μ₯μ±"},
|
213 |
+
{"title": "κ²½μ λΆμ", "style": "Risk Heat Map", "prompt_hint": "κ²½μμ¬ ν¬μ§μ
λ"},
|
214 |
+
{"title": "λΉμ¦λμ€ λͺ¨λΈ", "style": "Value Chain", "prompt_hint": "μμ΅ κ΅¬μ‘°"},
|
215 |
+
{"title": "ν μκ°", "style": "Colorful Mind Map", "prompt_hint": "ν΅μ¬ νμκ³Ό μλ"},
|
216 |
+
{"title": "μ¬λ¬΄ κ³ν", "style": "KPI Dashboard", "prompt_hint": "μμ λ§€μΆκ³Ό μμ΅"},
|
217 |
+
{"title": "μν κ΄λ¦¬", "style": "Risk Heat Map", "prompt_hint": "μ£Όμ 리μ€ν¬μ λμ"},
|
218 |
+
{"title": "ννΈλμ", "style": "Business Workflow", "prompt_hint": "μ λ΅μ μ ν΄"},
|
219 |
+
{"title": "κΈ°μ μ€ν", "style": "Flowchart", "prompt_hint": "ν΅μ¬ κΈ°μ ꡬ쑰"},
|
220 |
+
{"title": "κ³ κ° μ¬λ‘", "style": "Industrial Design", "prompt_hint": "μ±κ³΅ μ¬λ‘"},
|
221 |
+
{"title": "μ±μ₯ μ λ΅", "style": "Timeline Ribbon", "prompt_hint": "νμ₯ κ³ν"},
|
222 |
+
{"title": "ν¬μ νμ©", "style": "Pyramid/Funnel", "prompt_hint": "μκΈ μ¬μ© κ³ν"},
|
223 |
+
{"title": "Exit μ λ΅", "style": "Timeline Ribbon", "prompt_hint": "μΆκ΅¬ μ λ΅"}
|
224 |
+
]
|
225 |
+
},
|
226 |
+
"μ ν μκ°": {
|
227 |
+
"description": "μ μ ν λ°μΉ, μλΉμ€ μκ°μ©",
|
228 |
+
"core_slides": [
|
229 |
+
{"title": "μ ν 컨μ
", "style": "Industrial Design", "prompt_hint": "μ ν λμμΈ"},
|
230 |
+
{"title": "μ¬μ©μ λμ¦", "style": "Colorful Mind Map", "prompt_hint": "κ³ κ° νμΈν¬μΈνΈ"},
|
231 |
+
{"title": "κΈ°λ₯ μκ°", "style": "Mobile App Mockup", "prompt_hint": "UI/UX νλ©΄"},
|
232 |
+
{"title": "μλ μ리", "style": "Flowchart", "prompt_hint": "κΈ°λ₯ νλ‘μ°"},
|
233 |
+
{"title": "μμ₯ ν¬μ§μ
", "style": "3D Bubble Chart", "prompt_hint": "κ²½μμ¬ λΉκ΅"},
|
234 |
+
{"title": "μΆμ μΌμ ", "style": "Timeline Ribbon", "prompt_hint": "λ°μΉ λ‘λλ§΅"}
|
235 |
+
],
|
236 |
+
"optional_slides": [
|
237 |
+
{"title": "νκ² κ³ κ°", "style": "Colorful Mind Map", "prompt_hint": "μ£Όμ κ³ κ°μΈ΅"},
|
238 |
+
{"title": "κ°κ²© μ μ±
", "style": "Pyramid/Funnel", "prompt_hint": "κ°κ²© μ λ΅"},
|
239 |
+
{"title": "κΈ°μ μ°μ", "style": "Industrial Design", "prompt_hint": "ν΅μ¬ κΈ°μ "},
|
240 |
+
{"title": "μ¬μ© μλ리μ€", "style": "Business Workflow", "prompt_hint": "νμ© μ¬λ‘"},
|
241 |
+
{"title": "κ³ κ° νκΈ°", "style": "KPI Dashboard", "prompt_hint": "μ¬μ©μ νκ°"},
|
242 |
+
{"title": "νλ§€ μ±λ", "style": "Value Chain", "prompt_hint": "μ ν΅ μ λ΅"},
|
243 |
+
{"title": "λ§μΌν
μ λ΅", "style": "Timeline Ribbon", "prompt_hint": "ν보 κ³ν"},
|
244 |
+
{"title": "μ±λ₯ λΉκ΅", "style": "3D Bubble Chart", "prompt_hint": "λ²€μΉλ§ν¬"}
|
245 |
+
]
|
246 |
+
},
|
247 |
+
"νλ‘μ νΈ λ³΄κ³ ": {
|
248 |
+
"description": "μ§ν μν©, μ±κ³Ό λ³΄κ³ μ©",
|
249 |
+
"core_slides": [
|
250 |
+
{"title": "νλ‘μ νΈ κ°μ", "style": "Business Workflow", "prompt_hint": "μ 체 νλ‘μΈμ€"},
|
251 |
+
{"title": "μ§ν νν©", "style": "Gantt Chart", "prompt_hint": "μμ
μΌμ "},
|
252 |
+
{"title": "리μ€ν¬ κ΄λ¦¬", "style": "Risk Heat Map", "prompt_hint": "μν μμ"},
|
253 |
+
{"title": "μ±κ³Ό μ§ν", "style": "KPI Dashboard", "prompt_hint": "λ¬μ± μ€μ "},
|
254 |
+
{"title": "ν₯ν κ³ν", "style": "Timeline Ribbon", "prompt_hint": "λ€μ λ¨κ³"}
|
255 |
+
],
|
256 |
+
"optional_slides": [
|
257 |
+
{"title": "μμ° νν©", "style": "Pyramid/Funnel", "prompt_hint": "μμ° μ§ν"},
|
258 |
+
{"title": "ν μ±κ³Ό", "style": "3D Bubble Chart", "prompt_hint": "νλ³ κΈ°μ¬λ"},
|
259 |
+
{"title": "μ΄μ κ΄λ¦¬", "style": "Risk Heat Map", "prompt_hint": "μ£Όμ μ΄μ"},
|
260 |
+
{"title": "κ°μ μ¬ν", "style": "Colorful Mind Map", "prompt_hint": "νλ‘μΈμ€ κ°μ "},
|
261 |
+
{"title": "κ΅ν", "style": "Business Workflow", "prompt_hint": "λ°°μ΄ μ "}
|
262 |
+
]
|
263 |
+
},
|
264 |
+
"μ λ΅ κΈ°ν": {
|
265 |
+
"description": "μ€μ₯κΈ° μ λ΅, λΉμ μ립μ©",
|
266 |
+
"core_slides": [
|
267 |
+
{"title": "λΉμ ", "style": "3D Style (Pixar-like)", "prompt_hint": "λ―Έλ λΉμ "},
|
268 |
+
{"title": "νκ²½ λΆμ", "style": "Elegant SWOT Quadrant", "prompt_hint": "λ΄μΈλΆ νκ²½"},
|
269 |
+
{"title": "μ λ΅ μ²΄κ³", "style": "Colorful Mind Map", "prompt_hint": "μ λ΅ κ΅¬μ‘°"},
|
270 |
+
{"title": "κ°μΉ μ¬μ¬", "style": "Value Chain", "prompt_hint": "λΉμ¦λμ€ λͺ¨λΈ"},
|
271 |
+
{"title": "μ€ν λ‘λλ§΅", "style": "Timeline Ribbon", "prompt_hint": "λ¨κ³λ³ κ³ν"},
|
272 |
+
{"title": "λͺ©ν μ§ν", "style": "KPI Dashboard", "prompt_hint": "KPI λͺ©ν"}
|
273 |
+
],
|
274 |
+
"optional_slides": [
|
275 |
+
{"title": "μμ₯ μ λ§", "style": "3D Bubble Chart", "prompt_hint": "λ―Έλ μμ₯"},
|
276 |
+
{"title": "νμ λ°©ν₯", "style": "Industrial Design", "prompt_hint": "νμ μ λ΅"},
|
277 |
+
{"title": "μ‘°μ§ λ³ν", "style": "Business Workflow", "prompt_hint": "μ‘°μ§ κ°νΈ"},
|
278 |
+
{"title": "λμ§νΈ μ ν", "style": "Flowchart", "prompt_hint": "DX μ λ΅"},
|
279 |
+
{"title": "μ§μκ°λ₯μ±", "style": "Timeline Ribbon", "prompt_hint": "ESG μ λ΅"}
|
280 |
+
]
|
281 |
+
},
|
282 |
+
"μ¬μ©μ μ μ": {
|
283 |
+
"description": "μ§μ ꡬμ±νκΈ°",
|
284 |
+
"core_slides": [],
|
285 |
+
"optional_slides": []
|
286 |
+
}
|
287 |
+
}
|
288 |
+
|
289 |
+
def brave_search(query: str) -> List[Dict]:
|
290 |
+
"""Brave Search APIλ₯Ό μ¬μ©ν μΉ κ²μ"""
|
291 |
+
if not BRAVE_API_TOKEN:
|
292 |
+
print("[Brave Search] API ν ν°μ΄ μμ΄ κ²μμ 건λλλλ€.")
|
293 |
+
return []
|
294 |
+
|
295 |
+
print(f"[Brave Search] κ²μμ΄: {query}")
|
296 |
+
|
297 |
+
headers = {
|
298 |
+
"Accept": "application/json",
|
299 |
+
"X-Subscription-Token": BRAVE_API_TOKEN
|
300 |
+
}
|
301 |
+
|
302 |
+
params = {
|
303 |
+
"q": query,
|
304 |
+
"count": 5
|
305 |
+
}
|
306 |
+
|
307 |
+
try:
|
308 |
+
response = requests.get(
|
309 |
+
"https://api.search.brave.com/res/v1/web/search",
|
310 |
+
headers=headers,
|
311 |
+
params=params,
|
312 |
+
timeout=10
|
313 |
+
)
|
314 |
+
|
315 |
+
if response.status_code == 200:
|
316 |
+
data = response.json()
|
317 |
+
results = []
|
318 |
+
for item in data.get("web", {}).get("results", [])[:3]:
|
319 |
+
results.append({
|
320 |
+
"title": item.get("title", ""),
|
321 |
+
"description": item.get("description", ""),
|
322 |
+
"url": item.get("url", "")
|
323 |
+
})
|
324 |
+
print(f"[Brave Search] {len(results)}κ° κ²°κ³Ό νλ")
|
325 |
+
return results
|
326 |
+
else:
|
327 |
+
print(f"[Brave Search] μ€λ₯: {response.status_code}")
|
328 |
+
return []
|
329 |
+
except Exception as e:
|
330 |
+
print(f"[Brave Search] μμΈ: {str(e)}")
|
331 |
+
return []
|
332 |
+
|
333 |
+
def read_uploaded_file(file_path: str) -> str:
|
334 |
+
"""μ
λ‘λλ νμΌ μ½κΈ° (PDF, CSV, TXT)"""
|
335 |
+
print(f"[νμΌ μ½κΈ°] {file_path}")
|
336 |
+
|
337 |
+
try:
|
338 |
+
# νμΌ νμ₯μ νμΈ
|
339 |
+
ext = os.path.splitext(file_path)[1].lower()
|
340 |
+
|
341 |
+
if ext == '.pdf':
|
342 |
+
# PDF μ½κΈ°
|
343 |
+
with open(file_path, 'rb') as file:
|
344 |
+
pdf_reader = PyPDF2.PdfReader(file)
|
345 |
+
text = ""
|
346 |
+
for page in pdf_reader.pages:
|
347 |
+
text += page.extract_text() + "\n"
|
348 |
+
return text[:5000] # μ΅λ 5000μ
|
349 |
+
|
350 |
+
elif ext == '.csv':
|
351 |
+
# CSV μ½κΈ°
|
352 |
+
# μΈμ½λ© κ°μ§
|
353 |
+
with open(file_path, 'rb') as file:
|
354 |
+
raw_data = file.read()
|
355 |
+
result = chardet.detect(raw_data)
|
356 |
+
encoding = result['encoding'] or 'utf-8'
|
357 |
+
|
358 |
+
df = pd.read_csv(file_path, encoding=encoding)
|
359 |
+
return f"CSV λ°μ΄ν°:\n{df.head(20).to_string()}\n\nμμ½: {len(df)} ν, {len(df.columns)} μ΄"
|
360 |
+
|
361 |
+
elif ext in ['.txt', '.text']:
|
362 |
+
# ν
μ€νΈ νμΌ μ½κΈ°
|
363 |
+
with open(file_path, 'rb') as file:
|
364 |
+
raw_data = file.read()
|
365 |
+
result = chardet.detect(raw_data)
|
366 |
+
encoding = result['encoding'] or 'utf-8'
|
367 |
+
|
368 |
+
with open(file_path, 'r', encoding=encoding) as file:
|
369 |
+
return file.read()[:5000] # μ΅λ 5000μ
|
370 |
+
else:
|
371 |
+
return "μ§μνμ§ μλ νμΌ νμμ
λλ€."
|
372 |
+
|
373 |
+
except Exception as e:
|
374 |
+
return f"νμΌ μ½κΈ° μ€λ₯: {str(e)}"
|
375 |
+
|
376 |
+
def generate_presentation_notes(topic: str, slide_title: str, content: Dict) -> str:
|
377 |
+
"""κ° μ¬λΌμ΄λμ λ°νμ λ
ΈνΈ μμ± (ꡬμ΄μ²΄)"""
|
378 |
+
print(f"[λ°νμ λ
ΈνΈ] {slide_title} μμ± μ€...")
|
379 |
+
|
380 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
381 |
+
headers = {
|
382 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
383 |
+
"Content-Type": "application/json"
|
384 |
+
}
|
385 |
+
|
386 |
+
system_prompt = """You are a professional presentation coach who creates natural, conversational speaker notes.
|
387 |
+
|
388 |
+
Create speaker notes that:
|
389 |
+
1. Sound natural and conversational, as if speaking to an audience
|
390 |
+
2. Include transitions and engagement phrases
|
391 |
+
3. Reference the slide content but expand with additional context
|
392 |
+
4. Use a warm, professional tone
|
393 |
+
5. Be 100-150 words long
|
394 |
+
6. Include pauses and emphasis markers where appropriate
|
395 |
+
|
396 |
+
Format:
|
397 |
+
- Use conversational language
|
398 |
+
- Include transition phrases
|
399 |
+
- Add engagement questions or comments
|
400 |
+
- Keep it professional but friendly"""
|
401 |
+
|
402 |
+
bullet_text = "\n".join(content.get("bullet_points", []))
|
403 |
+
user_message = f"""Topic: {topic}
|
404 |
+
Slide Title: {slide_title}
|
405 |
+
Subtitle: {content.get('subtitle', '')}
|
406 |
+
Key Points:
|
407 |
+
{bullet_text}
|
408 |
+
|
409 |
+
Create natural speaker notes for presenting this slide."""
|
410 |
+
|
411 |
+
payload = {
|
412 |
+
"model": "dep89a2fld32mcm",
|
413 |
+
"messages": [
|
414 |
+
{
|
415 |
+
"role": "system",
|
416 |
+
"content": system_prompt
|
417 |
+
},
|
418 |
+
{
|
419 |
+
"role": "user",
|
420 |
+
"content": user_message
|
421 |
+
}
|
422 |
+
],
|
423 |
+
"max_tokens": 300,
|
424 |
+
"temperature": 0.8,
|
425 |
+
"stream": False
|
426 |
+
}
|
427 |
+
|
428 |
+
try:
|
429 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
430 |
+
if response.status_code == 200:
|
431 |
+
result = response.json()
|
432 |
+
notes = result['choices'][0]['message']['content'].strip()
|
433 |
+
|
434 |
+
# νκΈ μ£Όμ μΈ κ²½μ° λ²μ
|
435 |
+
if any(ord('κ°') <= ord(char) <= ord('ν£') for char in topic):
|
436 |
+
notes = translate_content_to_korean(notes)
|
437 |
+
|
438 |
+
return notes
|
439 |
+
else:
|
440 |
+
return "μ΄ μ¬λΌμ΄λμμλ ν΅μ¬ λ΄μ©μ μ€λͺ
ν΄ μ£ΌμΈμ."
|
441 |
+
except Exception as e:
|
442 |
+
print(f"[λ°νμ λ
ΈνΈ] μ€λ₯: {str(e)}")
|
443 |
+
return "μ΄ μ¬λΌμ΄λμμλ ν΅μ¬ λ΄μ©μ μ€λͺ
ν΄ μ£ΌμΈμ."
|
444 |
+
|
445 |
+
def generate_slide_content(topic: str, slide_title: str, slide_context: str, uploaded_content: str = None, web_search_results: List[Dict] = None) -> Dict[str, str]:
|
446 |
+
"""κ° μ¬λΌμ΄λμ ν
μ€νΈ λ΄μ© μμ±"""
|
447 |
+
print(f"[μ¬λΌμ΄λ λ΄μ©] {slide_title} ν
μ€νΈ μμ± μ€...")
|
448 |
+
|
449 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
450 |
+
headers = {
|
451 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
452 |
+
"Content-Type": "application/json"
|
453 |
+
}
|
454 |
+
|
455 |
+
system_prompt = """You are a professional presentation content writer specializing in creating concise, impactful slide content.
|
456 |
+
|
457 |
+
Your task is to create:
|
458 |
+
1. A compelling subtitle (max 10 words)
|
459 |
+
2. Exactly 5 bullet points, each being a complete, concise sentence
|
460 |
+
3. Each bullet point should be 10-15 words
|
461 |
+
|
462 |
+
Guidelines:
|
463 |
+
- Be specific and actionable
|
464 |
+
- Use professional business language
|
465 |
+
- Include relevant data points or metrics when appropriate
|
466 |
+
- Ensure content aligns with the slide's purpose
|
467 |
+
- Make each point distinct and valuable
|
468 |
+
- Use active voice and strong verbs
|
469 |
+
|
470 |
+
Output format:
|
471 |
+
Subtitle: [subtitle here]
|
472 |
+
β’ [Point 1]
|
473 |
+
β’ [Point 2]
|
474 |
+
β’ [Point 3]
|
475 |
+
β’ [Point 4]
|
476 |
+
β’ [Point 5]"""
|
477 |
+
|
478 |
+
user_message = f"""Topic: {topic}
|
479 |
+
Slide Title: {slide_title}
|
480 |
+
Context: {slide_context}"""
|
481 |
+
|
482 |
+
# μ
λ‘λλ μ½ν
μΈ κ° μμΌλ©΄ μΆκ°
|
483 |
+
if uploaded_content:
|
484 |
+
user_message += f"\n\nReference Material:\n{uploaded_content[:1000]}"
|
485 |
+
|
486 |
+
# μΉ κ²μ κ²°κ³Όκ° μμΌλ©΄ μΆκ°
|
487 |
+
if web_search_results:
|
488 |
+
search_context = "\n\nWeb Search Results:\n"
|
489 |
+
for result in web_search_results[:3]:
|
490 |
+
search_context += f"- {result['title']}: {result['description']}\n"
|
491 |
+
user_message += search_context
|
492 |
+
|
493 |
+
user_message += "\n\nCreate compelling content for this presentation slide."
|
494 |
+
|
495 |
+
payload = {
|
496 |
+
"model": "dep89a2fld32mcm",
|
497 |
+
"messages": [
|
498 |
+
{
|
499 |
+
"role": "system",
|
500 |
+
"content": system_prompt
|
501 |
+
},
|
502 |
+
{
|
503 |
+
"role": "user",
|
504 |
+
"content": user_message
|
505 |
+
}
|
506 |
+
],
|
507 |
+
"max_tokens": 300,
|
508 |
+
"top_p": 0.8,
|
509 |
+
"temperature": 0.7,
|
510 |
+
"stream": False
|
511 |
+
}
|
512 |
+
|
513 |
+
try:
|
514 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
515 |
+
if response.status_code == 200:
|
516 |
+
result = response.json()
|
517 |
+
content = result['choices'][0]['message']['content'].strip()
|
518 |
+
|
519 |
+
# Parse content
|
520 |
+
lines = content.split('\n')
|
521 |
+
subtitle = ""
|
522 |
+
bullet_points = []
|
523 |
+
|
524 |
+
for line in lines:
|
525 |
+
if line.startswith("Subtitle:"):
|
526 |
+
subtitle = line.replace("Subtitle:", "").strip()
|
527 |
+
elif line.strip().startswith("β’"):
|
528 |
+
bullet_points.append(line.strip())
|
529 |
+
|
530 |
+
# νκΈλ‘ λ²μμ΄ νμν κ²½μ°
|
531 |
+
if any(ord('κ°') <= ord(char) <= ord('ν£') for char in topic):
|
532 |
+
subtitle = translate_content_to_korean(subtitle)
|
533 |
+
bullet_points = [translate_content_to_korean(point) for point in bullet_points]
|
534 |
+
|
535 |
+
return {
|
536 |
+
"subtitle": subtitle,
|
537 |
+
"bullet_points": bullet_points[:5] # μ΅λ 5κ°
|
538 |
+
}
|
539 |
+
else:
|
540 |
+
return {
|
541 |
+
"subtitle": slide_title,
|
542 |
+
"bullet_points": ["λ΄μ©μ μμ±ν μ μμ΅λλ€."] * 5
|
543 |
+
}
|
544 |
+
except Exception as e:
|
545 |
+
print(f"[μ¬λΌμ΄λ λ΄μ©] μ€λ₯: {str(e)}")
|
546 |
+
return {
|
547 |
+
"subtitle": slide_title,
|
548 |
+
"bullet_points": ["λ΄μ©μ μμ±ν μ μμ΅λλ€."] * 5
|
549 |
+
}
|
550 |
+
|
551 |
+
def translate_content_to_korean(text: str) -> str:
|
552 |
+
"""μμ΄ ν
μ€νΈλ₯Ό νκΈλ‘ λ²μ"""
|
553 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
554 |
+
headers = {
|
555 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
556 |
+
"Content-Type": "application/json"
|
557 |
+
}
|
558 |
+
|
559 |
+
payload = {
|
560 |
+
"model": "dep89a2fld32mcm",
|
561 |
+
"messages": [
|
562 |
+
{
|
563 |
+
"role": "system",
|
564 |
+
"content": "You are a translator. Translate the given English text to Korean. Maintain professional business tone. Only return the translation without any explanation."
|
565 |
+
},
|
566 |
+
{
|
567 |
+
"role": "user",
|
568 |
+
"content": text
|
569 |
+
}
|
570 |
+
],
|
571 |
+
"max_tokens": 200,
|
572 |
+
"top_p": 0.8,
|
573 |
+
"stream": False
|
574 |
+
}
|
575 |
+
|
576 |
+
try:
|
577 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
578 |
+
if response.status_code == 200:
|
579 |
+
result = response.json()
|
580 |
+
return result['choices'][0]['message']['content'].strip()
|
581 |
+
else:
|
582 |
+
return text
|
583 |
+
except Exception as e:
|
584 |
+
return text
|
585 |
+
|
586 |
+
def generate_prompt_with_llm(topic: str, style_example: str = None, slide_context: str = None, uploaded_content: str = None) -> str:
|
587 |
+
"""μ£Όμ μ μ€νμΌ μμ λ₯Ό λ°μμ LLMμ μ¬μ©ν΄ μ΄λ―Έμ§ ν둬ννΈλ₯Ό μμ±"""
|
588 |
+
print(f"[LLM] ν둬ννΈ μμ± μμ: {slide_context}")
|
589 |
+
|
590 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
591 |
+
headers = {
|
592 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
593 |
+
"Content-Type": "application/json"
|
594 |
+
}
|
595 |
+
|
596 |
+
system_prompt = """You are an expert image prompt engineer specializing in creating prompts for professional presentation slides.
|
597 |
+
|
598 |
+
Your task is to create prompts that:
|
599 |
+
1. Are highly specific and visual, perfect for PPT backgrounds or main visuals
|
600 |
+
2. Consider the slide's purpose and maintain consistency across a presentation
|
601 |
+
3. Include style references matching the given example
|
602 |
+
4. Focus on clean, professional visuals that won't distract from text overlays
|
603 |
+
5. Ensure high contrast areas for text readability when needed
|
604 |
+
6. Maintain brand consistency and professional aesthetics
|
605 |
+
|
606 |
+
Important guidelines:
|
607 |
+
- If given a style example, adapt the topic to match that specific visual style
|
608 |
+
- Consider the slide context (e.g., "νμ§", "νν© λΆμ") to create appropriate visuals
|
609 |
+
- Always output ONLY the prompt without any explanation
|
610 |
+
- Keep prompts between 50-150 words for optimal results
|
611 |
+
- Ensure the visual supports rather than overwhelms the slide content"""
|
612 |
+
|
613 |
+
user_message = f"Topic: {topic}"
|
614 |
+
if style_example:
|
615 |
+
user_message += f"\n\nStyle reference to follow:\n{style_example}"
|
616 |
+
if slide_context:
|
617 |
+
user_message += f"\n\nSlide context: {slide_context}"
|
618 |
+
if uploaded_content:
|
619 |
+
user_message += f"\n\nAdditional context from document:\n{uploaded_content[:500]}"
|
620 |
+
|
621 |
+
payload = {
|
622 |
+
"model": "dep89a2fld32mcm",
|
623 |
+
"messages": [
|
624 |
+
{
|
625 |
+
"role": "system",
|
626 |
+
"content": system_prompt
|
627 |
+
},
|
628 |
+
{
|
629 |
+
"role": "user",
|
630 |
+
"content": user_message
|
631 |
+
}
|
632 |
+
],
|
633 |
+
"max_tokens": 300,
|
634 |
+
"top_p": 0.8,
|
635 |
+
"temperature": 0.7,
|
636 |
+
"stream": False
|
637 |
+
}
|
638 |
+
|
639 |
+
try:
|
640 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
641 |
+
if response.status_code == 200:
|
642 |
+
result = response.json()
|
643 |
+
prompt = result['choices'][0]['message']['content'].strip()
|
644 |
+
print(f"[LLM] ν둬ννΈ μμ± μλ£: {prompt[:50]}...")
|
645 |
+
return prompt
|
646 |
+
else:
|
647 |
+
error_msg = f"ν둬ννΈ μμ± μ€ν¨: {response.status_code}"
|
648 |
+
print(f"[LLM] {error_msg}")
|
649 |
+
return error_msg
|
650 |
+
except Exception as e:
|
651 |
+
error_msg = f"ν둬ννΈ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
652 |
+
print(f"[LLM] {error_msg}")
|
653 |
+
return error_msg
|
654 |
+
|
655 |
+
def translate_to_english(text: str) -> str:
|
656 |
+
"""νκΈ ν
μ€νΈλ₯Ό μμ΄λ‘ λ²μ (LLM μ¬μ©)"""
|
657 |
+
if not any(ord('κ°') <= ord(char) <= ord('ν£') for char in text):
|
658 |
+
return text
|
659 |
+
|
660 |
+
print(f"[λ²μ] νκΈ κ°μ§, μμ΄λ‘ λ²μ μμ")
|
661 |
+
|
662 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
663 |
+
headers = {
|
664 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
665 |
+
"Content-Type": "application/json"
|
666 |
+
}
|
667 |
+
|
668 |
+
payload = {
|
669 |
+
"model": "dep89a2fld32mcm",
|
670 |
+
"messages": [
|
671 |
+
{
|
672 |
+
"role": "system",
|
673 |
+
"content": "You are a translator. Translate the given Korean text to English. Only return the translation without any explanation."
|
674 |
+
},
|
675 |
+
{
|
676 |
+
"role": "user",
|
677 |
+
"content": text
|
678 |
+
}
|
679 |
+
],
|
680 |
+
"max_tokens": 500,
|
681 |
+
"top_p": 0.8,
|
682 |
+
"stream": False
|
683 |
+
}
|
684 |
+
|
685 |
+
try:
|
686 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
687 |
+
if response.status_code == 200:
|
688 |
+
result = response.json()
|
689 |
+
translated = result['choices'][0]['message']['content'].strip()
|
690 |
+
print(f"[λ²μ] μλ£")
|
691 |
+
return translated
|
692 |
+
else:
|
693 |
+
print(f"[λ²μ] μ€ν¨, μλ³Έ μ¬μ©")
|
694 |
+
return text
|
695 |
+
except Exception as e:
|
696 |
+
print(f"[λ²μ] μ€λ₯: {str(e)}, μλ³Έ μ¬μ©")
|
697 |
+
return text
|
698 |
+
|
699 |
+
def generate_image(prompt: str, seed: int = 10, slide_info: str = "") -> Tuple[Image.Image, str]:
|
700 |
+
"""Replicate APIλ₯Ό μ¬μ©ν΄ μ΄λ―Έμ§ μμ±"""
|
701 |
+
print(f"\n[μ΄λ―Έμ§ μμ±] {slide_info}")
|
702 |
+
print(f"[μ΄λ―Έμ§ μμ±] ν둬ννΈ: {prompt[:50]}...")
|
703 |
+
|
704 |
+
try:
|
705 |
+
english_prompt = translate_to_english(prompt)
|
706 |
+
|
707 |
+
if not REPLICATE_API_TOKEN:
|
708 |
+
error_msg = "RAPI_TOKEN νκ²½λ³μκ° μ€μ λμ§ μμμ΅λλ€."
|
709 |
+
print(f"[μ΄λ―Έμ§ μμ±] μ€λ₯: {error_msg}")
|
710 |
+
return None, error_msg
|
711 |
+
|
712 |
+
print(f"[μ΄λ―Έμ§ μμ±] Replicate API νΈμΆ μ€...")
|
713 |
+
client = replicate.Client(api_token=REPLICATE_API_TOKEN)
|
714 |
+
|
715 |
+
input_params = {
|
716 |
+
"seed": seed,
|
717 |
+
"prompt": english_prompt,
|
718 |
+
"speed_mode": "Extra Juiced π (even more speed)",
|
719 |
+
"output_quality": 100
|
720 |
+
}
|
721 |
+
|
722 |
+
start_time = time.time()
|
723 |
+
output = client.run(
|
724 |
+
"prunaai/hidream-l1-fast:17c237d753218fed0ed477cb553902b6b75735f48c128537ab829096ef3d3645",
|
725 |
+
input=input_params
|
726 |
+
)
|
727 |
+
|
728 |
+
elapsed = time.time() - start_time
|
729 |
+
print(f"[μ΄λ―Έμ§ μμ±] API μλ΅ λ°μ ({elapsed:.1f}μ΄)")
|
730 |
+
|
731 |
+
if output:
|
732 |
+
if isinstance(output, str) and output.startswith('http'):
|
733 |
+
print(f"[μ΄λ―Έμ§ μμ±] URLμμ μ΄λ―Έμ§ λ€μ΄λ‘λ μ€...")
|
734 |
+
response = requests.get(output, timeout=30)
|
735 |
+
img = Image.open(BytesIO(response.content))
|
736 |
+
print(f"[μ΄λ―Έμ§ μμ±] μλ£!")
|
737 |
+
return img, english_prompt
|
738 |
+
else:
|
739 |
+
print(f"[μ΄λ―Έμ§ μμ±] λ°μ΄λ리 λ°μ΄ν° μ²λ¦¬ μ€...")
|
740 |
+
img = Image.open(BytesIO(output.read()))
|
741 |
+
print(f"[μ΄λ―Έμ§ μμ±] μλ£!")
|
742 |
+
return img, english_prompt
|
743 |
+
else:
|
744 |
+
error_msg = "μ΄λ―Έμ§ μμ± μ€ν¨ - λΉ μλ΅"
|
745 |
+
print(f"[μ΄λ―Έμ§ μμ±] {error_msg}")
|
746 |
+
return None, error_msg
|
747 |
+
|
748 |
+
except Exception as e:
|
749 |
+
error_msg = f"μ€λ₯: {str(e)}"
|
750 |
+
print(f"[μ΄λ―Έμ§ μμ±] {error_msg}")
|
751 |
+
print(f"[μ΄λ―Έμ§ μμ±] μμΈ μ€λ₯:\n{traceback.format_exc()}")
|
752 |
+
return None, error_msg
|
753 |
+
|
754 |
+
def create_slide_preview_html(slide_data: Dict) -> str:
|
755 |
+
"""16:9 λΉμ¨μ μ¬λΌμ΄λ ν리뷰 HTML μμ± (λ₯κ·Ό λͺ¨μ리μ μ
체κ°)"""
|
756 |
+
|
757 |
+
# μ΄λ―Έμ§λ₯Ό base64λ‘ μΈμ½λ©
|
758 |
+
img_base64 = ""
|
759 |
+
if slide_data.get("image"):
|
760 |
+
buffered = BytesIO()
|
761 |
+
slide_data["image"].save(buffered, format="PNG")
|
762 |
+
img_base64 = base64.b64encode(buffered.getvalue()).decode()
|
763 |
+
|
764 |
+
# ν
μ€νΈ λ΄μ© κ°μ Έμ€κΈ°
|
765 |
+
subtitle = slide_data.get("subtitle", "")
|
766 |
+
bullet_points = slide_data.get("bullet_points", [])
|
767 |
+
|
768 |
+
# HTML μμ±
|
769 |
+
html = f"""
|
770 |
+
<div class="slide-container" style="
|
771 |
+
width: 100%;
|
772 |
+
max-width: 1200px;
|
773 |
+
margin: 20px auto;
|
774 |
+
background: white;
|
775 |
+
border-radius: 12px;
|
776 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
777 |
+
overflow: hidden;
|
778 |
+
">
|
779 |
+
<div class="slide-header" style="
|
780 |
+
background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
|
781 |
+
color: white;
|
782 |
+
padding: 15px 30px;
|
783 |
+
font-size: 18px;
|
784 |
+
font-weight: bold;
|
785 |
+
">
|
786 |
+
μ¬λΌμ΄λ {slide_data.get('slide_number', '')}: {slide_data.get('title', '')}
|
787 |
+
</div>
|
788 |
+
|
789 |
+
<div class="slide-content" style="
|
790 |
+
display: flex;
|
791 |
+
height: 0;
|
792 |
+
padding-bottom: 56.25%; /* 16:9 λΉμ¨ */
|
793 |
+
position: relative;
|
794 |
+
background: #fafbfc;
|
795 |
+
">
|
796 |
+
<div class="slide-inner" style="
|
797 |
+
position: absolute;
|
798 |
+
top: 0;
|
799 |
+
left: 0;
|
800 |
+
width: 100%;
|
801 |
+
height: 100%;
|
802 |
+
display: flex;
|
803 |
+
padding: 20px;
|
804 |
+
gap: 20px;
|
805 |
+
">
|
806 |
+
"""
|
807 |
+
|
808 |
+
# νμ§μ λ§μ§λ§ μ¬λΌμ΄λλ μ 체 νλ©΄ μ΄λ―Έμ§
|
809 |
+
if slide_data.get('title') in ['νμ§', 'Thank You']:
|
810 |
+
html += f"""
|
811 |
+
<!-- μ 체 νλ©΄ μ΄λ―Έμ§ -->
|
812 |
+
<div style="
|
813 |
+
width: 100%;
|
814 |
+
height: 100%;
|
815 |
+
position: relative;
|
816 |
+
background: #e9ecef;
|
817 |
+
border-radius: 12px;
|
818 |
+
overflow: hidden;
|
819 |
+
">
|
820 |
+
"""
|
821 |
+
|
822 |
+
if img_base64:
|
823 |
+
html += f"""
|
824 |
+
<img src="data:image/png;base64,{img_base64}" style="
|
825 |
+
width: 100%;
|
826 |
+
height: 100%;
|
827 |
+
object-fit: cover;
|
828 |
+
" alt="Slide Image">
|
829 |
+
<div style="
|
830 |
+
position: absolute;
|
831 |
+
top: 50%;
|
832 |
+
left: 50%;
|
833 |
+
transform: translate(-50%, -50%);
|
834 |
+
text-align: center;
|
835 |
+
color: white;
|
836 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
|
837 |
+
">
|
838 |
+
<h1 style="font-size: 48px; margin-bottom: 20px;">{slide_data.get('topic', '')}</h1>
|
839 |
+
<h2 style="font-size: 24px;">{subtitle}</h2>
|
840 |
+
</div>
|
841 |
+
"""
|
842 |
+
|
843 |
+
html += """
|
844 |
+
</div>
|
845 |
+
"""
|
846 |
+
else:
|
847 |
+
# μΌλ° μ¬λΌμ΄λ λ μ΄μμ
|
848 |
+
html += f"""
|
849 |
+
<!-- ν
μ€νΈ μμ (μ’μΈ‘) -->
|
850 |
+
<div class="text-area" style="
|
851 |
+
flex: 1;
|
852 |
+
padding: 30px;
|
853 |
+
display: flex;
|
854 |
+
flex-direction: column;
|
855 |
+
justify-content: center;
|
856 |
+
background: rgba(255, 255, 255, 0.95);
|
857 |
+
border-radius: 12px;
|
858 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
|
859 |
+
">
|
860 |
+
<h2 style="
|
861 |
+
color: #212529;
|
862 |
+
font-size: 28px;
|
863 |
+
margin-bottom: 30px;
|
864 |
+
font-weight: 600;
|
865 |
+
">{subtitle}</h2>
|
866 |
+
|
867 |
+
<ul style="
|
868 |
+
list-style: none;
|
869 |
+
padding: 0;
|
870 |
+
margin: 0;
|
871 |
+
">
|
872 |
+
"""
|
873 |
+
|
874 |
+
for point in bullet_points:
|
875 |
+
html += f"""
|
876 |
+
<li style="
|
877 |
+
margin-bottom: 16px;
|
878 |
+
padding-left: 28px;
|
879 |
+
position: relative;
|
880 |
+
color: #495057;
|
881 |
+
font-size: 16px;
|
882 |
+
line-height: 1.6;
|
883 |
+
">
|
884 |
+
<span style="
|
885 |
+
position: absolute;
|
886 |
+
left: 0;
|
887 |
+
color: #007bff;
|
888 |
+
font-size: 18px;
|
889 |
+
">β’</span>
|
890 |
+
{point.replace('β’', '').strip()}
|
891 |
+
</li>
|
892 |
+
"""
|
893 |
+
|
894 |
+
html += f"""
|
895 |
+
</ul>
|
896 |
+
</div>
|
897 |
+
|
898 |
+
<!-- μ΄λ―Έμ§ μμ (μ°μΈ‘) -->
|
899 |
+
<div class="image-area" style="
|
900 |
+
flex: 1;
|
901 |
+
background: rgba(248, 249, 250, 0.9);
|
902 |
+
border-radius: 12px;
|
903 |
+
display: flex;
|
904 |
+
align-items: center;
|
905 |
+
justify-content: center;
|
906 |
+
padding: 20px;
|
907 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
908 |
+
">
|
909 |
+
"""
|
910 |
+
|
911 |
+
if img_base64:
|
912 |
+
html += f"""
|
913 |
+
<img src="data:image/png;base64,{img_base64}" style="
|
914 |
+
max-width: 100%;
|
915 |
+
max-height: 100%;
|
916 |
+
object-fit: contain;
|
917 |
+
border-radius: 8px;
|
918 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
919 |
+
" alt="Slide Image">
|
920 |
+
"""
|
921 |
+
else:
|
922 |
+
html += """
|
923 |
+
<div style="
|
924 |
+
color: #6c757d;
|
925 |
+
text-align: center;
|
926 |
+
">
|
927 |
+
<div style="font-size: 48px;">πΌοΈ</div>
|
928 |
+
<p>μ΄λ―Έμ§ μμ± μ€...</p>
|
929 |
+
</div>
|
930 |
+
"""
|
931 |
+
|
932 |
+
html += """
|
933 |
+
</div>
|
934 |
+
"""
|
935 |
+
|
936 |
+
html += """
|
937 |
+
</div>
|
938 |
+
</div>
|
939 |
+
</div>
|
940 |
+
"""
|
941 |
+
|
942 |
+
return html
|
943 |
+
|
944 |
+
def create_pptx_file(results: List[Dict], topic: str, template_name: str, theme_name: str = "λ―Έλλ© λΌμ΄νΈ") -> str:
|
945 |
+
"""μμ±λ κ²°κ³Όλ₯Ό PPTX νμΌλ‘ λ³ν (λ°νμ λ
ΈνΈ ν¬ν¨)"""
|
946 |
+
print(f"[PPTX] νμΌ μμ± μμ... ν
λ§: {theme_name}")
|
947 |
+
|
948 |
+
# νλ μ ν
μ΄μ
μμ± (16:9 λΉμ¨)
|
949 |
+
prs = Presentation()
|
950 |
+
prs.slide_width = Inches(16)
|
951 |
+
prs.slide_height = Inches(9)
|
952 |
+
|
953 |
+
# μ νλ ν
λ§ κ°μ Έμ€κΈ°
|
954 |
+
theme = DESIGN_THEMES.get(theme_name, DESIGN_THEMES["λ―Έλλ© λΌμ΄νΈ"])
|
955 |
+
|
956 |
+
# κ° κ²°κ³Ό μ¬λΌμ΄λ μΆκ°
|
957 |
+
for i, result in enumerate(results):
|
958 |
+
if not result.get("success", False):
|
959 |
+
continue
|
960 |
+
|
961 |
+
slide_data = result.get("slide_data", {})
|
962 |
+
|
963 |
+
# λΉ λ μ΄μμ μ¬μ© (μ λͺ© νλ μ΄μ€νλ μλ μμ ν λΉ μ¬λΌμ΄λ)
|
964 |
+
blank_layout = prs.slide_layouts[6] # μμ ν λΉ λ μ΄μμ
|
965 |
+
slide = prs.slides.add_slide(blank_layout)
|
966 |
+
|
967 |
+
# νμ§ μ¬λΌμ΄λ
|
968 |
+
if slide_data.get('title') == 'νμ§':
|
969 |
+
# λ°°κ²½ μ΄λ―Έμ§ μΆκ°
|
970 |
+
if slide_data.get('image'):
|
971 |
+
try:
|
972 |
+
img_buffer = BytesIO()
|
973 |
+
slide_data['image'].save(img_buffer, format='PNG')
|
974 |
+
img_buffer.seek(0)
|
975 |
+
|
976 |
+
# μ 체 νλ©΄ λ°°κ²½ μ΄λ―Έμ§
|
977 |
+
pic = slide.shapes.add_picture(
|
978 |
+
img_buffer,
|
979 |
+
0, 0,
|
980 |
+
width=prs.slide_width,
|
981 |
+
height=prs.slide_height
|
982 |
+
)
|
983 |
+
# 맨 λ€λ‘ 보λ΄κΈ°
|
984 |
+
slide.shapes._spTree.remove(pic._element)
|
985 |
+
slide.shapes._spTree.insert(2, pic._element)
|
986 |
+
except Exception as e:
|
987 |
+
print(f"[PPTX] νμ§ μ΄λ―Έμ§ μΆκ° μ€ν¨: {str(e)}")
|
988 |
+
|
989 |
+
# μ λͺ© λ°°κ²½ λ°μ€ (λ°ν¬λͺ
)
|
990 |
+
title_bg = slide.shapes.add_shape(
|
991 |
+
MSO_SHAPE.ROUNDED_RECTANGLE,
|
992 |
+
Inches(2), Inches(2.5),
|
993 |
+
Inches(12), Inches(4)
|
994 |
+
)
|
995 |
+
title_bg.fill.solid()
|
996 |
+
title_bg.fill.fore_color.rgb = RGBColor(0, 0, 0)
|
997 |
+
title_bg.fill.transparency = 0.5
|
998 |
+
title_bg.adjustments[0] = 0.1
|
999 |
+
title_bg.line.fill.background()
|
1000 |
+
|
1001 |
+
# μ λͺ© ν
μ€νΈ μΆκ°
|
1002 |
+
title_box = slide.shapes.add_textbox(
|
1003 |
+
Inches(2), Inches(3),
|
1004 |
+
Inches(12), Inches(3)
|
1005 |
+
)
|
1006 |
+
title_frame = title_box.text_frame
|
1007 |
+
title_frame.text = topic
|
1008 |
+
title_para = title_frame.paragraphs[0]
|
1009 |
+
title_para.font.size = Pt(48)
|
1010 |
+
title_para.font.bold = True
|
1011 |
+
title_para.font.color.rgb = RGBColor(255, 255, 255)
|
1012 |
+
title_para.alignment = PP_ALIGN.CENTER
|
1013 |
+
|
1014 |
+
# λΆμ λͺ© μΆκ°
|
1015 |
+
subtitle_box = slide.shapes.add_textbox(
|
1016 |
+
Inches(2), Inches(6),
|
1017 |
+
Inches(12), Inches(2)
|
1018 |
+
)
|
1019 |
+
subtitle_frame = subtitle_box.text_frame
|
1020 |
+
subtitle_frame.text = slide_data.get('subtitle', f'{template_name} - AI νλ μ ν
μ΄μ
')
|
1021 |
+
subtitle_para = subtitle_frame.paragraphs[0]
|
1022 |
+
subtitle_para.font.size = Pt(24)
|
1023 |
+
subtitle_para.font.color.rgb = RGBColor(255, 255, 255)
|
1024 |
+
subtitle_para.alignment = PP_ALIGN.CENTER
|
1025 |
+
|
1026 |
+
# Thank You μ¬λΌμ΄λ
|
1027 |
+
elif slide_data.get('title') == 'Thank You':
|
1028 |
+
# λ°°κ²½ μ΄λ―Έμ§ μΆκ°
|
1029 |
+
if slide_data.get('image'):
|
1030 |
+
try:
|
1031 |
+
img_buffer = BytesIO()
|
1032 |
+
slide_data['image'].save(img_buffer, format='PNG')
|
1033 |
+
img_buffer.seek(0)
|
1034 |
+
|
1035 |
+
# μ 체 νλ©΄ λ°°κ²½ μ΄λ―Έμ§
|
1036 |
+
pic = slide.shapes.add_picture(
|
1037 |
+
img_buffer,
|
1038 |
+
0, 0,
|
1039 |
+
width=prs.slide_width,
|
1040 |
+
height=prs.slide_height
|
1041 |
+
)
|
1042 |
+
# 맨 λ€λ‘ 보λ΄κΈ°
|
1043 |
+
slide.shapes._spTree.remove(pic._element)
|
1044 |
+
slide.shapes._spTree.insert(2, pic._element)
|
1045 |
+
except Exception as e:
|
1046 |
+
print(f"[PPTX] Thank You μ΄λ―Έμ§ μΆκ° μ€ν¨: {str(e)}")
|
1047 |
+
|
1048 |
+
# Thank You λ°°κ²½ λ°μ€
|
1049 |
+
thanks_bg = slide.shapes.add_shape(
|
1050 |
+
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1051 |
+
Inches(3), Inches(3),
|
1052 |
+
Inches(10), Inches(3)
|
1053 |
+
)
|
1054 |
+
thanks_bg.fill.solid()
|
1055 |
+
thanks_bg.fill.fore_color.rgb = RGBColor(0, 0, 0)
|
1056 |
+
thanks_bg.fill.transparency = 0.5
|
1057 |
+
thanks_bg.adjustments[0] = 0.1
|
1058 |
+
thanks_bg.line.fill.background()
|
1059 |
+
|
1060 |
+
# Thank You ν
μ€νΈ
|
1061 |
+
thanks_box = slide.shapes.add_textbox(
|
1062 |
+
Inches(2), Inches(3.5),
|
1063 |
+
Inches(12), Inches(2)
|
1064 |
+
)
|
1065 |
+
thanks_frame = thanks_box.text_frame
|
1066 |
+
thanks_frame.text = "Thank You"
|
1067 |
+
thanks_para = thanks_frame.paragraphs[0]
|
1068 |
+
thanks_para.font.size = Pt(60)
|
1069 |
+
thanks_para.font.bold = True
|
1070 |
+
thanks_para.font.color.rgb = RGBColor(255, 255, 255)
|
1071 |
+
thanks_para.alignment = PP_ALIGN.CENTER
|
1072 |
+
|
1073 |
+
# μΌλ° μ¬λΌμ΄λ
|
1074 |
+
else:
|
1075 |
+
# λ°°κ²½μ μ€μ
|
1076 |
+
background = slide.background
|
1077 |
+
fill = background.fill
|
1078 |
+
fill.solid()
|
1079 |
+
fill.fore_color.rgb = theme["background"]
|
1080 |
+
|
1081 |
+
# μ¬λΌμ΄λ μ λͺ© λ°°κ²½ λ°μ€ (λ₯κ·Ό λͺ¨μ리 ν¨κ³Ό)
|
1082 |
+
title_box_bg = slide.shapes.add_shape(
|
1083 |
+
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1084 |
+
Inches(0.3), Inches(0.2),
|
1085 |
+
Inches(15.4), Inches(1.0)
|
1086 |
+
)
|
1087 |
+
title_box_bg.fill.solid()
|
1088 |
+
title_box_bg.fill.fore_color.rgb = theme["box_fill"]
|
1089 |
+
title_box_bg.fill.transparency = 1 - theme["box_opacity"]
|
1090 |
+
|
1091 |
+
# λ₯κ·Ό μ λ μ‘°μ
|
1092 |
+
title_box_bg.adjustments[0] = 0.15 # λ₯κ·Ό μ λ (0-1)
|
1093 |
+
|
1094 |
+
# κ·Έλ¦Όμ ν¨κ³Ό
|
1095 |
+
if theme["shadow"]:
|
1096 |
+
shadow = title_box_bg.shadow
|
1097 |
+
shadow.visible = True
|
1098 |
+
shadow.distance = Pt(4)
|
1099 |
+
shadow.size = 100
|
1100 |
+
shadow.blur_radius = Pt(8)
|
1101 |
+
shadow.transparency = 0.75
|
1102 |
+
shadow.angle = 45
|
1103 |
+
|
1104 |
+
title_box_bg.line.fill.background() # ν
λ리 μμ
|
1105 |
+
|
1106 |
+
# μ¬λΌμ΄λ μ λͺ© μΆκ°
|
1107 |
+
title_box = slide.shapes.add_textbox(
|
1108 |
+
Inches(0.5), Inches(0.3),
|
1109 |
+
Inches(15), Inches(0.8)
|
1110 |
+
)
|
1111 |
+
title_frame = title_box.text_frame
|
1112 |
+
title_frame.text = f"{slide_data.get('title', '')}"
|
1113 |
+
title_para = title_frame.paragraphs[0]
|
1114 |
+
title_para.font.size = Pt(28)
|
1115 |
+
title_para.font.bold = True
|
1116 |
+
title_para.font.color.rgb = theme["title_color"]
|
1117 |
+
|
1118 |
+
# μ’μΈ‘ ν
μ€νΈ μμ λ°°κ²½ λ°μ€
|
1119 |
+
text_box_bg = slide.shapes.add_shape(
|
1120 |
+
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1121 |
+
Inches(0.3), Inches(1.4),
|
1122 |
+
Inches(7.8), Inches(6.8)
|
1123 |
+
)
|
1124 |
+
text_box_bg.fill.solid()
|
1125 |
+
text_box_bg.fill.fore_color.rgb = theme["box_fill"]
|
1126 |
+
text_box_bg.fill.transparency = 1 - theme["box_opacity"]
|
1127 |
+
|
1128 |
+
# λ₯κ·Ό μ λ μ‘°μ
|
1129 |
+
text_box_bg.adjustments[0] = 0.12
|
1130 |
+
|
1131 |
+
if theme["shadow"]:
|
1132 |
+
shadow = text_box_bg.shadow
|
1133 |
+
shadow.visible = True
|
1134 |
+
shadow.distance = Pt(5)
|
1135 |
+
shadow.size = 100
|
1136 |
+
shadow.blur_radius = Pt(10)
|
1137 |
+
shadow.transparency = 0.7
|
1138 |
+
shadow.angle = 45
|
1139 |
+
|
1140 |
+
text_box_bg.line.fill.background()
|
1141 |
+
|
1142 |
+
# μ’μΈ‘ ν
μ€νΈ μμ
|
1143 |
+
text_box = slide.shapes.add_textbox(
|
1144 |
+
Inches(0.8), Inches(1.8),
|
1145 |
+
Inches(7.0), Inches(6.0)
|
1146 |
+
)
|
1147 |
+
text_frame = text_box.text_frame
|
1148 |
+
text_frame.word_wrap = True
|
1149 |
+
|
1150 |
+
# μμ λͺ© μΆκ°
|
1151 |
+
subtitle_para = text_frame.paragraphs[0]
|
1152 |
+
subtitle_para.text = slide_data.get('subtitle', '')
|
1153 |
+
subtitle_para.font.size = Pt(20)
|
1154 |
+
subtitle_para.font.bold = True
|
1155 |
+
subtitle_para.font.color.rgb = theme["subtitle_color"]
|
1156 |
+
subtitle_para.space_after = Pt(20)
|
1157 |
+
|
1158 |
+
# λΆλ¦Ώ ν¬μΈνΈ μΆκ°
|
1159 |
+
bullet_points = slide_data.get('bullet_points', [])
|
1160 |
+
for point in bullet_points:
|
1161 |
+
p = text_frame.add_paragraph()
|
1162 |
+
p.text = point.replace('β’', '').strip()
|
1163 |
+
p.font.size = Pt(16)
|
1164 |
+
p.font.color.rgb = theme["text_color"]
|
1165 |
+
p.level = 0
|
1166 |
+
p.space_after = Pt(12)
|
1167 |
+
p.line_spacing = 1.5
|
1168 |
+
|
1169 |
+
# λΆλ¦Ώ μμ
|
1170 |
+
p.font.color.rgb = theme["text_color"]
|
1171 |
+
|
1172 |
+
# μ°μΈ‘ μ΄λ―Έμ§ μμ λ°°κ²½ λ°μ€
|
1173 |
+
img_box_bg = slide.shapes.add_shape(
|
1174 |
+
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1175 |
+
Inches(8.3), Inches(1.4),
|
1176 |
+
Inches(7.4), Inches(6.8)
|
1177 |
+
)
|
1178 |
+
img_box_bg.fill.solid()
|
1179 |
+
img_box_bg.fill.fore_color.rgb = RGBColor(248, 249, 250)
|
1180 |
+
img_box_bg.fill.transparency = 0.1
|
1181 |
+
|
1182 |
+
# λ₯κ·Ό μ λ μ‘°μ
|
1183 |
+
img_box_bg.adjustments[0] = 0.12
|
1184 |
+
|
1185 |
+
if theme["shadow"]:
|
1186 |
+
shadow = img_box_bg.shadow
|
1187 |
+
shadow.visible = True
|
1188 |
+
shadow.distance = Pt(5)
|
1189 |
+
shadow.size = 100
|
1190 |
+
shadow.blur_radius = Pt(10)
|
1191 |
+
shadow.transparency = 0.7
|
1192 |
+
shadow.angle = 45
|
1193 |
+
|
1194 |
+
img_box_bg.line.fill.background()
|
1195 |
+
|
1196 |
+
# μ°μΈ‘ μ΄λ―Έμ§ μΆκ°
|
1197 |
+
if slide_data.get('image'):
|
1198 |
+
try:
|
1199 |
+
img_buffer = BytesIO()
|
1200 |
+
slide_data['image'].save(img_buffer, format='PNG')
|
1201 |
+
img_buffer.seek(0)
|
1202 |
+
|
1203 |
+
pic = slide.shapes.add_picture(
|
1204 |
+
img_buffer,
|
1205 |
+
Inches(8.5), Inches(1.6),
|
1206 |
+
width=Inches(6.8), height=Inches(6.4)
|
1207 |
+
)
|
1208 |
+
|
1209 |
+
# μ΄λ―Έμ§ ν
λ리 μ κ±°
|
1210 |
+
pic.line.fill.background()
|
1211 |
+
|
1212 |
+
except Exception as e:
|
1213 |
+
print(f"[PPTX] μ΄λ―Έμ§ μΆκ° μ€ν¨: {str(e)}")
|
1214 |
+
|
1215 |
+
# νμ΄μ§ λ²νΈ μΆκ°
|
1216 |
+
page_num = slide.shapes.add_textbox(
|
1217 |
+
Inches(15), Inches(8.5),
|
1218 |
+
Inches(1), Inches(0.5)
|
1219 |
+
)
|
1220 |
+
page_frame = page_num.text_frame
|
1221 |
+
page_frame.text = str(i + 1)
|
1222 |
+
page_para = page_frame.paragraphs[0]
|
1223 |
+
page_para.font.size = Pt(12)
|
1224 |
+
page_para.font.color.rgb = theme["text_color"]
|
1225 |
+
page_para.alignment = PP_ALIGN.RIGHT
|
1226 |
+
|
1227 |
+
# λ°νμ λ
ΈνΈ μΆκ°
|
1228 |
+
notes_slide = slide.notes_slide
|
1229 |
+
notes_slide.notes_text_frame.text = slide_data.get('speaker_notes', '')
|
1230 |
+
|
1231 |
+
# νμΌ μ μ₯
|
1232 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
1233 |
+
filename = f"presentation_{timestamp}.pptx"
|
1234 |
+
filepath = os.path.join("/tmp", filename)
|
1235 |
+
prs.save(filepath)
|
1236 |
+
|
1237 |
+
print(f"[PPTX] νμΌ μμ± μλ£: {filename}")
|
1238 |
+
return filepath
|
1239 |
+
|
1240 |
+
def generate_dynamic_slides(topic: str, template: Dict, slide_count: int) -> List[Dict]:
|
1241 |
+
"""μ νλ μ¬λΌμ΄λ μμ λ°λΌ λμ μΌλ‘ μ¬λΌμ΄λ ꡬμ±"""
|
1242 |
+
core_slides = template.get("core_slides", [])
|
1243 |
+
optional_slides = template.get("optional_slides", [])
|
1244 |
+
|
1245 |
+
# νμ§μ Thank Youλ₯Ό μ μΈν λ³Έλ¬Έ μ¬λΌμ΄λ μ
|
1246 |
+
content_slide_count = slide_count
|
1247 |
+
|
1248 |
+
# μ½μ΄ μ¬λΌμ΄λκ° μμ²λ μλ³΄λ€ λ§μΌλ©΄ μ‘°μ
|
1249 |
+
if len(core_slides) > content_slide_count:
|
1250 |
+
selected_slides = core_slides[:content_slide_count]
|
1251 |
+
else:
|
1252 |
+
# μ½μ΄ μ¬λΌμ΄λ + μ΅μ
λ μ¬λΌμ΄λμμ μ ν
|
1253 |
+
selected_slides = core_slides.copy()
|
1254 |
+
remaining = content_slide_count - len(core_slides)
|
1255 |
+
|
1256 |
+
if remaining > 0 and optional_slides:
|
1257 |
+
# μ΅μ
λ μ¬λΌμ΄λμμ μΆκ° μ ν
|
1258 |
+
additional = optional_slides[:remaining]
|
1259 |
+
selected_slides.extend(additional)
|
1260 |
+
|
1261 |
+
# νμ§ μΆκ° (맨 μ)
|
1262 |
+
slides = [{"title": "νμ§", "style": "Title Slide (Hero)", "prompt_hint": "νλ μ ν
μ΄μ
νμ§"}]
|
1263 |
+
|
1264 |
+
# λ³Έλ¬Έ μ¬λΌμ΄λ μΆκ°
|
1265 |
+
slides.extend(selected_slides)
|
1266 |
+
|
1267 |
+
# Thank You μ¬λΌμ΄λ μΆκ° (맨 λ€)
|
1268 |
+
slides.append({"title": "Thank You", "style": "Thank You Slide", "prompt_hint": "κ°μ¬ μΈμ¬"})
|
1269 |
+
|
1270 |
+
return slides
|
1271 |
+
|
1272 |
+
def generate_ppt_with_content(topic: str, template_name: str, custom_slides: List[Dict],
|
1273 |
+
slide_count: int, seed: int, uploaded_file: str,
|
1274 |
+
use_web_search: bool, theme_name: str = "λ―Έλλ© λΌμ΄νΈ",
|
1275 |
+
progress=gr.Progress()):
|
1276 |
+
"""PPT μ΄λ―Έμ§μ ν
μ€νΈ λ΄μ©μ ν¨κ» μμ± (λ°νμ λ
ΈνΈ ν¬ν¨)"""
|
1277 |
+
results = []
|
1278 |
+
preview_html = ""
|
1279 |
+
|
1280 |
+
# μ
λ‘λλ νμΌ λ΄μ© μ½κΈ°
|
1281 |
+
uploaded_content = ""
|
1282 |
+
if uploaded_file:
|
1283 |
+
uploaded_content = read_uploaded_file(uploaded_file.name)
|
1284 |
+
print(f"[νμΌ μ
λ‘λ] λ΄μ© κΈΈμ΄: {len(uploaded_content)}μ")
|
1285 |
+
|
1286 |
+
# ν
νλ¦Ώ μ ν λ° μ¬λΌμ΄λ ꡬμ±
|
1287 |
+
if template_name == "μ¬μ©μ μ μ" and custom_slides:
|
1288 |
+
slides = [{"title": "νμ§", "style": "Title Slide (Hero)", "prompt_hint": "νλ μ ν
μ΄μ
νμ§"}]
|
1289 |
+
slides.extend(custom_slides)
|
1290 |
+
slides.append({"title": "Thank You", "style": "Thank You Slide", "prompt_hint": "κ°μ¬ μΈμ¬"})
|
1291 |
+
else:
|
1292 |
+
template = PPT_TEMPLATES[template_name]
|
1293 |
+
slides = generate_dynamic_slides(topic, template, slide_count)
|
1294 |
+
|
1295 |
+
if not slides:
|
1296 |
+
yield "", "μ¬λΌμ΄λκ° μ μλμ§ μμμ΅λλ€.", None
|
1297 |
+
return
|
1298 |
+
|
1299 |
+
total_slides = len(slides)
|
1300 |
+
print(f"\n[PPT μμ±] μμ - μ΄ {total_slides}κ° μ¬λΌμ΄λ (νμ§ + λ³Έλ¬Έ {slide_count} + Thank You)")
|
1301 |
+
print(f"[PPT μμ±] μ£Όμ : {topic}")
|
1302 |
+
print(f"[PPT μμ±] ν
νλ¦Ώ: {template_name}")
|
1303 |
+
print(f"[PPT μμ±] λμμΈ ν
λ§: {theme_name}")
|
1304 |
+
print(f"[PPT μμ±] μΉ κ²μ: {'μ¬μ©' if use_web_search else 'λ―Έμ¬μ©'}")
|
1305 |
+
|
1306 |
+
# μΉ κ²μ μ€ν (μ νλ κ²½μ°)
|
1307 |
+
web_search_results = []
|
1308 |
+
if use_web_search and BRAVE_API_TOKEN:
|
1309 |
+
progress(0.05, "μΉ κ²μ μ€...")
|
1310 |
+
web_search_results = brave_search(topic)
|
1311 |
+
|
1312 |
+
# CSS μ€νμΌ μΆκ°
|
1313 |
+
preview_html = """
|
1314 |
+
<style>
|
1315 |
+
.slides-container {
|
1316 |
+
width: 100%;
|
1317 |
+
max-width: 1400px;
|
1318 |
+
margin: 0 auto;
|
1319 |
+
}
|
1320 |
+
</style>
|
1321 |
+
<div class="slides-container">
|
1322 |
+
"""
|
1323 |
+
|
1324 |
+
# κ° μ¬λΌμ΄λ μμ°¨ μ²λ¦¬
|
1325 |
+
for i, slide in enumerate(slides):
|
1326 |
+
progress((i + 1) / (total_slides + 1), f"μ¬λΌμ΄λ {i+1}/{total_slides} μ²λ¦¬ μ€...")
|
1327 |
+
|
1328 |
+
slide_info = f"μ¬λΌμ΄λ {i+1}: {slide['title']}"
|
1329 |
+
|
1330 |
+
# ν
μ€νΈ λ΄μ© μμ±
|
1331 |
+
slide_context = f"{slide['title']} - {slide.get('prompt_hint', '')}"
|
1332 |
+
content = generate_slide_content(
|
1333 |
+
topic, slide['title'], slide_context,
|
1334 |
+
uploaded_content, web_search_results
|
1335 |
+
)
|
1336 |
+
|
1337 |
+
# λ°νμ λ
ΈνΈ μμ±
|
1338 |
+
speaker_notes = generate_presentation_notes(topic, slide['title'], content)
|
1339 |
+
|
1340 |
+
# ν둬ννΈ μμ± λ° μ΄λ―Έμ§ μμ±
|
1341 |
+
style_key = slide["style"]
|
1342 |
+
if style_key in STYLE_TEMPLATES:
|
1343 |
+
style_info = STYLE_TEMPLATES[style_key]
|
1344 |
+
prompt = generate_prompt_with_llm(
|
1345 |
+
topic, style_info["example"],
|
1346 |
+
slide_context, uploaded_content
|
1347 |
+
)
|
1348 |
+
|
1349 |
+
# μ΄λ―Έμ§ μμ±
|
1350 |
+
slide_seed = seed + i
|
1351 |
+
img, used_prompt = generate_image(prompt, slide_seed, slide_info)
|
1352 |
+
|
1353 |
+
# μ¬λΌμ΄λ λ°μ΄ν° ꡬμ±
|
1354 |
+
slide_data = {
|
1355 |
+
"slide_number": i + 1,
|
1356 |
+
"title": slide["title"],
|
1357 |
+
"subtitle": content["subtitle"],
|
1358 |
+
"bullet_points": content["bullet_points"],
|
1359 |
+
"image": img,
|
1360 |
+
"style": style_info["name"],
|
1361 |
+
"speaker_notes": speaker_notes,
|
1362 |
+
"topic": topic # νμ§μ©
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
# ν리뷰 HTML μμ±
|
1366 |
+
preview_html += create_slide_preview_html(slide_data)
|
1367 |
+
|
1368 |
+
# νμ¬κΉμ§μ μν μ
λ°μ΄νΈ
|
1369 |
+
yield preview_html + "</div>", f"### π {slide_info} μμ± μ€...", None
|
1370 |
+
|
1371 |
+
results.append({
|
1372 |
+
"slide_data": slide_data,
|
1373 |
+
"success": img is not None
|
1374 |
+
})
|
1375 |
+
|
1376 |
+
# PPTX νμΌ μμ±
|
1377 |
+
progress(0.95, "PPTX νμΌ μμ± μ€...")
|
1378 |
+
pptx_path = None
|
1379 |
+
try:
|
1380 |
+
pptx_path = create_pptx_file(results, topic, template_name, theme_name)
|
1381 |
+
except Exception as e:
|
1382 |
+
print(f"[PPTX] νμΌ μμ± μ€λ₯: {str(e)}")
|
1383 |
+
|
1384 |
+
# μ΅μ’
κ²°κ³Ό
|
1385 |
+
preview_html += "</div>"
|
1386 |
+
progress(1.0, "μλ£!")
|
1387 |
+
successful = sum(1 for r in results if r["success"])
|
1388 |
+
final_status = f"### π μμ± μλ£! μ΄ {total_slides}κ° μ¬λΌμ΄λ μ€ {successful}κ° μ±κ³΅"
|
1389 |
+
|
1390 |
+
if pptx_path:
|
1391 |
+
final_status += f"\n\n### π₯ PPTX νμΌμ΄ μ€λΉλμμ΅λλ€! μλμμ λ€μ΄λ‘λνμΈμ."
|
1392 |
+
final_status += f"\n\nπ‘ **λ°νμ λ
ΈνΈκ° κ° μ¬λΌμ΄λμ ν¬ν¨λμ΄ μμ΅λλ€!**"
|
1393 |
+
|
1394 |
+
yield preview_html, final_status, pptx_path
|
1395 |
+
|
1396 |
+
def create_custom_slides_ui():
|
1397 |
+
"""μ¬μ©μ μ μ μ¬λΌμ΄λ κ΅¬μ± UI (3-20μ₯)"""
|
1398 |
+
slides = []
|
1399 |
+
for i in range(20): # μ΅λ 20μ₯
|
1400 |
+
with gr.Row(visible=(i < 3)): # κΈ°λ³Έ 3μ₯λ§ νμ
|
1401 |
+
with gr.Column(scale=2):
|
1402 |
+
title = gr.Textbox(
|
1403 |
+
label=f"μ¬λΌμ΄λ {i+1} μ λͺ©",
|
1404 |
+
placeholder="μ: νν© λΆμ, μ루μ
, λ‘λλ§΅...",
|
1405 |
+
)
|
1406 |
+
with gr.Column(scale=3):
|
1407 |
+
style = gr.Dropdown(
|
1408 |
+
choices=list(STYLE_TEMPLATES.keys()),
|
1409 |
+
label=f"μ€νμΌ μ ν",
|
1410 |
+
value="Colorful Mind Map"
|
1411 |
+
)
|
1412 |
+
with gr.Column(scale=3):
|
1413 |
+
hint = gr.Textbox(
|
1414 |
+
label=f"ν둬ννΈ ννΈ",
|
1415 |
+
placeholder="μ΄ μ¬λΌμ΄λμμ νννκ³ μΆμ λ΄μ©"
|
1416 |
+
)
|
1417 |
+
slides.append({"title": title, "style": style, "hint": hint, "row": gr.Row})
|
1418 |
+
return slides
|
1419 |
+
|
1420 |
+
# Gradio μΈν°νμ΄μ€ μμ±
|
1421 |
+
with gr.Blocks(title="PPT μ΄λ―Έμ§ μμ±κΈ°", theme=gr.themes.Soft(), css="""
|
1422 |
+
.preview-container { max-width: 1400px; margin: 0 auto; }
|
1423 |
+
""") as demo:
|
1424 |
+
gr.Markdown("""
|
1425 |
+
# π― AI κΈ°λ° PPT ν΅ν© μμ±κΈ° (λμμΈ ν
λ§ ν¬ν¨)
|
1426 |
+
|
1427 |
+
### ν
μ€νΈμ μ΄λ―Έμ§κ° μλ²½νκ² μ‘°νλ νλ μ ν
μ΄μ
μ μλμΌλ‘ μμ±νκ³ λ€μ΄λ‘λνμΈμ!
|
1428 |
+
|
1429 |
+
#### π μλ‘μ΄ κΈ°λ₯:
|
1430 |
+
- π¨ **λμμΈ ν
λ§**: 5κ°μ§ μ λ¬Έμ μΈ λμμΈ ν
λ§ μ ν κ°λ₯
|
1431 |
+
- π **νμ§μ Thank You μ¬λΌμ΄λ** μλ μΆκ°
|
1432 |
+
- π **λ°νμ λ
ΈνΈ** μλ μμ± (ꡬμ΄μ²΄)
|
1433 |
+
- π **νμΌ μ
λ‘λ** μ§μ (PDF/CSV/TXT)
|
1434 |
+
- π **μΉ κ²μ** κΈ°λ₯ (Brave Search)
|
1435 |
+
- ποΈ **μ¬λΌμ΄λ μ μ‘°μ ** (6-20μ₯)
|
1436 |
+
- π **μ
μ²΄κ° μλ λμμΈ**: λ₯κ·Ό λͺ¨μ리μ κ·Έλ¦Όμ ν¨κ³Ό
|
1437 |
+
""")
|
1438 |
+
|
1439 |
+
# API ν ν° μν νμΈ
|
1440 |
+
token_status = []
|
1441 |
+
if not REPLICATE_API_TOKEN:
|
1442 |
+
token_status.append("οΏ½οΏ½οΈ RAPI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
1443 |
+
if not FRIENDLI_TOKEN:
|
1444 |
+
token_status.append("β οΈ FRIENDLI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
1445 |
+
if not BRAVE_API_TOKEN:
|
1446 |
+
token_status.append("βΉοΈ BAPI_TOKENμ΄ μμ΄ μΉ κ²μ κΈ°λ₯μ΄ λΉνμ±νλ©λλ€.")
|
1447 |
+
|
1448 |
+
if token_status:
|
1449 |
+
gr.Markdown("\n".join(token_status))
|
1450 |
+
|
1451 |
+
with gr.Row():
|
1452 |
+
with gr.Column(scale=1):
|
1453 |
+
# κΈ°λ³Έ μ
λ ₯
|
1454 |
+
topic_input = gr.Textbox(
|
1455 |
+
label="νλ μ ν
μ΄μ
μ£Όμ ",
|
1456 |
+
placeholder="μ: AI μ€ννΈμ
ν¬μ μ μΉ, μ μ ν λ°μΉ, λμ§νΈ μ ν μ λ΅",
|
1457 |
+
lines=2
|
1458 |
+
)
|
1459 |
+
|
1460 |
+
# PPT ν
νλ¦Ώ μ ν
|
1461 |
+
template_select = gr.Dropdown(
|
1462 |
+
choices=list(PPT_TEMPLATES.keys()),
|
1463 |
+
label="PPT ν
νλ¦Ώ μ ν",
|
1464 |
+
value="λΉμ¦λμ€ μ μμ",
|
1465 |
+
info="λͺ©μ μ λ§λ ν
νλ¦Ώμ μ ννμΈμ"
|
1466 |
+
)
|
1467 |
+
|
1468 |
+
# λμμΈ ν
λ§ μ ν
|
1469 |
+
theme_select = gr.Dropdown(
|
1470 |
+
choices=list(DESIGN_THEMES.keys()),
|
1471 |
+
label="λμμΈ ν
λ§ μ ν",
|
1472 |
+
value="λ―Έλλ© λΌμ΄νΈ",
|
1473 |
+
info="νλ μ ν
μ΄μ
μ μ 체μ μΈ λμμΈ μ€νμΌ"
|
1474 |
+
)
|
1475 |
+
|
1476 |
+
# ν
λ§ λ―Έλ¦¬λ³΄κΈ°
|
1477 |
+
theme_preview = gr.HTML()
|
1478 |
+
|
1479 |
+
# μ¬λΌμ΄λ μ μ ν
|
1480 |
+
slide_count = gr.Slider(
|
1481 |
+
minimum=6,
|
1482 |
+
maximum=20,
|
1483 |
+
value=8,
|
1484 |
+
step=1,
|
1485 |
+
label="λ³Έλ¬Έ μ¬λΌμ΄λ μ (νμ§μ Thank You μ μΈ)",
|
1486 |
+
info="μμ±ν λ³Έλ¬Έ μ¬λΌμ΄λ μλ₯Ό μ ννμΈμ"
|
1487 |
+
)
|
1488 |
+
|
1489 |
+
# νμΌ μ
λ‘λ
|
1490 |
+
file_upload = gr.File(
|
1491 |
+
label="μ°Έκ³ μλ£ μ
λ‘λ (μ ν)",
|
1492 |
+
file_types=[".pdf", ".csv", ".txt"],
|
1493 |
+
type="filepath"
|
1494 |
+
)
|
1495 |
+
|
1496 |
+
# μΉ κ²μ μ΅μ
|
1497 |
+
use_web_search = gr.Checkbox(
|
1498 |
+
label="μΉ κ²μ μ¬μ©",
|
1499 |
+
value=False,
|
1500 |
+
info="Brave Searchλ₯Ό μ¬μ©νμ¬ μ΅μ μ 보 λ°μ"
|
1501 |
+
)
|
1502 |
+
|
1503 |
+
# ν
νλ¦Ώ μ€λͺ
|
1504 |
+
template_info = gr.Markdown()
|
1505 |
+
|
1506 |
+
# μλ κ°
|
1507 |
+
seed_input = gr.Slider(
|
1508 |
+
minimum=1,
|
1509 |
+
maximum=100,
|
1510 |
+
value=10,
|
1511 |
+
step=1,
|
1512 |
+
label="μλ κ°"
|
1513 |
+
)
|
1514 |
+
|
1515 |
+
generate_btn = gr.Button("π PPT μ 체 μμ± (ν
μ€νΈ + μ΄λ―Έμ§ + λ°νλ
ΈνΈ)", variant="primary", size="lg")
|
1516 |
+
|
1517 |
+
# PPTX λ€μ΄λ‘λ μμ
|
1518 |
+
with gr.Row():
|
1519 |
+
download_file = gr.File(
|
1520 |
+
label="π₯ μμ±λ PPTX νμΌ λ€μ΄λ‘λ",
|
1521 |
+
visible=True,
|
1522 |
+
elem_id="download-file"
|
1523 |
+
)
|
1524 |
+
|
1525 |
+
# μ¬μ©μ μ μ μΉμ
|
1526 |
+
with gr.Accordion("π μ¬μ©μ μ μ μ¬λΌμ΄λ ꡬμ±", open=False) as custom_accordion:
|
1527 |
+
gr.Markdown("ν
νλ¦Ώμ μ¬μ©νμ§ μκ³ μ§μ μ¬λΌμ΄λλ₯Ό ꡬμ±νμΈμ. (3-20μ₯)")
|
1528 |
+
|
1529 |
+
# μ¬μ©μ μ μ μ¬λΌμ΄λ μ μ ν
|
1530 |
+
custom_slide_count = gr.Slider(
|
1531 |
+
minimum=3,
|
1532 |
+
maximum=20,
|
1533 |
+
value=3,
|
1534 |
+
step=1,
|
1535 |
+
label="μ¬μ©μ μ μ μ¬λΌμ΄λ μ"
|
1536 |
+
)
|
1537 |
+
|
1538 |
+
custom_slides_components = create_custom_slides_ui()
|
1539 |
+
|
1540 |
+
# μν νμ
|
1541 |
+
status_output = gr.Markdown(
|
1542 |
+
value="### π ν
νλ¦Ώμ μ ννκ³ μμ± λ²νΌμ ν΄λ¦νμΈμ!"
|
1543 |
+
)
|
1544 |
+
|
1545 |
+
# ν리뷰 μμ
|
1546 |
+
preview_output = gr.HTML(
|
1547 |
+
label="PPT ν리뷰 (16:9)",
|
1548 |
+
elem_classes="preview-container"
|
1549 |
+
)
|
1550 |
+
|
1551 |
+
# μ΄λ²€νΈ νΈλ€λ¬
|
1552 |
+
def update_theme_preview(theme_name):
|
1553 |
+
"""ν
λ§ λ―Έλ¦¬λ³΄κΈ° HTML μμ±"""
|
1554 |
+
theme = DESIGN_THEMES.get(theme_name, DESIGN_THEMES["λ―Έλλ© λΌμ΄νΈ"])
|
1555 |
+
|
1556 |
+
# RGB κ°μ hexλ‘ λ³ν
|
1557 |
+
def rgb_to_hex(rgb_color):
|
1558 |
+
return f"#{rgb_color.r:02x}{rgb_color.g:02x}{rgb_color.b:02x}"
|
1559 |
+
|
1560 |
+
bg_hex = rgb_to_hex(theme["background"])
|
1561 |
+
box_hex = rgb_to_hex(theme["box_fill"])
|
1562 |
+
title_hex = rgb_to_hex(theme["title_color"])
|
1563 |
+
text_hex = rgb_to_hex(theme["text_color"])
|
1564 |
+
accent_hex = rgb_to_hex(theme["accent_color"])
|
1565 |
+
|
1566 |
+
preview_html = f"""
|
1567 |
+
<div style="
|
1568 |
+
background: {bg_hex};
|
1569 |
+
padding: 20px;
|
1570 |
+
border-radius: 8px;
|
1571 |
+
margin: 10px 0;
|
1572 |
+
">
|
1573 |
+
<div style="
|
1574 |
+
background: {box_hex};
|
1575 |
+
opacity: {theme['box_opacity']};
|
1576 |
+
padding: 15px;
|
1577 |
+
border-radius: 12px;
|
1578 |
+
margin-bottom: 10px;
|
1579 |
+
{'box-shadow: 0 4px 8px rgba(0,0,0,0.1);' if theme['shadow'] else ''}
|
1580 |
+
">
|
1581 |
+
<h4 style="color: {title_hex}; margin: 0 0 10px 0;">{theme['name']}</h4>
|
1582 |
+
<p style="color: {text_hex}; margin: 0; font-size: 14px;">
|
1583 |
+
{theme['description']}
|
1584 |
+
</p>
|
1585 |
+
<div style="
|
1586 |
+
width: 40px;
|
1587 |
+
height: 4px;
|
1588 |
+
background: {accent_hex};
|
1589 |
+
margin-top: 10px;
|
1590 |
+
border-radius: 2px;
|
1591 |
+
"></div>
|
1592 |
+
</div>
|
1593 |
+
</div>
|
1594 |
+
"""
|
1595 |
+
return preview_html
|
1596 |
+
|
1597 |
+
def update_template_info(template_name, slide_count):
|
1598 |
+
if template_name in PPT_TEMPLATES:
|
1599 |
+
template = PPT_TEMPLATES[template_name]
|
1600 |
+
info = f"**{template['description']}**\n\n"
|
1601 |
+
|
1602 |
+
# λμ μΌλ‘ μμ±λ μ¬λΌμ΄λ κ΅¬μ± νμ
|
1603 |
+
slides = generate_dynamic_slides("", template, slide_count)
|
1604 |
+
info += f"μμ±λ μ¬λΌμ΄λ ({len(slides)}μ₯):\n"
|
1605 |
+
for i, slide in enumerate(slides):
|
1606 |
+
style_info = STYLE_TEMPLATES.get(slide['style'], {})
|
1607 |
+
info += f"{i+1}. {slide['title']} - {style_info.get('use_case', '')}\n"
|
1608 |
+
|
1609 |
+
return info
|
1610 |
+
return ""
|
1611 |
+
|
1612 |
+
def update_custom_slides_visibility(count):
|
1613 |
+
"""μ¬μ©μ μ μ μ¬λΌμ΄λ μμ λ°λΌ UI νμ/μ¨κΉ"""
|
1614 |
+
updates = []
|
1615 |
+
for i in range(20):
|
1616 |
+
updates.extend([
|
1617 |
+
gr.update(visible=(i < count)), # title
|
1618 |
+
gr.update(visible=(i < count)), # style
|
1619 |
+
gr.update(visible=(i < count)) # hint
|
1620 |
+
])
|
1621 |
+
return updates
|
1622 |
+
|
1623 |
+
def generate_ppt_handler(topic, template_name, theme_name, slide_count, seed, file_upload,
|
1624 |
+
use_web_search, custom_slide_count, progress=gr.Progress(),
|
1625 |
+
*custom_inputs):
|
1626 |
+
if not topic.strip():
|
1627 |
+
yield "", "β μ£Όμ λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ.", None
|
1628 |
+
return
|
1629 |
+
|
1630 |
+
# μ¬μ©μ μ μ μ¬λΌμ΄λ μ²λ¦¬
|
1631 |
+
custom_slides = []
|
1632 |
+
if template_name == "μ¬μ©μ μ μ":
|
1633 |
+
for i in range(0, custom_slide_count * 3, 3):
|
1634 |
+
if i < len(custom_inputs):
|
1635 |
+
title = custom_inputs[i]
|
1636 |
+
style = custom_inputs[i+1] if i+1 < len(custom_inputs) else None
|
1637 |
+
hint = custom_inputs[i+2] if i+2 < len(custom_inputs) else ""
|
1638 |
+
|
1639 |
+
if title and style:
|
1640 |
+
custom_slides.append({
|
1641 |
+
"title": title,
|
1642 |
+
"style": style,
|
1643 |
+
"prompt_hint": hint
|
1644 |
+
})
|
1645 |
+
|
1646 |
+
# PPT μμ±
|
1647 |
+
for preview, status, pptx_file in generate_ppt_with_content(
|
1648 |
+
topic, template_name, custom_slides, slide_count, seed,
|
1649 |
+
file_upload, use_web_search, theme_name, progress
|
1650 |
+
):
|
1651 |
+
yield preview, status, pptx_file
|
1652 |
+
|
1653 |
+
# μ΄λ²€νΈ μ°κ²°
|
1654 |
+
theme_select.change(
|
1655 |
+
fn=update_theme_preview,
|
1656 |
+
inputs=[theme_select],
|
1657 |
+
outputs=[theme_preview]
|
1658 |
+
)
|
1659 |
+
|
1660 |
+
template_select.change(
|
1661 |
+
fn=update_template_info,
|
1662 |
+
inputs=[template_select, slide_count],
|
1663 |
+
outputs=[template_info]
|
1664 |
+
)
|
1665 |
+
|
1666 |
+
slide_count.change(
|
1667 |
+
fn=update_template_info,
|
1668 |
+
inputs=[template_select, slide_count],
|
1669 |
+
outputs=[template_info]
|
1670 |
+
)
|
1671 |
+
|
1672 |
+
custom_slide_count.change(
|
1673 |
+
fn=update_custom_slides_visibility,
|
1674 |
+
inputs=[custom_slide_count],
|
1675 |
+
outputs=[comp for slide in custom_slides_components for comp in [slide["title"], slide["style"], slide["hint"]]]
|
1676 |
+
)
|
1677 |
+
|
1678 |
+
# μ¬μ©μ μ μ μ
λ ₯ μμ§
|
1679 |
+
all_custom_inputs = []
|
1680 |
+
for slide_components in custom_slides_components:
|
1681 |
+
all_custom_inputs.extend([
|
1682 |
+
slide_components["title"],
|
1683 |
+
slide_components["style"],
|
1684 |
+
slide_components["hint"]
|
1685 |
+
])
|
1686 |
+
|
1687 |
+
generate_btn.click(
|
1688 |
+
fn=generate_ppt_handler,
|
1689 |
+
inputs=[topic_input, template_select, theme_select, slide_count, seed_input,
|
1690 |
+
file_upload, use_web_search, custom_slide_count] + all_custom_inputs,
|
1691 |
+
outputs=[preview_output, status_output, download_file]
|
1692 |
+
)
|
1693 |
+
|
1694 |
+
# μ΄κΈ° ν
νλ¦Ώ μ 보 νμ
|
1695 |
+
demo.load(
|
1696 |
+
fn=lambda template, slide_count, theme: (
|
1697 |
+
update_template_info(template, slide_count),
|
1698 |
+
update_theme_preview(theme)
|
1699 |
+
),
|
1700 |
+
inputs=[template_select, slide_count, theme_select],
|
1701 |
+
outputs=[template_info, theme_preview]
|
1702 |
+
)
|
1703 |
+
|
1704 |
+
# μ± μ€ν
|
1705 |
+
if __name__ == "__main__":
|
1706 |
+
print("\n" + "="*50)
|
1707 |
+
print("π PPT ν΅ν© μμ±κΈ° (λμμΈ ν
λ§ λ²μ ) μμ!")
|
1708 |
+
print("="*50)
|
1709 |
+
|
1710 |
+
# νκ²½ λ³μ νμΈ
|
1711 |
+
if not REPLICATE_API_TOKEN:
|
1712 |
+
print("β οΈ κ²½κ³ : RAPI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
1713 |
+
else:
|
1714 |
+
print("β
RAPI_TOKEN νμΈλ¨")
|
1715 |
+
|
1716 |
+
if not FRIENDLI_TOKEN:
|
1717 |
+
print("β οΈ κ²½κ³ : FRIENDLI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
1718 |
+
else:
|
1719 |
+
print("β
FRIENDLI_TOKEN νμΈλ¨")
|
1720 |
+
|
1721 |
+
if not BRAVE_API_TOKEN:
|
1722 |
+
print("βΉοΈ BAPI_TOKENμ΄ μμ΄ μΉ κ²μ κΈ°λ₯μ΄ λΉνμ±νλ©λλ€.")
|
1723 |
+
else:
|
1724 |
+
print("β
BAPI_TOKEN νμΈλ¨")
|
1725 |
+
|
1726 |
+
print("="*50 + "\n")
|
1727 |
+
|
1728 |
+
demo.launch()
|