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ests
|
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 |
+
|
21 |
+
# νκ²½ λ³μμμ ν ν° κ°μ Έμ€κΈ°
|
22 |
+
REPLICATE_API_TOKEN = os.getenv("RAPI_TOKEN")
|
23 |
+
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN")
|
24 |
+
|
25 |
+
# μ€νμΌ μ μ
|
26 |
+
STYLE_TEMPLATES = {
|
27 |
+
"3D Style (Pixar-like)": {
|
28 |
+
"name": "3D Style",
|
29 |
+
"description": "Pixar-esque 3D render with volumetric lighting",
|
30 |
+
"use_case": "νμ§, λΉμ , λ―Έλ 컨μ
",
|
31 |
+
"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."
|
32 |
+
},
|
33 |
+
"Elegant SWOT Quadrant": {
|
34 |
+
"name": "SWOT Analysis",
|
35 |
+
"description": "Flat-design 4-grid layout with minimal shadows",
|
36 |
+
"use_case": "νν© λΆμ, μ λ΅ νκ°",
|
37 |
+
"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"
|
38 |
+
},
|
39 |
+
"Colorful Mind Map": {
|
40 |
+
"name": "Mind Map",
|
41 |
+
"description": "Hand-drawn educational style with vibrant colors",
|
42 |
+
"use_case": "λΈλ μΈμ€ν λ°, μμ΄λμ΄ μ 리",
|
43 |
+
"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"
|
44 |
+
},
|
45 |
+
"Business Workflow": {
|
46 |
+
"name": "Business Process",
|
47 |
+
"description": "End-to-end business workflow with clear phases",
|
48 |
+
"use_case": "νλ‘μΈμ€ μ€λͺ
, λ¨κ³λ³ μ§ν",
|
49 |
+
"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"
|
50 |
+
},
|
51 |
+
"Industrial Design": {
|
52 |
+
"name": "Product Design",
|
53 |
+
"description": "Sleek industrial design concept sketch",
|
54 |
+
"use_case": "μ ν μκ°, 컨μ
λμμΈ",
|
55 |
+
"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"
|
56 |
+
},
|
57 |
+
"3D Bubble Chart": {
|
58 |
+
"name": "Bubble Chart",
|
59 |
+
"description": "Clean 3D bubble visualization",
|
60 |
+
"use_case": "λΉκ΅ λΆμ, ν¬μ§μ
λ",
|
61 |
+
"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"
|
62 |
+
},
|
63 |
+
"Timeline Ribbon": {
|
64 |
+
"name": "Timeline",
|
65 |
+
"description": "Horizontal ribbon timeline with cyber-futuristic vibe",
|
66 |
+
"use_case": "μΌμ , λ‘λλ§΅, λ§μΌμ€ν€",
|
67 |
+
"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"
|
68 |
+
},
|
69 |
+
"Risk Heat Map": {
|
70 |
+
"name": "Heat Map",
|
71 |
+
"description": "Risk assessment heat map with gradient colors",
|
72 |
+
"use_case": "리μ€ν¬ λΆμ, μ°μ μμ",
|
73 |
+
"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"
|
74 |
+
},
|
75 |
+
"Pyramid/Funnel": {
|
76 |
+
"name": "Funnel Chart",
|
77 |
+
"description": "Multi-layer gradient funnel visualization",
|
78 |
+
"use_case": "λ¨κ³λ³ μΆμ, ν΅μ¬ λμΆ",
|
79 |
+
"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"
|
80 |
+
},
|
81 |
+
"KPI Dashboard": {
|
82 |
+
"name": "Dashboard",
|
83 |
+
"description": "Dark-mode analytics dashboard with sci-fi interface",
|
84 |
+
"use_case": "μ±κ³Ό μ§ν, μ€μ λμ보λ",
|
85 |
+
"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"
|
86 |
+
},
|
87 |
+
"Value Chain": {
|
88 |
+
"name": "Value Chain",
|
89 |
+
"description": "Horizontal value chain with industrial look",
|
90 |
+
"use_case": "κ°μΉ μ¬μ¬, λΉμ¦λμ€ λͺ¨λΈ",
|
91 |
+
"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"
|
92 |
+
},
|
93 |
+
"Gantt Chart": {
|
94 |
+
"name": "Gantt Chart",
|
95 |
+
"description": "Hand-drawn style Gantt chart with playful colors",
|
96 |
+
"use_case": "νλ‘μ νΈ μΌμ , μμ
κ΄λ¦¬",
|
97 |
+
"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"
|
98 |
+
},
|
99 |
+
"Mobile App Mockup": {
|
100 |
+
"name": "App Mockup",
|
101 |
+
"description": "Clean wireframe for mobile app design",
|
102 |
+
"use_case": "μ±/μΉ UI, νλ©΄ μ€κ³",
|
103 |
+
"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"
|
104 |
+
},
|
105 |
+
"Flowchart": {
|
106 |
+
"name": "Flowchart",
|
107 |
+
"description": "Vibrant flowchart with minimalistic icons",
|
108 |
+
"use_case": "μμ¬κ²°μ , νλ‘μΈμ€ νλ¦",
|
109 |
+
"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"
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
# PPT ν
νλ¦Ώ μ μ
|
114 |
+
PPT_TEMPLATES = {
|
115 |
+
"λΉμ¦λμ€ μ μμ": {
|
116 |
+
"description": "ν¬μ μ μΉ, μ¬μ
μ μμ©",
|
117 |
+
"slides": [
|
118 |
+
{"title": "νμ§", "style": "3D Style (Pixar-like)", "prompt_hint": "νμ¬ λΉμ κ³Ό λ―Έλ"},
|
119 |
+
{"title": "λͺ©μ°¨", "style": "Flowchart", "prompt_hint": "νλ μ ν
μ΄μ
ꡬ쑰"},
|
120 |
+
{"title": "λ¬Έμ μ μ", "style": "Colorful Mind Map", "prompt_hint": "νμ¬ μμ₯μ λ¬Έμ μ "},
|
121 |
+
{"title": "νν© λΆμ", "style": "Elegant SWOT Quadrant", "prompt_hint": "κ°μ , μ½μ , κΈ°ν, μν"},
|
122 |
+
{"title": "μ루μ
", "style": "Industrial Design", "prompt_hint": "μ ν/μλΉμ€ 컨μ
"},
|
123 |
+
{"title": "νλ‘μΈμ€", "style": "Business Workflow", "prompt_hint": "μ€ν λ¨κ³"},
|
124 |
+
{"title": "μΌμ ", "style": "Timeline Ribbon", "prompt_hint": "μ£Όμ λ§μΌμ€ν€"},
|
125 |
+
{"title": "μ±κ³Ό μμΈ‘", "style": "KPI Dashboard", "prompt_hint": "μμ μ±κ³Ό μ§ν"},
|
126 |
+
{"title": "ν¬μ μμ²", "style": "Pyramid/Funnel", "prompt_hint": "ν¬μ κ·λͺ¨μ νμ©"}
|
127 |
+
]
|
128 |
+
},
|
129 |
+
"μ ν μκ°": {
|
130 |
+
"description": "μ μ ν λ°μΉ, μλΉμ€ μκ°μ©",
|
131 |
+
"slides": [
|
132 |
+
{"title": "μ ν 컨μ
", "style": "Industrial Design", "prompt_hint": "μ ν λμμΈ"},
|
133 |
+
{"title": "μ¬μ©μ λμ¦", "style": "Colorful Mind Map", "prompt_hint": "κ³ κ° νμΈν¬μΈνΈ"},
|
134 |
+
{"title": "κΈ°λ₯ μκ°", "style": "Mobile App Mockup", "prompt_hint": "UI/UX νλ©΄"},
|
135 |
+
{"title": "μλ μ리", "style": "Flowchart", "prompt_hint": "κΈ°λ₯ νλ‘μ°"},
|
136 |
+
{"title": "μμ₯ ν¬μ§μ
", "style": "3D Bubble Chart", "prompt_hint": "κ²½μμ¬ λΉκ΅"},
|
137 |
+
{"title": "μΆμ μΌμ ", "style": "Timeline Ribbon", "prompt_hint": "λ°μΉ λ‘λλ§΅"}
|
138 |
+
]
|
139 |
+
},
|
140 |
+
"νλ‘μ νΈ λ³΄κ³ ": {
|
141 |
+
"description": "μ§ν μν©, μ±κ³Ό λ³΄κ³ μ©",
|
142 |
+
"slides": [
|
143 |
+
{"title": "νλ‘μ νΈ κ°μ", "style": "Business Workflow", "prompt_hint": "μ 체 νλ‘μΈμ€"},
|
144 |
+
{"title": "μ§ν νν©", "style": "Gantt Chart", "prompt_hint": "μμ
μΌμ "},
|
145 |
+
{"title": "리μ€ν¬ κ΄λ¦¬", "style": "Risk Heat Map", "prompt_hint": "μν μμ"},
|
146 |
+
{"title": "μ±κ³Ό μ§ν", "style": "KPI Dashboard", "prompt_hint": "λ¬μ± μ€μ "},
|
147 |
+
{"title": "ν₯ν κ³ν", "style": "Timeline Ribbon", "prompt_hint": "λ€μ λ¨κ³"}
|
148 |
+
]
|
149 |
+
},
|
150 |
+
"μ λ΅ κΈ°ν": {
|
151 |
+
"description": "μ€μ₯κΈ° μ λ΅, λΉμ μ립μ©",
|
152 |
+
"slides": [
|
153 |
+
{"title": "λΉμ ", "style": "3D Style (Pixar-like)", "prompt_hint": "λ―Έλ λΉμ "},
|
154 |
+
{"title": "νκ²½ λΆμ", "style": "Elegant SWOT Quadrant", "prompt_hint": "λ΄μΈλΆ νκ²½"},
|
155 |
+
{"title": "μ λ΅ μ²΄κ³", "style": "Colorful Mind Map", "prompt_hint": "μ λ΅ κ΅¬μ‘°"},
|
156 |
+
{"title": "κ°μΉ μ¬μ¬", "style": "Value Chain", "prompt_hint": "λΉμ¦λμ€ λͺ¨λΈ"},
|
157 |
+
{"title": "μ€ν λ‘λλ§΅", "style": "Timeline Ribbon", "prompt_hint": "λ¨κ³λ³ κ³ν"},
|
158 |
+
{"title": "λͺ©ν μ§ν", "style": "KPI Dashboard", "prompt_hint": "KPI λͺ©ν"}
|
159 |
+
]
|
160 |
+
},
|
161 |
+
"μ¬μ©μ μ μ": {
|
162 |
+
"description": "μ§μ ꡬμ±νκΈ°",
|
163 |
+
"slides": []
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
def generate_slide_content(topic: str, slide_title: str, slide_context: str) -> Dict[str, str]:
|
168 |
+
"""κ° μ¬λΌμ΄λμ ν
μ€νΈ λ΄μ© μμ±"""
|
169 |
+
print(f"[μ¬λΌμ΄λ λ΄μ©] {slide_title} ν
μ€νΈ μμ± μ€...")
|
170 |
+
|
171 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
172 |
+
headers = {
|
173 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
174 |
+
"Content-Type": "application/json"
|
175 |
+
}
|
176 |
+
|
177 |
+
system_prompt = """You are a professional presentation content writer specializing in creating concise, impactful slide content.
|
178 |
+
|
179 |
+
Your task is to create:
|
180 |
+
1. A compelling subtitle (max 10 words)
|
181 |
+
2. Exactly 5 bullet points, each being a complete, concise sentence
|
182 |
+
3. Each bullet point should be 10-15 words
|
183 |
+
|
184 |
+
Guidelines:
|
185 |
+
- Be specific and actionable
|
186 |
+
- Use professional business language
|
187 |
+
- Include relevant data points or metrics when appropriate
|
188 |
+
- Ensure content aligns with the slide's purpose
|
189 |
+
- Make each point distinct and valuable
|
190 |
+
- Use active voice and strong verbs
|
191 |
+
|
192 |
+
Output format:
|
193 |
+
Subtitle: [subtitle here]
|
194 |
+
β’ [Point 1]
|
195 |
+
β’ [Point 2]
|
196 |
+
β’ [Point 3]
|
197 |
+
β’ [Point 4]
|
198 |
+
β’ [Point 5]"""
|
199 |
+
|
200 |
+
user_message = f"""Topic: {topic}
|
201 |
+
Slide Title: {slide_title}
|
202 |
+
Context: {slide_context}
|
203 |
+
|
204 |
+
Create compelling content for this presentation slide."""
|
205 |
+
|
206 |
+
payload = {
|
207 |
+
"model": "dep89a2fld32mcm",
|
208 |
+
"messages": [
|
209 |
+
{
|
210 |
+
"role": "system",
|
211 |
+
"content": system_prompt
|
212 |
+
},
|
213 |
+
{
|
214 |
+
"role": "user",
|
215 |
+
"content": user_message
|
216 |
+
}
|
217 |
+
],
|
218 |
+
"max_tokens": 300,
|
219 |
+
"top_p": 0.8,
|
220 |
+
"temperature": 0.7,
|
221 |
+
"stream": False
|
222 |
+
}
|
223 |
+
|
224 |
+
try:
|
225 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
226 |
+
if response.status_code == 200:
|
227 |
+
result = response.json()
|
228 |
+
content = result['choices'][0]['message']['content'].strip()
|
229 |
+
|
230 |
+
# Parse content
|
231 |
+
lines = content.split('\n')
|
232 |
+
subtitle = ""
|
233 |
+
bullet_points = []
|
234 |
+
|
235 |
+
for line in lines:
|
236 |
+
if line.startswith("Subtitle:"):
|
237 |
+
subtitle = line.replace("Subtitle:", "").strip()
|
238 |
+
elif line.strip().startswith("β’"):
|
239 |
+
bullet_points.append(line.strip())
|
240 |
+
|
241 |
+
# νκΈλ‘ λ²μμ΄ νμν κ²½μ°
|
242 |
+
if any(ord('κ°') <= ord(char) <= ord('ν£') for char in topic):
|
243 |
+
subtitle = translate_content_to_korean(subtitle)
|
244 |
+
bullet_points = [translate_content_to_korean(point) for point in bullet_points]
|
245 |
+
|
246 |
+
return {
|
247 |
+
"subtitle": subtitle,
|
248 |
+
"bullet_points": bullet_points[:5] # μ΅λ 5κ°
|
249 |
+
}
|
250 |
+
else:
|
251 |
+
return {
|
252 |
+
"subtitle": slide_title,
|
253 |
+
"bullet_points": ["λ΄μ©μ μμ±ν μ μμ΅λλ€."] * 5
|
254 |
+
}
|
255 |
+
except Exception as e:
|
256 |
+
print(f"[μ¬λΌμ΄λ λ΄μ©] μ€λ₯: {str(e)}")
|
257 |
+
return {
|
258 |
+
"subtitle": slide_title,
|
259 |
+
"bullet_points": ["λ΄μ©μ μμ±ν μ μμ΅λλ€."] * 5
|
260 |
+
}
|
261 |
+
|
262 |
+
def translate_content_to_korean(text: str) -> str:
|
263 |
+
"""μμ΄ ν
μ€νΈλ₯Ό νκΈλ‘ λ²μ"""
|
264 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
265 |
+
headers = {
|
266 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
267 |
+
"Content-Type": "application/json"
|
268 |
+
}
|
269 |
+
|
270 |
+
payload = {
|
271 |
+
"model": "dep89a2fld32mcm",
|
272 |
+
"messages": [
|
273 |
+
{
|
274 |
+
"role": "system",
|
275 |
+
"content": "You are a translator. Translate the given English text to Korean. Maintain professional business tone. Only return the translation without any explanation."
|
276 |
+
},
|
277 |
+
{
|
278 |
+
"role": "user",
|
279 |
+
"content": text
|
280 |
+
}
|
281 |
+
],
|
282 |
+
"max_tokens": 200,
|
283 |
+
"top_p": 0.8,
|
284 |
+
"stream": False
|
285 |
+
}
|
286 |
+
|
287 |
+
try:
|
288 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
289 |
+
if response.status_code == 200:
|
290 |
+
result = response.json()
|
291 |
+
return result['choices'][0]['message']['content'].strip()
|
292 |
+
else:
|
293 |
+
return text
|
294 |
+
except Exception as e:
|
295 |
+
return text
|
296 |
+
|
297 |
+
def generate_prompt_with_llm(topic: str, style_example: str = None, slide_context: str = None) -> str:
|
298 |
+
"""μ£Όμ μ μ€νμΌ μμ λ₯Ό λ°μμ LLMμ μ¬μ©ν΄ μ΄λ―Έμ§ ν둬ννΈλ₯Ό μμ±"""
|
299 |
+
print(f"[LLM] ν둬ννΈ μμ± μμ: {slide_context}")
|
300 |
+
|
301 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
302 |
+
headers = {
|
303 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
304 |
+
"Content-Type": "application/json"
|
305 |
+
}
|
306 |
+
|
307 |
+
system_prompt = """You are an expert image prompt engineer specializing in creating prompts for professional presentation slides.
|
308 |
+
|
309 |
+
Your task is to create prompts that:
|
310 |
+
1. Are highly specific and visual, perfect for PPT backgrounds or main visuals
|
311 |
+
2. Consider the slide's purpose and maintain consistency across a presentation
|
312 |
+
3. Include style references matching the given example
|
313 |
+
4. Focus on clean, professional visuals that won't distract from text overlays
|
314 |
+
5. Ensure high contrast areas for text readability when needed
|
315 |
+
6. Maintain brand consistency and professional aesthetics
|
316 |
+
|
317 |
+
Important guidelines:
|
318 |
+
- If given a style example, adapt the topic to match that specific visual style
|
319 |
+
- Consider the slide context (e.g., "νμ§", "νν© λΆμ") to create appropriate visuals
|
320 |
+
- Always output ONLY the prompt without any explanation
|
321 |
+
- Keep prompts between 50-150 words for optimal results
|
322 |
+
- Ensure the visual supports rather than overwhelms the slide content"""
|
323 |
+
|
324 |
+
user_message = f"Topic: {topic}"
|
325 |
+
if style_example:
|
326 |
+
user_message += f"\n\nStyle reference to follow:\n{style_example}"
|
327 |
+
if slide_context:
|
328 |
+
user_message += f"\n\nSlide context: {slide_context}"
|
329 |
+
|
330 |
+
payload = {
|
331 |
+
"model": "dep89a2fld32mcm",
|
332 |
+
"messages": [
|
333 |
+
{
|
334 |
+
"role": "system",
|
335 |
+
"content": system_prompt
|
336 |
+
},
|
337 |
+
{
|
338 |
+
"role": "user",
|
339 |
+
"content": user_message
|
340 |
+
}
|
341 |
+
],
|
342 |
+
"max_tokens": 300,
|
343 |
+
"top_p": 0.8,
|
344 |
+
"temperature": 0.7,
|
345 |
+
"stream": False
|
346 |
+
}
|
347 |
+
|
348 |
+
try:
|
349 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
350 |
+
if response.status_code == 200:
|
351 |
+
result = response.json()
|
352 |
+
prompt = result['choices'][0]['message']['content'].strip()
|
353 |
+
print(f"[LLM] ν둬ννΈ μμ± μλ£: {prompt[:50]}...")
|
354 |
+
return prompt
|
355 |
+
else:
|
356 |
+
error_msg = f"ν둬ννΈ μμ± μ€ν¨: {response.status_code}"
|
357 |
+
print(f"[LLM] {error_msg}")
|
358 |
+
return error_msg
|
359 |
+
except Exception as e:
|
360 |
+
error_msg = f"ν둬ννΈ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
361 |
+
print(f"[LLM] {error_msg}")
|
362 |
+
return error_msg
|
363 |
+
|
364 |
+
def translate_to_english(text: str) -> str:
|
365 |
+
"""νκΈ ν
μ€νΈλ₯Ό μμ΄λ‘ λ²μ (LLM μ¬μ©)"""
|
366 |
+
if not any(ord('κ°') <= ord(char) <= ord('ν£') for char in text):
|
367 |
+
return text
|
368 |
+
|
369 |
+
print(f"[λ²μ] νκΈ κ°μ§, μμ΄λ‘ λ²μ μμ")
|
370 |
+
|
371 |
+
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
372 |
+
headers = {
|
373 |
+
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
374 |
+
"Content-Type": "application/json"
|
375 |
+
}
|
376 |
+
|
377 |
+
payload = {
|
378 |
+
"model": "dep89a2fld32mcm",
|
379 |
+
"messages": [
|
380 |
+
{
|
381 |
+
"role": "system",
|
382 |
+
"content": "You are a translator. Translate the given Korean text to English. Only return the translation without any explanation."
|
383 |
+
},
|
384 |
+
{
|
385 |
+
"role": "user",
|
386 |
+
"content": text
|
387 |
+
}
|
388 |
+
],
|
389 |
+
"max_tokens": 500,
|
390 |
+
"top_p": 0.8,
|
391 |
+
"stream": False
|
392 |
+
}
|
393 |
+
|
394 |
+
try:
|
395 |
+
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
396 |
+
if response.status_code == 200:
|
397 |
+
result = response.json()
|
398 |
+
translated = result['choices'][0]['message']['content'].strip()
|
399 |
+
print(f"[λ²μ] μλ£")
|
400 |
+
return translated
|
401 |
+
else:
|
402 |
+
print(f"[λ²μ] μ€ν¨, μλ³Έ μ¬μ©")
|
403 |
+
return text
|
404 |
+
except Exception as e:
|
405 |
+
print(f"[λ²μ] μ€λ₯: {str(e)}, μλ³Έ μ¬μ©")
|
406 |
+
return text
|
407 |
+
|
408 |
+
def generate_image(prompt: str, seed: int = 10, slide_info: str = "") -> Tuple[Image.Image, str]:
|
409 |
+
"""Replicate APIλ₯Ό μ¬μ©ν΄ μ΄λ―Έμ§ μμ±"""
|
410 |
+
print(f"\n[μ΄λ―Έμ§ μμ±] {slide_info}")
|
411 |
+
print(f"[μ΄λ―Έμ§ μμ±] ν둬ννΈ: {prompt[:50]}...")
|
412 |
+
|
413 |
+
try:
|
414 |
+
english_prompt = translate_to_english(prompt)
|
415 |
+
|
416 |
+
if not REPLICATE_API_TOKEN:
|
417 |
+
error_msg = "RAPI_TOKEN νκ²½λ³μκ° μ€μ λμ§ μμμ΅λλ€."
|
418 |
+
print(f"[μ΄λ―Έμ§ μμ±] μ€λ₯: {error_msg}")
|
419 |
+
return None, error_msg
|
420 |
+
|
421 |
+
print(f"[μ΄λ―Έμ§ μμ±] Replicate API νΈμΆ μ€...")
|
422 |
+
client = replicate.Client(api_token=REPLICATE_API_TOKEN)
|
423 |
+
|
424 |
+
input_params = {
|
425 |
+
"seed": seed,
|
426 |
+
"prompt": english_prompt,
|
427 |
+
"speed_mode": "Extra Juiced π (even more speed)",
|
428 |
+
"output_quality": 100
|
429 |
+
}
|
430 |
+
|
431 |
+
start_time = time.time()
|
432 |
+
output = client.run(
|
433 |
+
"prunaai/hidream-l1-fast:17c237d753218fed0ed477cb553902b6b75735f48c128537ab829096ef3d3645",
|
434 |
+
input=input_params
|
435 |
+
)
|
436 |
+
|
437 |
+
elapsed = time.time() - start_time
|
438 |
+
print(f"[μ΄λ―Έμ§ μμ±] API μλ΅ λ°μ ({elapsed:.1f}μ΄)")
|
439 |
+
|
440 |
+
if output:
|
441 |
+
if isinstance(output, str) and output.startswith('http'):
|
442 |
+
print(f"[μ΄λ―Έμ§ μμ±] URLμμ μ΄λ―Έμ§ λ€μ΄λ‘λ μ€...")
|
443 |
+
response = requests.get(output, timeout=30)
|
444 |
+
img = Image.open(BytesIO(response.content))
|
445 |
+
print(f"[μ΄λ―Έμ§ μμ±] μλ£!")
|
446 |
+
return img, english_prompt
|
447 |
+
else:
|
448 |
+
print(f"[μ΄λ―Έμ§ μμ±] λ°μ΄λ리 λ°μ΄ν° μ²λ¦¬ μ€...")
|
449 |
+
img = Image.open(BytesIO(output.read()))
|
450 |
+
print(f"[μ΄λ―Έμ§ μμ±] μλ£!")
|
451 |
+
return img, english_prompt
|
452 |
+
else:
|
453 |
+
error_msg = "μ΄λ―Έμ§ μμ± μ€ν¨ - λΉ μλ΅"
|
454 |
+
print(f"[μ΄λ―Έμ§ μμ±] {error_msg}")
|
455 |
+
return None, error_msg
|
456 |
+
|
457 |
+
except Exception as e:
|
458 |
+
error_msg = f"μ€λ₯: {str(e)}"
|
459 |
+
print(f"[μ΄λ―Έμ§ μμ±] {error_msg}")
|
460 |
+
print(f"[μ΄λ―Έμ§ μμ±] μμΈ μ€λ₯:\n{traceback.format_exc()}")
|
461 |
+
return None, error_msg
|
462 |
+
|
463 |
+
def create_slide_preview_html(slide_data: Dict) -> str:
|
464 |
+
"""16:9 λΉμ¨μ μ¬λΌμ΄λ ν리뷰 HTML μμ±"""
|
465 |
+
|
466 |
+
# μ΄λ―Έμ§λ₯Ό base64λ‘ μΈμ½λ©
|
467 |
+
img_base64 = ""
|
468 |
+
if slide_data.get("image"):
|
469 |
+
buffered = BytesIO()
|
470 |
+
slide_data["image"].save(buffered, format="PNG")
|
471 |
+
img_base64 = base64.b64encode(buffered.getvalue()).decode()
|
472 |
+
|
473 |
+
# ν
μ€νΈ λ΄μ© κ°μ Έμ€κΈ°
|
474 |
+
subtitle = slide_data.get("subtitle", "")
|
475 |
+
bullet_points = slide_data.get("bullet_points", [])
|
476 |
+
|
477 |
+
# HTML μμ±
|
478 |
+
html = f"""
|
479 |
+
<div class="slide-container" style="
|
480 |
+
width: 100%;
|
481 |
+
max-width: 1200px;
|
482 |
+
margin: 20px auto;
|
483 |
+
background: white;
|
484 |
+
border-radius: 8px;
|
485 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
486 |
+
overflow: hidden;
|
487 |
+
">
|
488 |
+
<div class="slide-header" style="
|
489 |
+
background: #2c3e50;
|
490 |
+
color: white;
|
491 |
+
padding: 15px 30px;
|
492 |
+
font-size: 18px;
|
493 |
+
font-weight: bold;
|
494 |
+
">
|
495 |
+
μ¬λΌμ΄λ {slide_data.get('slide_number', '')}: {slide_data.get('title', '')}
|
496 |
+
</div>
|
497 |
+
|
498 |
+
<div class="slide-content" style="
|
499 |
+
display: flex;
|
500 |
+
height: 0;
|
501 |
+
padding-bottom: 56.25%; /* 16:9 λΉμ¨ */
|
502 |
+
position: relative;
|
503 |
+
">
|
504 |
+
<div class="slide-inner" style="
|
505 |
+
position: absolute;
|
506 |
+
top: 0;
|
507 |
+
left: 0;
|
508 |
+
width: 100%;
|
509 |
+
height: 100%;
|
510 |
+
display: flex;
|
511 |
+
">
|
512 |
+
<!-- ν
μ€νΈ μμ (μ’μΈ‘) -->
|
513 |
+
<div class="text-area" style="
|
514 |
+
flex: 1;
|
515 |
+
padding: 40px;
|
516 |
+
display: flex;
|
517 |
+
flex-direction: column;
|
518 |
+
justify-content: center;
|
519 |
+
background: #f8f9fa;
|
520 |
+
">
|
521 |
+
<h2 style="
|
522 |
+
color: #2c3e50;
|
523 |
+
font-size: 28px;
|
524 |
+
margin-bottom: 30px;
|
525 |
+
font-weight: 600;
|
526 |
+
">{subtitle}</h2>
|
527 |
+
|
528 |
+
<ul style="
|
529 |
+
list-style: none;
|
530 |
+
padding: 0;
|
531 |
+
margin: 0;
|
532 |
+
">
|
533 |
+
"""
|
534 |
+
|
535 |
+
for point in bullet_points:
|
536 |
+
html += f"""
|
537 |
+
<li style="
|
538 |
+
margin-bottom: 15px;
|
539 |
+
padding-left: 25px;
|
540 |
+
position: relative;
|
541 |
+
color: #34495e;
|
542 |
+
font-size: 16px;
|
543 |
+
line-height: 1.6;
|
544 |
+
">
|
545 |
+
<span style="
|
546 |
+
position: absolute;
|
547 |
+
left: 0;
|
548 |
+
color: #3498db;
|
549 |
+
">βΆ</span>
|
550 |
+
{point.replace('β’', '').strip()}
|
551 |
+
</li>
|
552 |
+
"""
|
553 |
+
|
554 |
+
html += f"""
|
555 |
+
</ul>
|
556 |
+
</div>
|
557 |
+
|
558 |
+
<!-- μ΄λ―Έμ§ μμ (μ°μΈ‘) -->
|
559 |
+
<div class="image-area" style="
|
560 |
+
flex: 1;
|
561 |
+
background: #e9ecef;
|
562 |
+
display: flex;
|
563 |
+
align-items: center;
|
564 |
+
justify-content: center;
|
565 |
+
padding: 20px;
|
566 |
+
">
|
567 |
+
"""
|
568 |
+
|
569 |
+
if img_base64:
|
570 |
+
html += f"""
|
571 |
+
<img src="data:image/png;base64,{img_base64}" style="
|
572 |
+
max-width: 100%;
|
573 |
+
max-height: 100%;
|
574 |
+
object-fit: contain;
|
575 |
+
border-radius: 4px;
|
576 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
577 |
+
" alt="Slide Image">
|
578 |
+
"""
|
579 |
+
else:
|
580 |
+
html += """
|
581 |
+
<div style="
|
582 |
+
color: #6c757d;
|
583 |
+
text-align: center;
|
584 |
+
">
|
585 |
+
<div style="font-size: 48px;">πΌοΈ</div>
|
586 |
+
<p>μ΄λ―Έμ§ μμ± μ€...</p>
|
587 |
+
</div>
|
588 |
+
"""
|
589 |
+
|
590 |
+
html += """
|
591 |
+
</div>
|
592 |
+
</div>
|
593 |
+
</div>
|
594 |
+
</div>
|
595 |
+
"""
|
596 |
+
|
597 |
+
return html
|
598 |
+
|
599 |
+
def create_pptx_file(results: List[Dict], topic: str, template_name: str) -> str:
|
600 |
+
"""μμ±λ κ²°κ³Όλ₯Ό PPTX νμΌλ‘ λ³ν"""
|
601 |
+
print("[PPTX] νμΌ μμ± μμ...")
|
602 |
+
|
603 |
+
# νλ μ ν
μ΄μ
μμ± (16:9 λΉμ¨)
|
604 |
+
prs = Presentation()
|
605 |
+
prs.slide_width = Inches(16)
|
606 |
+
prs.slide_height = Inches(9)
|
607 |
+
|
608 |
+
# νμ΄ν μ¬λΌμ΄λ λ μ΄μμ
|
609 |
+
title_layout = prs.slide_layouts[0]
|
610 |
+
|
611 |
+
# νμ§ μ¬λΌμ΄λ μΆκ°
|
612 |
+
slide = prs.slides.add_slide(title_layout)
|
613 |
+
title = slide.shapes.title
|
614 |
+
subtitle = slide.placeholders[1]
|
615 |
+
|
616 |
+
title.text = topic
|
617 |
+
subtitle.text = f"{template_name} - AIλ‘ μμ±λ νλ μ ν
μ΄μ
"
|
618 |
+
|
619 |
+
# κ° κ²°κ³Ό μ¬λΌμ΄λ μΆκ°
|
620 |
+
for i, result in enumerate(results):
|
621 |
+
if not result.get("success", False):
|
622 |
+
continue
|
623 |
+
|
624 |
+
slide_data = result.get("slide_data", {})
|
625 |
+
|
626 |
+
# λΉ λ μ΄μμ μ¬μ©
|
627 |
+
blank_layout = prs.slide_layouts[5]
|
628 |
+
slide = prs.slides.add_slide(blank_layout)
|
629 |
+
|
630 |
+
# μ¬λΌμ΄λ μ λͺ© μΆκ° (μλ¨)
|
631 |
+
title_box = slide.shapes.add_textbox(
|
632 |
+
Inches(0.5), Inches(0.3),
|
633 |
+
Inches(15), Inches(0.8)
|
634 |
+
)
|
635 |
+
title_frame = title_box.text_frame
|
636 |
+
title_frame.text = f"{slide_data.get('title', '')}"
|
637 |
+
title_para = title_frame.paragraphs[0]
|
638 |
+
title_para.font.size = Pt(28)
|
639 |
+
title_para.font.bold = True
|
640 |
+
title_para.font.color.rgb = RGBColor(44, 62, 80) # μ§ν νλμ
|
641 |
+
|
642 |
+
# μ’μΈ‘ ν
μ€νΈ μμ
|
643 |
+
text_box = slide.shapes.add_textbox(
|
644 |
+
Inches(0.5), Inches(1.5),
|
645 |
+
Inches(7.5), Inches(6.5)
|
646 |
+
)
|
647 |
+
text_frame = text_box.text_frame
|
648 |
+
text_frame.word_wrap = True
|
649 |
+
|
650 |
+
# μμ λͺ© μΆκ°
|
651 |
+
subtitle_para = text_frame.paragraphs[0]
|
652 |
+
subtitle_para.text = slide_data.get('subtitle', '')
|
653 |
+
subtitle_para.font.size = Pt(20)
|
654 |
+
subtitle_para.font.bold = True
|
655 |
+
subtitle_para.font.color.rgb = RGBColor(52, 73, 94)
|
656 |
+
subtitle_para.space_after = Pt(20)
|
657 |
+
|
658 |
+
# λΆλ¦Ώ ν¬μΈνΈ μΆκ°
|
659 |
+
bullet_points = slide_data.get('bullet_points', [])
|
660 |
+
for point in bullet_points:
|
661 |
+
p = text_frame.add_paragraph()
|
662 |
+
p.text = point.replace('β’', '').strip()
|
663 |
+
p.font.size = Pt(16)
|
664 |
+
p.font.color.rgb = RGBColor(52, 73, 94)
|
665 |
+
p.level = 0
|
666 |
+
p.space_after = Pt(12)
|
667 |
+
p.line_spacing = 1.5
|
668 |
+
|
669 |
+
# μ°μΈ‘ μ΄λ―Έμ§ μΆκ°
|
670 |
+
if slide_data.get('image'):
|
671 |
+
try:
|
672 |
+
# PIL μ΄λ―Έμ§λ₯Ό BytesIOλ‘ λ³ν
|
673 |
+
img_buffer = BytesIO()
|
674 |
+
slide_data['image'].save(img_buffer, format='PNG')
|
675 |
+
img_buffer.seek(0)
|
676 |
+
|
677 |
+
# μ΄λ―Έμ§ μΆκ° (μ°μΈ‘)
|
678 |
+
pic = slide.shapes.add_picture(
|
679 |
+
img_buffer,
|
680 |
+
Inches(8.5), Inches(1.5),
|
681 |
+
width=Inches(7), height=Inches(6)
|
682 |
+
)
|
683 |
+
|
684 |
+
# μ΄λ―Έμ§ ν
λ리 μ€νμΌ
|
685 |
+
pic.line.color.rgb = RGBColor(189, 195, 199)
|
686 |
+
pic.line.width = Pt(1)
|
687 |
+
|
688 |
+
except Exception as e:
|
689 |
+
print(f"[PPTX] μ΄λ―Έμ§ μΆκ° μ€ν¨: {str(e)}")
|
690 |
+
|
691 |
+
# νμ΄μ§ λ²νΈ μΆκ°
|
692 |
+
page_num = slide.shapes.add_textbox(
|
693 |
+
Inches(15), Inches(8.5),
|
694 |
+
Inches(1), Inches(0.5)
|
695 |
+
)
|
696 |
+
page_frame = page_num.text_frame
|
697 |
+
page_frame.text = str(i + 2) # νμ§κ° 1νμ΄μ§
|
698 |
+
page_para = page_frame.paragraphs[0]
|
699 |
+
page_para.font.size = Pt(12)
|
700 |
+
page_para.font.color.rgb = RGBColor(127, 140, 141)
|
701 |
+
page_para.alignment = PP_ALIGN.RIGHT
|
702 |
+
|
703 |
+
# νμΌ μ μ₯
|
704 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
705 |
+
filename = f"presentation_{timestamp}.pptx"
|
706 |
+
filepath = os.path.join("/tmp", filename)
|
707 |
+
prs.save(filepath)
|
708 |
+
|
709 |
+
print(f"[PPTX] νμΌ μμ± μλ£: {filename}")
|
710 |
+
return filepath
|
711 |
+
|
712 |
+
def generate_ppt_with_content(topic: str, template_name: str, custom_slides: List[Dict], seed: int, progress=gr.Progress()):
|
713 |
+
"""PPT μ΄λ―Έμ§μ ν
μ€νΈ λ΄μ©μ ν¨κ» μμ±"""
|
714 |
+
results = []
|
715 |
+
preview_html = ""
|
716 |
+
|
717 |
+
# ν
νλ¦Ώ μ ν
|
718 |
+
if template_name == "μ¬μ©μ μ μ" and custom_slides:
|
719 |
+
slides = custom_slides
|
720 |
+
else:
|
721 |
+
slides = PPT_TEMPLATES[template_name]["slides"]
|
722 |
+
|
723 |
+
if not slides:
|
724 |
+
yield "", "μ¬λΌμ΄λκ° μ μλμ§ μμμ΅λλ€.", None
|
725 |
+
return
|
726 |
+
|
727 |
+
total_slides = len(slides)
|
728 |
+
print(f"\n[PPT μμ±] μμ - μ΄ {total_slides}κ° μ¬λΌμ΄λ")
|
729 |
+
print(f"[PPT μμ±] μ£Όμ : {topic}")
|
730 |
+
print(f"[PPT μμ±] ν
νλ¦Ώ: {template_name}")
|
731 |
+
|
732 |
+
# CSS μ€νμΌ οΏ½οΏ½οΏ½κ°
|
733 |
+
preview_html = """
|
734 |
+
<style>
|
735 |
+
.slides-container {
|
736 |
+
width: 100%;
|
737 |
+
max-width: 1400px;
|
738 |
+
margin: 0 auto;
|
739 |
+
}
|
740 |
+
</style>
|
741 |
+
<div class="slides-container">
|
742 |
+
"""
|
743 |
+
|
744 |
+
# κ° μ¬λΌμ΄λ μμ°¨ μ²λ¦¬
|
745 |
+
for i, slide in enumerate(slides):
|
746 |
+
progress((i + 1) / (total_slides + 1), f"μ¬λΌμ΄λ {i+1}/{total_slides} μ²λ¦¬ μ€...")
|
747 |
+
|
748 |
+
slide_info = f"μ¬λΌμ΄λ {i+1}: {slide['title']}"
|
749 |
+
|
750 |
+
# ν
μ€νΈ λ΄μ© μμ±
|
751 |
+
slide_context = f"{slide['title']} - {slide.get('prompt_hint', '')}"
|
752 |
+
content = generate_slide_content(topic, slide['title'], slide_context)
|
753 |
+
|
754 |
+
# ν둬ννΈ μμ± λ° μ΄λ―Έμ§ μμ±
|
755 |
+
style_key = slide["style"]
|
756 |
+
if style_key in STYLE_TEMPLATES:
|
757 |
+
style_info = STYLE_TEMPLATES[style_key]
|
758 |
+
prompt = generate_prompt_with_llm(topic, style_info["example"], slide_context)
|
759 |
+
|
760 |
+
# μ΄λ―Έμ§ μμ±
|
761 |
+
slide_seed = seed + i
|
762 |
+
img, used_prompt = generate_image(prompt, slide_seed, slide_info)
|
763 |
+
|
764 |
+
# μ¬λΌμ΄λ λ°μ΄ν° ꡬμ±
|
765 |
+
slide_data = {
|
766 |
+
"slide_number": i + 1,
|
767 |
+
"title": slide["title"],
|
768 |
+
"subtitle": content["subtitle"],
|
769 |
+
"bullet_points": content["bullet_points"],
|
770 |
+
"image": img,
|
771 |
+
"style": style_info["name"]
|
772 |
+
}
|
773 |
+
|
774 |
+
# ν리뷰 HTML μμ±
|
775 |
+
preview_html += create_slide_preview_html(slide_data)
|
776 |
+
|
777 |
+
# νμ¬κΉμ§μ μν μ
λ°μ΄νΈ
|
778 |
+
yield preview_html + "</div>", f"### π {slide_info} μμ± μ€...", None
|
779 |
+
|
780 |
+
results.append({
|
781 |
+
"slide_data": slide_data,
|
782 |
+
"success": img is not None
|
783 |
+
})
|
784 |
+
|
785 |
+
# PPTX νμΌ μμ±
|
786 |
+
progress(0.95, "PPTX νμΌ μμ± μ€...")
|
787 |
+
pptx_path = None
|
788 |
+
try:
|
789 |
+
pptx_path = create_pptx_file(results, topic, template_name)
|
790 |
+
except Exception as e:
|
791 |
+
print(f"[PPTX] νμΌ μμ± μ€λ₯: {str(e)}")
|
792 |
+
|
793 |
+
# μ΅μ’
κ²°κ³Ό
|
794 |
+
preview_html += "</div>"
|
795 |
+
progress(1.0, "μλ£!")
|
796 |
+
successful = sum(1 for r in results if r["success"])
|
797 |
+
final_status = f"### π μμ± μλ£! μ΄ {total_slides}κ° μ¬λΌμ΄λ μ€ {successful}κ° μ±κ³΅"
|
798 |
+
|
799 |
+
if pptx_path:
|
800 |
+
final_status += f"\n\n### π₯ PPTX νμΌμ΄ μ€λΉλμμ΅λλ€! μλμμ λ€μ΄λ‘λνμΈμ."
|
801 |
+
|
802 |
+
yield preview_html, final_status, pptx_path
|
803 |
+
|
804 |
+
def create_custom_slides_ui():
|
805 |
+
"""μ¬μ©μ μ μ μ¬λΌμ΄λ κ΅¬μ± UI"""
|
806 |
+
slides = []
|
807 |
+
for i in range(10):
|
808 |
+
with gr.Row():
|
809 |
+
with gr.Column(scale=2):
|
810 |
+
title = gr.Textbox(
|
811 |
+
label=f"μ¬λΌμ΄λ {i+1} μ λͺ©",
|
812 |
+
placeholder="μ: νμ§, λͺ©μ°¨, νν© λΆμ...",
|
813 |
+
visible=(i < 3)
|
814 |
+
)
|
815 |
+
with gr.Column(scale=3):
|
816 |
+
style = gr.Dropdown(
|
817 |
+
choices=list(STYLE_TEMPLATES.keys()),
|
818 |
+
label=f"μ€νμΌ μ ν",
|
819 |
+
visible=(i < 3)
|
820 |
+
)
|
821 |
+
with gr.Column(scale=3):
|
822 |
+
hint = gr.Textbox(
|
823 |
+
label=f"ν둬ννΈ ννΈ",
|
824 |
+
placeholder="μ΄ μ¬λΌμ΄λμμ νννκ³ μΆμ λ΄μ©",
|
825 |
+
visible=(i < 3)
|
826 |
+
)
|
827 |
+
slides.append({"title": title, "style": style, "hint": hint})
|
828 |
+
return slides
|
829 |
+
|
830 |
+
# Gradio μΈν°νμ΄μ€ μμ±
|
831 |
+
with gr.Blocks(title="PPT μ΄λ―Έμ§ μμ±κΈ°", theme=gr.themes.Soft(), css="""
|
832 |
+
.preview-container { max-width: 1400px; margin: 0 auto; }
|
833 |
+
""") as demo:
|
834 |
+
gr.Markdown("""
|
835 |
+
# π― AI κΈ°λ° PPT ν΅ν© μμ±κΈ°
|
836 |
+
|
837 |
+
### ν
μ€νΈμ μ΄λ―Έμ§κ° μλ²½νκ² μ‘°νλ νλ μ ν
μ΄μ
μ μλμΌλ‘ μμ±νκ³ λ€μ΄λ‘λνμΈμ!
|
838 |
+
""")
|
839 |
+
|
840 |
+
# API ν ν° μν νμΈ
|
841 |
+
if not REPLICATE_API_TOKEN:
|
842 |
+
gr.Markdown("β οΈ **κ²½κ³ **: RAPI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
843 |
+
if not FRIENDLI_TOKEN:
|
844 |
+
gr.Markdown("β οΈ **κ²½κ³ **: FRIENDLI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
845 |
+
|
846 |
+
with gr.Row():
|
847 |
+
with gr.Column(scale=1):
|
848 |
+
# κΈ°λ³Έ μ
λ ₯
|
849 |
+
topic_input = gr.Textbox(
|
850 |
+
label="νλ μ ν
μ΄μ
μ£Όμ ",
|
851 |
+
placeholder="μ: AI μ€ννΈμ
ν¬μ μ μΉ, μ μ ν λ°μΉ, λμ§νΈ μ ν μ λ΅",
|
852 |
+
lines=2
|
853 |
+
)
|
854 |
+
|
855 |
+
# PPT ν
νλ¦Ώ μ ν
|
856 |
+
template_select = gr.Dropdown(
|
857 |
+
choices=list(PPT_TEMPLATES.keys()),
|
858 |
+
label="PPT ν
νλ¦Ώ μ ν",
|
859 |
+
value="λΉμ¦λμ€ μ μμ",
|
860 |
+
info="λͺ©μ μ λ§λ ν
νλ¦Ώμ μ ννμΈμ"
|
861 |
+
)
|
862 |
+
|
863 |
+
# ν
νλ¦Ώ μ€λͺ
|
864 |
+
template_info = gr.Markdown()
|
865 |
+
|
866 |
+
# μλ κ°
|
867 |
+
seed_input = gr.Slider(
|
868 |
+
minimum=1,
|
869 |
+
maximum=100,
|
870 |
+
value=10,
|
871 |
+
step=1,
|
872 |
+
label="μλ κ°"
|
873 |
+
)
|
874 |
+
|
875 |
+
generate_btn = gr.Button("π PPT μ 체 μμ± (ν
μ€νΈ + μ΄λ―Έμ§)", variant="primary", size="lg")
|
876 |
+
|
877 |
+
# PPTX λ€μ΄λ‘λ μμ
|
878 |
+
with gr.Row():
|
879 |
+
download_file = gr.File(
|
880 |
+
label="π₯ μμ±λ PPTX νμΌ λ€μ΄λ‘λ",
|
881 |
+
visible=True,
|
882 |
+
elem_id="download-file"
|
883 |
+
)
|
884 |
+
|
885 |
+
# μ¬μ©μ μ μ μΉμ
|
886 |
+
with gr.Accordion("π μ¬μ©μ μ μ μ¬λΌμ΄λ ꡬμ±", open=False) as custom_accordion:
|
887 |
+
gr.Markdown("ν
νλ¦Ώμ μ¬μ©νμ§ μκ³ μ§μ μ¬λΌμ΄λλ₯Ό ꡬμ±νμΈμ.")
|
888 |
+
custom_slides_components = create_custom_slides_ui()
|
889 |
+
|
890 |
+
# μν νμ
|
891 |
+
status_output = gr.Markdown(
|
892 |
+
value="### π ν
νλ¦Ώμ μ ννκ³ μμ± λ²νΌμ ν΄λ¦νμΈμ!"
|
893 |
+
)
|
894 |
+
|
895 |
+
# ν리뷰 μμ
|
896 |
+
preview_output = gr.HTML(
|
897 |
+
label="PPT ν리뷰 (16:9)",
|
898 |
+
elem_classes="preview-container"
|
899 |
+
)
|
900 |
+
|
901 |
+
# νμ© ν
|
902 |
+
gr.Markdown("""
|
903 |
+
---
|
904 |
+
### π‘ μλ‘μ΄ κΈ°λ₯:
|
905 |
+
|
906 |
+
1. **μλ ν
μ€νΈ μμ±**: κ° μ¬λΌμ΄λλ§λ€ μ μ ν μ λͺ©κ³Ό 5κ°μ ν΅μ¬ ν¬μΈνΈ μλ μμ±
|
907 |
+
2. **16:9 ν리뷰**: μ€μ PPTμ λμΌν λΉμ¨λ‘ 미리보기
|
908 |
+
3. **PPTX λ€μ΄λ‘λ**: μμ±λ λ΄μ©μ μ€μ PowerPoint νμΌλ‘ λ€μ΄λ‘λ
|
909 |
+
4. **μ’μ° λ μ΄μμ**: μ’μΈ‘ ν
μ€νΈ, μ°μΈ‘ μ΄λ―Έμ§λ‘ κΉλν ꡬμ±
|
910 |
+
|
911 |
+
### π νμν μΆκ° ν¨ν€μ§:
|
912 |
+
```bash
|
913 |
+
pip install python-pptx
|
914 |
+
```
|
915 |
+
|
916 |
+
### π νμ© ν:
|
917 |
+
- λ€μ΄λ‘λν PPTX νμΌμ PowerPointμμ λ°λ‘ νΈμ§ κ°λ₯
|
918 |
+
- ν°νΈ, μμ, λ μ΄μμμ μΆκ°λ‘ 컀μ€ν°λ§μ΄μ§ κ°λ₯
|
919 |
+
- μμ±λ μ΄λ―Έμ§λ κ³ ν΄μλλ‘ PPTμ ν¬ν¨λ¨
|
920 |
+
""")
|
921 |
+
|
922 |
+
# μ΄λ²€νΈ νΈλ€λ¬
|
923 |
+
def update_template_info(template_name):
|
924 |
+
if template_name in PPT_TEMPLATES:
|
925 |
+
template = PPT_TEMPLATES[template_name]
|
926 |
+
info = f"**{template['description']}**\n\nν¬ν¨λ μ¬λΌμ΄λ:\n"
|
927 |
+
for i, slide in enumerate(template['slides']):
|
928 |
+
info += f"{i+1}. {slide['title']} - {STYLE_TEMPLATES[slide['style']]['use_case']}\n"
|
929 |
+
return info
|
930 |
+
return ""
|
931 |
+
|
932 |
+
def generate_ppt_handler(topic, template_name, seed, progress=gr.Progress(), *custom_inputs):
|
933 |
+
if not topic.strip():
|
934 |
+
yield "", "β μ£Όμ λ₯Ό μ
λ ₯ν΄μ£ΌμΈμ.", None
|
935 |
+
return
|
936 |
+
|
937 |
+
# μ¬μ©μ μ μ μ¬λΌμ΄λ μ²λ¦¬
|
938 |
+
custom_slides = []
|
939 |
+
if template_name == "μ¬μ©μ μ μ":
|
940 |
+
for i in range(0, len(custom_inputs), 3):
|
941 |
+
title = custom_inputs[i]
|
942 |
+
style = custom_inputs[i+1] if i+1 < len(custom_inputs) else None
|
943 |
+
hint = custom_inputs[i+2] if i+2 < len(custom_inputs) else ""
|
944 |
+
|
945 |
+
if title and style:
|
946 |
+
custom_slides.append({
|
947 |
+
"title": title,
|
948 |
+
"style": style,
|
949 |
+
"prompt_hint": hint
|
950 |
+
})
|
951 |
+
|
952 |
+
# PPT μμ±
|
953 |
+
for preview, status, pptx_file in generate_ppt_with_content(topic, template_name, custom_slides, seed, progress):
|
954 |
+
yield preview, status, pptx_file
|
955 |
+
|
956 |
+
# μ΄λ²€νΈ μ°κ²°
|
957 |
+
template_select.change(
|
958 |
+
fn=update_template_info,
|
959 |
+
inputs=[template_select],
|
960 |
+
outputs=[template_info]
|
961 |
+
)
|
962 |
+
|
963 |
+
# μ¬μ©μ μ μ μ
λ ₯ μμ§
|
964 |
+
all_custom_inputs = []
|
965 |
+
for slide_components in custom_slides_components:
|
966 |
+
all_custom_inputs.extend([
|
967 |
+
slide_components["title"],
|
968 |
+
slide_components["style"],
|
969 |
+
slide_components["hint"]
|
970 |
+
])
|
971 |
+
|
972 |
+
generate_btn.click(
|
973 |
+
fn=generate_ppt_handler,
|
974 |
+
inputs=[topic_input, template_select, seed_input] + all_custom_inputs,
|
975 |
+
outputs=[preview_output, status_output, download_file]
|
976 |
+
)
|
977 |
+
|
978 |
+
# μ΄κΈ° ν
νλ¦Ώ μ 보 νμ
|
979 |
+
demo.load(
|
980 |
+
fn=update_template_info,
|
981 |
+
inputs=[template_select],
|
982 |
+
outputs=[template_info]
|
983 |
+
)
|
984 |
+
|
985 |
+
# μ± μ€ν
|
986 |
+
if __name__ == "__main__":
|
987 |
+
print("\n" + "="*50)
|
988 |
+
print("π PPT ν΅ν© μμ±κΈ° μμ!")
|
989 |
+
print("="*50)
|
990 |
+
|
991 |
+
# νκ²½ λ³μ νμΈ
|
992 |
+
if not REPLICATE_API_TOKEN:
|
993 |
+
print("β οΈ κ²½κ³ : RAPI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
994 |
+
else:
|
995 |
+
print("β
RAPI_TOKEN νμΈλ¨")
|
996 |
+
|
997 |
+
if not FRIENDLI_TOKEN:
|
998 |
+
print("β οΈ κ²½κ³ : FRIENDLI_TOKEN νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
999 |
+
else:
|
1000 |
+
print("β
FRIENDLI_TOKEN νμΈλ¨")
|
1001 |
+
|
1002 |
+
print("="*50 + "\n")
|
1003 |
+
|
1004 |
+
demo.launch()
|