Update app.py
Browse files
app.py
CHANGED
@@ -1,2266 +1,35 @@
|
|
1 |
-
import replicate
|
2 |
-
import requests
|
3 |
import os
|
4 |
-
import
|
5 |
-
|
6 |
-
from
|
7 |
-
from typing import List, Tuple, Dict
|
8 |
-
from datetime import datetime
|
9 |
-
import time
|
10 |
-
import traceback
|
11 |
-
import base64
|
12 |
-
from pptx import Presentation
|
13 |
-
from pptx.util import Inches, Pt
|
14 |
-
from pptx.dml.color import RGBColor
|
15 |
-
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
|
16 |
-
from pptx.enum.shapes import MSO_SHAPE
|
17 |
-
import PyPDF2
|
18 |
-
import pandas as pd
|
19 |
-
import chardet
|
20 |
-
import gradio as gr
|
21 |
|
22 |
-
|
23 |
-
try:
|
24 |
-
from process_flow_generator import generate_process_flow_for_ppt
|
25 |
-
PROCESS_FLOW_AVAILABLE = True
|
26 |
-
except ImportError:
|
27 |
-
PROCESS_FLOW_AVAILABLE = False
|
28 |
-
print("[๊ฒฝ๊ณ ] process_flow_generator๋ฅผ ์ํฌํธํ ์ ์์ต๋๋ค. ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ๊ธฐ๋ฅ์ด ๋นํ์ฑํ๋ฉ๋๋ค.")
|
29 |
-
|
30 |
-
# ์์ ํ
ํ๋ฆฟ ์ ์
|
31 |
-
EXAMPLE_TOPICS = {
|
32 |
-
"๋น์ฆ๋์ค ์ ์์": "AI ๊ธฐ๋ฐ ๊ณ ๊ฐ ์๋น์ค ์๋ํ ํ๋ซํผ ํฌ์ ์ ์",
|
33 |
-
"์ ํ ์๊ฐ": "์ค๋งํธ ํ IoT ๋ณด์ ์์คํ
์ ์ ํ ๋ฐ์นญ",
|
34 |
-
"ํ๋ก์ ํธ ๋ณด๊ณ ": "๋์งํธ ์ ํ ํ๋ก์ ํธ 3๋ถ๊ธฐ ์ฑ๊ณผ ๋ณด๊ณ ",
|
35 |
-
"์ ๋ต ๊ธฐํ": "2025๋
๊ธ๋ก๋ฒ ์์ฅ ์ง์ถ ์ ๋ต ์๋ฆฝ"
|
36 |
-
}
|
37 |
-
|
38 |
-
# ์ค๋์ธ์ค ํ์
์ ์
|
39 |
-
AUDIENCE_TYPES = {
|
40 |
-
"๊ฒฝ์์ง/์์": {
|
41 |
-
"description": "C-level, ์์ฌ๊ฒฐ์ ๊ถ์",
|
42 |
-
"tone": "์ ๋ต์ , ๊ฒฐ๊ณผ ์ค์ฌ, ROI ๊ฐ์กฐ",
|
43 |
-
"focus": "๋น์ฆ๋์ค ๊ฐ์น, ํฌ์ ์์ต๋ฅ , ์ ๋ต์ ์ํฅ"
|
44 |
-
},
|
45 |
-
"ํฌ์์": {
|
46 |
-
"description": "VC, ์์ คํฌ์์, ๊ธฐ๊ดํฌ์์",
|
47 |
-
"tone": "์์น ๊ธฐ๋ฐ, ์ฑ์ฅ ๊ฐ๋ฅ์ฑ, ์์ฅ ๊ธฐํ",
|
48 |
-
"focus": "์์ฅ ๊ท๋ชจ, ์ฑ์ฅ๋ฅ , ๊ฒฝ์์ฐ์, Exit ์ ๋ต"
|
49 |
-
},
|
50 |
-
"๊ธฐ์ ํ": {
|
51 |
-
"description": "๊ฐ๋ฐ์, ์์ง๋์ด, IT ์ ๋ฌธ๊ฐ",
|
52 |
-
"tone": "๊ธฐ์ ์ , ๊ตฌ์ฒด์ , ์ค์ฉ์ ",
|
53 |
-
"focus": "๊ธฐ์ ์คํ, ์ํคํ
์ฒ, ๊ตฌํ ๋ฐฉ๋ฒ, ์ฑ๋ฅ"
|
54 |
-
},
|
55 |
-
"์ผ๋ฐ ์ง์": {
|
56 |
-
"description": "์ค๋ฌด์, ํ์",
|
57 |
-
"tone": "์น๊ทผํ, ์ค๋ฌด์ , ํ์
์ค์ฌ",
|
58 |
-
"focus": "์คํ ๊ณํ, ์ญํ , ํ๋ก์ธ์ค, ํ์
๋ฐฉ์"
|
59 |
-
},
|
60 |
-
"๊ณ ๊ฐ/ํํธ๋": {
|
61 |
-
"description": "B2B ๊ณ ๊ฐ, ๋น์ฆ๋์ค ํํธ๋",
|
62 |
-
"tone": "์ ๋ขฐ๊ฐ, ์ ๋ฌธ์ , ํํ ์ค์ฌ",
|
63 |
-
"focus": "๊ณ ๊ฐ ๊ฐ์น, ํํ, ์ฌ๋ก, ์ง์ ์ฒด๊ณ"
|
64 |
-
},
|
65 |
-
"์ผ๋ฐ ๋์ค": {
|
66 |
-
"description": "B2C ๊ณ ๊ฐ, ์ผ๋ฐ ์ฌ์ฉ์",
|
67 |
-
"tone": "์ฝ๊ณ ์น๊ทผํ, ์ดํดํ๊ธฐ ์ฌ์ด",
|
68 |
-
"focus": "์ฌ์ฉ ํธ์์ฑ, ํํ, ๊ฐ๊ฒฉ, ์ฐจ๋ณ์ "
|
69 |
-
}
|
70 |
-
}
|
71 |
-
|
72 |
-
# ํ๊ฒฝ ๋ณ์์์ ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
|
73 |
-
REPLICATE_API_TOKEN = os.getenv("RAPI_TOKEN")
|
74 |
-
FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN")
|
75 |
-
BRAVE_API_TOKEN = os.getenv("BAPI_TOKEN")
|
76 |
-
|
77 |
-
# ์ ์ญ ๋ณ์๋ก ํ์ฌ ์ฌ๋ผ์ด๋ ๋ฐ์ดํฐ ์ ์ฅ
|
78 |
-
current_slides_data = []
|
79 |
-
current_topic = ""
|
80 |
-
current_template = ""
|
81 |
-
current_theme = ""
|
82 |
-
uploaded_content = "" # ์ ์ญ ๋ณ์๋ก ์ถ๊ฐ
|
83 |
-
|
84 |
-
# ๋์์ธ ํ
๋ง ์ ์
|
85 |
-
DESIGN_THEMES = {
|
86 |
-
"๋ฏธ๋๋ฉ ๋ผ์ดํธ": {
|
87 |
-
"name": "Minimal Light",
|
88 |
-
"description": "๋ฐ๊ณ ๊นจ๋ํ ๋ฏธ๋๋ฉ ๋์์ธ",
|
89 |
-
"background": RGBColor(250, 250, 252),
|
90 |
-
"title_color": RGBColor(33, 37, 41),
|
91 |
-
"subtitle_color": RGBColor(52, 58, 64),
|
92 |
-
"text_color": RGBColor(73, 80, 87),
|
93 |
-
"accent_color": RGBColor(0, 123, 255),
|
94 |
-
"box_fill": RGBColor(255, 255, 255),
|
95 |
-
"box_opacity": 0.95,
|
96 |
-
"shadow": True,
|
97 |
-
"gradient": False
|
98 |
-
},
|
99 |
-
"๋ชจ๋ ๊ทธ๋ผ๋์ธํธ": {
|
100 |
-
"name": "Modern Gradient",
|
101 |
-
"description": "๋ถ๋๋ฌ์ด ๊ทธ๋ผ๋์ธํธ์ ํ๋์ ๋๋",
|
102 |
-
"background": RGBColor(245, 247, 250),
|
103 |
-
"title_color": RGBColor(25, 42, 86),
|
104 |
-
"subtitle_color": RGBColor(68, 85, 102),
|
105 |
-
"text_color": RGBColor(85, 102, 119),
|
106 |
-
"accent_color": RGBColor(103, 58, 183),
|
107 |
-
"box_fill": RGBColor(249, 250, 251),
|
108 |
-
"box_opacity": 0.9,
|
109 |
-
"shadow": True,
|
110 |
-
"gradient": True
|
111 |
-
},
|
112 |
-
"๋คํฌ ์๋ ๊ฐ์ค": {
|
113 |
-
"name": "Dark Elegance",
|
114 |
-
"description": "์ธ๋ จ๋ ๋คํฌ ๋ชจ๋ ๋์์ธ",
|
115 |
-
"background": RGBColor(25, 25, 35),
|
116 |
-
"title_color": RGBColor(240, 240, 245),
|
117 |
-
"subtitle_color": RGBColor(200, 200, 210),
|
118 |
-
"text_color": RGBColor(170, 170, 180),
|
119 |
-
"accent_color": RGBColor(0, 188, 212),
|
120 |
-
"box_fill": RGBColor(35, 35, 45),
|
121 |
-
"box_opacity": 0.85,
|
122 |
-
"shadow": False,
|
123 |
-
"gradient": False
|
124 |
-
},
|
125 |
-
"๋ค์ด์ฒ ๊ทธ๋ฆฐ": {
|
126 |
-
"name": "Nature Green",
|
127 |
-
"description": "์์ฐ ์นํ์ ์ธ ๊ทธ๋ฆฐ ํ
๋ง",
|
128 |
-
"background": RGBColor(242, 248, 244),
|
129 |
-
"title_color": RGBColor(27, 67, 50),
|
130 |
-
"subtitle_color": RGBColor(45, 106, 79),
|
131 |
-
"text_color": RGBColor(64, 125, 98),
|
132 |
-
"accent_color": RGBColor(76, 175, 80),
|
133 |
-
"box_fill": RGBColor(255, 255, 255),
|
134 |
-
"box_opacity": 0.92,
|
135 |
-
"shadow": True,
|
136 |
-
"gradient": False
|
137 |
-
},
|
138 |
-
"์ฝํผ๋ ์ดํธ ๋ธ๋ฃจ": {
|
139 |
-
"name": "Corporate Blue",
|
140 |
-
"description": "์ ๋ฌธ์ ์ธ ๋น์ฆ๋์ค ์คํ์ผ",
|
141 |
-
"background": RGBColor(244, 247, 252),
|
142 |
-
"title_color": RGBColor(13, 71, 161),
|
143 |
-
"subtitle_color": RGBColor(25, 118, 210),
|
144 |
-
"text_color": RGBColor(42, 63, 84),
|
145 |
-
"accent_color": RGBColor(33, 150, 243),
|
146 |
-
"box_fill": RGBColor(255, 255, 255),
|
147 |
-
"box_opacity": 0.95,
|
148 |
-
"shadow": True,
|
149 |
-
"gradient": False
|
150 |
-
}
|
151 |
-
}
|
152 |
-
|
153 |
-
# ์คํ์ผ ์ ์ (ํ๋ก์ธ์ค ํ๋ก์ฐ ์ถ๊ฐ)
|
154 |
-
STYLE_TEMPLATES = {
|
155 |
-
"Title Slide (Hero)": {
|
156 |
-
"name": "Title Slide",
|
157 |
-
"description": "Impactful hero image for title slide",
|
158 |
-
"use_case": "ํ์ง, ํ์ดํ",
|
159 |
-
"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"
|
160 |
-
},
|
161 |
-
"Thank You Slide": {
|
162 |
-
"name": "Closing Slide",
|
163 |
-
"description": "Elegant closing slide design with conclusion",
|
164 |
-
"use_case": "ํ๋ ์ ํ
์ด์
๋ง๋ฌด๋ฆฌ",
|
165 |
-
"example": "Abstract elegant background with soft gradient from deep blue to purple, golden particles floating like celebration confetti, subtle light rays, with space for conclusion text. Minimalist, professional, warm feeling"
|
166 |
-
},
|
167 |
-
"3D Style (Pixar-like)": {
|
168 |
-
"name": "3D Style",
|
169 |
-
"description": "Pixar-esque 3D render with volumetric lighting",
|
170 |
-
"use_case": "ํ์ง, ๋น์ , ๋ฏธ๋ ์ปจ์
",
|
171 |
-
"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."
|
172 |
-
},
|
173 |
-
"Elegant SWOT Quadrant": {
|
174 |
-
"name": "SWOT Analysis",
|
175 |
-
"description": "Flat-design 4-grid layout with minimal shadows",
|
176 |
-
"use_case": "ํํฉ ๋ถ์, ์ ๋ต ํ๊ฐ",
|
177 |
-
"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"
|
178 |
-
},
|
179 |
-
"Colorful Mind Map": {
|
180 |
-
"name": "Mind Map",
|
181 |
-
"description": "Hand-drawn educational style with vibrant colors",
|
182 |
-
"use_case": "๋ธ๋ ์ธ์คํ ๋ฐ, ์์ด๋์ด ์ ๋ฆฌ",
|
183 |
-
"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"
|
184 |
-
},
|
185 |
-
"Business Workflow": {
|
186 |
-
"name": "Business Process",
|
187 |
-
"description": "End-to-end business workflow with clear phases",
|
188 |
-
"use_case": "ํ๋ก์ธ์ค ์ค๋ช
, ๋จ๊ณ๋ณ ์งํ",
|
189 |
-
"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",
|
190 |
-
"is_process_flow": True # ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์ฌ์ฉ ํ์
|
191 |
-
},
|
192 |
-
"Industrial Design": {
|
193 |
-
"name": "Product Design",
|
194 |
-
"description": "Sleek industrial design concept sketch",
|
195 |
-
"use_case": "์ ํ ์๊ฐ, ์ปจ์
๋์์ธ",
|
196 |
-
"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"
|
197 |
-
},
|
198 |
-
"3D Bubble Chart": {
|
199 |
-
"name": "Bubble Chart",
|
200 |
-
"description": "Clean 3D bubble visualization",
|
201 |
-
"use_case": "๋น๊ต ๋ถ์, ํฌ์ง์
๋",
|
202 |
-
"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"
|
203 |
-
},
|
204 |
-
"Timeline Ribbon": {
|
205 |
-
"name": "Timeline",
|
206 |
-
"description": "Horizontal ribbon timeline with cyber-futuristic vibe",
|
207 |
-
"use_case": "์ผ์ , ๋ก๋๋งต, ๋ง์ผ์คํค",
|
208 |
-
"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"
|
209 |
-
},
|
210 |
-
"Risk Heat Map": {
|
211 |
-
"name": "Heat Map",
|
212 |
-
"description": "Risk assessment heat map with gradient colors",
|
213 |
-
"use_case": "๋ฆฌ์คํฌ ๋ถ์, ์ฐ์ ์์",
|
214 |
-
"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"
|
215 |
-
},
|
216 |
-
"Pyramid/Funnel": {
|
217 |
-
"name": "Funnel Chart",
|
218 |
-
"description": "Multi-layer gradient funnel visualization",
|
219 |
-
"use_case": "๋จ๊ณ๋ณ ์ถ์, ํต์ฌ ๋์ถ",
|
220 |
-
"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"
|
221 |
-
},
|
222 |
-
"KPI Dashboard": {
|
223 |
-
"name": "Dashboard",
|
224 |
-
"description": "Dark-mode analytics dashboard with sci-fi interface",
|
225 |
-
"use_case": "์ฑ๊ณผ ์งํ, ์ค์ ๋์๋ณด๋",
|
226 |
-
"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"
|
227 |
-
},
|
228 |
-
"Value Chain": {
|
229 |
-
"name": "Value Chain",
|
230 |
-
"description": "Horizontal value chain with industrial look",
|
231 |
-
"use_case": "๊ฐ์น ์ฌ์ฌ, ๋น์ฆ๋์ค ๋ชจ๋ธ",
|
232 |
-
"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"
|
233 |
-
},
|
234 |
-
"Gantt Chart": {
|
235 |
-
"name": "Gantt Chart",
|
236 |
-
"description": "Hand-drawn style Gantt chart with playful colors",
|
237 |
-
"use_case": "ํ๋ก์ ํธ ์ผ์ , ์์
๊ด๋ฆฌ",
|
238 |
-
"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"
|
239 |
-
},
|
240 |
-
"Mobile App Mockup": {
|
241 |
-
"name": "App Mockup",
|
242 |
-
"description": "Clean wireframe for mobile app design",
|
243 |
-
"use_case": "์ฑ/์น UI, ํ๋ฉด ์ค๊ณ",
|
244 |
-
"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"
|
245 |
-
},
|
246 |
-
"Flowchart": {
|
247 |
-
"name": "Flowchart",
|
248 |
-
"description": "Vibrant flowchart with minimalistic icons",
|
249 |
-
"use_case": "์์ฌ๊ฒฐ์ , ํ๋ก์ธ์ค ํ๋ฆ",
|
250 |
-
"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",
|
251 |
-
"is_process_flow": True # ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์ฌ์ฉ ํ์
|
252 |
-
}
|
253 |
-
}
|
254 |
-
|
255 |
-
# PPT ํ
ํ๋ฆฟ ์ ์ (๋์ ์ผ๋ก ์ฌ๋ผ์ด๋ ์ ์กฐ์ ๊ฐ๋ฅ)
|
256 |
-
# PPT_TEMPLATES ์์ - ํ๋ก์ธ์ค ํ๋ก์ฐ๋ ํน์ ์ฌ๋ผ์ด๋์๋ง ์ ์ฉ
|
257 |
-
PPT_TEMPLATES = {
|
258 |
-
"๋น์ฆ๋์ค ์ ์์": {
|
259 |
-
"description": "ํฌ์ ์ ์น, ์ฌ์
์ ์์ฉ",
|
260 |
-
"core_slides": [
|
261 |
-
{"title": "๋ชฉ์ฐจ", "style": "Flowchart", "prompt_hint": "ํ๋ ์ ํ
์ด์
๊ตฌ์กฐ"}, # ์ด๊ฑด ๋ชฉ์ฐจ์ฉ ํ๋ก์ฐ์ฐจํธ
|
262 |
-
{"title": "๋ฌธ์ ์ ์", "style": "Colorful Mind Map", "prompt_hint": "ํ์ฌ ์์ฅ์ ๋ฌธ์ ์ "},
|
263 |
-
{"title": "ํํฉ ๋ถ์", "style": "Elegant SWOT Quadrant", "prompt_hint": "๊ฐ์ , ์ฝ์ , ๊ธฐํ, ์ํ"},
|
264 |
-
{"title": "์๋ฃจ์
", "style": "Industrial Design", "prompt_hint": "์ ํ/์๋น์ค ์ปจ์
"},
|
265 |
-
{"title": "ํ๋ก์ธ์ค", "style": "Business Workflow", "prompt_hint": "์คํ ๋จ๊ณ"}, # ์ฌ๊ธฐ์๋ง ํ๋ก์ธ์ค ํ๋ก์ฐ
|
266 |
-
{"title": "์ผ์ ", "style": "Timeline Ribbon", "prompt_hint": "์ฃผ์ ๋ง์ผ์คํค"}
|
267 |
-
],
|
268 |
-
"optional_slides": [
|
269 |
-
{"title": "์์ฅ ๊ท๋ชจ", "style": "3D Bubble Chart", "prompt_hint": "์์ฅ ๊ธฐํ์ ์ฑ์ฅ์ฑ"},
|
270 |
-
{"title": "๊ฒฝ์ ๋ถ์", "style": "Risk Heat Map", "prompt_hint": "๊ฒฝ์์ฌ ํฌ์ง์
๋"},
|
271 |
-
{"title": "๋น์ฆ๋์ค ๋ชจ๋ธ", "style": "Value Chain", "prompt_hint": "์์ต ๊ตฌ์กฐ"},
|
272 |
-
{"title": "ํ ์๊ฐ", "style": "Colorful Mind Map", "prompt_hint": "ํต์ฌ ํ์๊ณผ ์ญ๋"},
|
273 |
-
{"title": "์ฌ๋ฌด ๊ณํ", "style": "KPI Dashboard", "prompt_hint": "์์ ๋งค์ถ๊ณผ ์์ต"},
|
274 |
-
{"title": "์ํ ๊ด๋ฆฌ", "style": "Risk Heat Map", "prompt_hint": "์ฃผ์ ๋ฆฌ์คํฌ์ ๋์"},
|
275 |
-
{"title": "ํํธ๋์ญ", "style": "Value Chain", "prompt_hint": "์ ๋ต์ ์ ํด"}, # Business Workflow ๋์ Value Chain
|
276 |
-
{"title": "๊ธฐ์ ์คํ", "style": "Industrial Design", "prompt_hint": "ํต์ฌ ๊ธฐ์ ๊ตฌ์กฐ"}, # Flowchart ๋์
|
277 |
-
{"title": "๊ณ ๊ฐ ์ฌ๋ก", "style": "Industrial Design", "prompt_hint": "์ฑ๊ณต ์ฌ๋ก"},
|
278 |
-
{"title": "์ฑ์ฅ ์ ๋ต", "style": "Timeline Ribbon", "prompt_hint": "ํ์ฅ ๊ณํ"},
|
279 |
-
{"title": "ํฌ์ ํ์ฉ", "style": "Pyramid/Funnel", "prompt_hint": "์๊ธ ์ฌ์ฉ ๊ณํ"},
|
280 |
-
{"title": "Exit ์ ๋ต", "style": "Timeline Ribbon", "prompt_hint": "์ถ๊ตฌ ์ ๋ต"}
|
281 |
-
]
|
282 |
-
},
|
283 |
-
"์ ํ ์๊ฐ": {
|
284 |
-
"description": "์ ์ ํ ๋ฐ์นญ, ์๋น์ค ์๊ฐ์ฉ",
|
285 |
-
"core_slides": [
|
286 |
-
{"title": "์ ํ ์ปจ์
", "style": "Industrial Design", "prompt_hint": "์ ํ ๋์์ธ"},
|
287 |
-
{"title": "์ฌ์ฉ์ ๋์ฆ", "style": "Colorful Mind Map", "prompt_hint": "๊ณ ๊ฐ ํ์ธํฌ์ธํธ"},
|
288 |
-
{"title": "๊ธฐ๋ฅ ์๊ฐ", "style": "Mobile App Mockup", "prompt_hint": "UI/UX ํ๋ฉด"},
|
289 |
-
{"title": "์๋ ์๋ฆฌ", "style": "Flowchart", "prompt_hint": "๊ธฐ๋ฅ ํ๋ก์ฐ"}, # ์ฌ๊ธฐ์๋ง ํ๋ก์ธ์ค ํ๋ก์ฐ
|
290 |
-
{"title": "์์ฅ ํฌ์ง์
", "style": "3D Bubble Chart", "prompt_hint": "๊ฒฝ์์ฌ ๋น๊ต"},
|
291 |
-
{"title": "์ถ์ ์ผ์ ", "style": "Timeline Ribbon", "prompt_hint": "๋ฐ์นญ ๋ก๋๋งต"}
|
292 |
-
],
|
293 |
-
"optional_slides": [
|
294 |
-
{"title": "ํ๊ฒ ๊ณ ๊ฐ", "style": "Colorful Mind Map", "prompt_hint": "์ฃผ์ ๊ณ ๊ฐ์ธต"},
|
295 |
-
{"title": "๊ฐ๊ฒฉ ์ ์ฑ
", "style": "Pyramid/Funnel", "prompt_hint": "๊ฐ๊ฒฉ ์ ๋ต"},
|
296 |
-
{"title": "๊ธฐ์ ์ฐ์", "style": "Industrial Design", "prompt_hint": "ํต์ฌ ๊ธฐ์ "},
|
297 |
-
{"title": "์ฌ์ฉ ์๋๋ฆฌ์ค", "style": "Mobile App Mockup", "prompt_hint": "ํ์ฉ ์ฌ๋ก"}, # Business Workflow ๋์
|
298 |
-
{"title": "๊ณ ๊ฐ ํ๊ธฐ", "style": "KPI Dashboard", "prompt_hint": "์ฌ์ฉ์ ํ๊ฐ"},
|
299 |
-
{"title": "ํ๋งค ์ฑ๋", "style": "Value Chain", "prompt_hint": "์ ํต ์ ๋ต"},
|
300 |
-
{"title": "๋ง์ผํ
์ ๋ต", "style": "Timeline Ribbon", "prompt_hint": "ํ๋ณด ๊ณํ"},
|
301 |
-
{"title": "์ฑ๋ฅ ๋น๊ต", "style": "3D Bubble Chart", "prompt_hint": "๋ฒค์น๋งํฌ"}
|
302 |
-
]
|
303 |
-
},
|
304 |
-
"ํ๋ก์ ํธ ๋ณด๊ณ ": {
|
305 |
-
"description": "์งํ ์ํฉ, ์ฑ๊ณผ ๋ณด๊ณ ์ฉ",
|
306 |
-
"core_slides": [
|
307 |
-
{"title": "ํ๋ก์ ํธ ๊ฐ์", "style": "Business Workflow", "prompt_hint": "์ ์ฒด ํ๋ก์ธ์ค"}, # ์ฌ๊ธฐ์๋ง
|
308 |
-
{"title": "์งํ ํํฉ", "style": "Gantt Chart", "prompt_hint": "์์
์ผ์ "},
|
309 |
-
{"title": "๋ฆฌ์คํฌ ๊ด๋ฆฌ", "style": "Risk Heat Map", "prompt_hint": "์ํ ์์"},
|
310 |
-
{"title": "์ฑ๊ณผ ์งํ", "style": "KPI Dashboard", "prompt_hint": "๋ฌ์ฑ ์ค์ "},
|
311 |
-
{"title": "ํฅํ ๊ณํ", "style": "Timeline Ribbon", "prompt_hint": "๋ค์ ๋จ๊ณ"}
|
312 |
-
],
|
313 |
-
"optional_slides": [
|
314 |
-
{"title": "์์ฐ ํํฉ", "style": "Pyramid/Funnel", "prompt_hint": "์์ฐ ์งํ"},
|
315 |
-
{"title": "ํ ์ฑ๊ณผ", "style": "3D Bubble Chart", "prompt_hint": "ํ๋ณ ๊ธฐ์ฌ๋"},
|
316 |
-
{"title": "์ด์ ๊ด๋ฆฌ", "style": "Risk Heat Map", "prompt_hint": "์ฃผ์ ์ด์"},
|
317 |
-
{"title": "๊ฐ์ ์ฌํญ", "style": "Colorful Mind Map", "prompt_hint": "ํ๋ก์ธ์ค ๊ฐ์ "},
|
318 |
-
{"title": "๊ตํ", "style": "Colorful Mind Map", "prompt_hint": "๋ฐฐ์ด ์ "} # Business Workflow ๋์
|
319 |
-
]
|
320 |
-
},
|
321 |
-
"์ ๋ต ๊ธฐํ": {
|
322 |
-
"description": "์ค์ฅ๊ธฐ ์ ๋ต, ๋น์ ์๋ฆฝ์ฉ",
|
323 |
-
"core_slides": [
|
324 |
-
{"title": "๋น์ ", "style": "3D Style (Pixar-like)", "prompt_hint": "๋ฏธ๋ ๋น์ "},
|
325 |
-
{"title": "ํ๊ฒฝ ๋ถ์", "style": "Elegant SWOT Quadrant", "prompt_hint": "๋ด์ธ๋ถ ํ๊ฒฝ"},
|
326 |
-
{"title": "์ ๋ต ์ฒด๊ณ", "style": "Colorful Mind Map", "prompt_hint": "์ ๋ต ๊ตฌ์กฐ"},
|
327 |
-
{"title": "๊ฐ์น ์ฌ์ฌ", "style": "Value Chain", "prompt_hint": "๋น์ฆ๋์ค ๋ชจ๋ธ"},
|
328 |
-
{"title": "์คํ ๋ก๋๋งต", "style": "Timeline Ribbon", "prompt_hint": "๋จ๊ณ๋ณ ๊ณํ"},
|
329 |
-
{"title": "๋ชฉํ ์งํ", "style": "KPI Dashboard", "prompt_hint": "KPI ๋ชฉํ"}
|
330 |
-
],
|
331 |
-
"optional_slides": [
|
332 |
-
{"title": "์์ฅ ์ ๋ง", "style": "3D Bubble Chart", "prompt_hint": "๋ฏธ๋ ์์ฅ"},
|
333 |
-
{"title": "ํ์ ๋ฐฉํฅ", "style": "Industrial Design", "prompt_hint": "ํ์ ์ ๋ต"},
|
334 |
-
{"title": "์กฐ์ง ๋ณํ", "style": "Value Chain", "prompt_hint": "์กฐ์ง ๊ฐํธ"}, # Business Workflow ๋์
|
335 |
-
{"title": "๋์งํธ ์ ํ", "style": "Industrial Design", "prompt_hint": "DX ์ ๋ต"}, # Flowchart ๋์
|
336 |
-
{"title": "์ง์๊ฐ๋ฅ์ฑ", "style": "Timeline Ribbon", "prompt_hint": "ESG ์ ๋ต"}
|
337 |
-
]
|
338 |
-
},
|
339 |
-
"์ฌ์ฉ์ ์ ์": {
|
340 |
-
"description": "์ง์ ๊ตฌ์ฑํ๊ธฐ",
|
341 |
-
"core_slides": [],
|
342 |
-
"optional_slides": []
|
343 |
-
}
|
344 |
-
}
|
345 |
-
|
346 |
-
def brave_search(query: str) -> List[Dict]:
|
347 |
-
"""Brave Search API๋ฅผ ์ฌ์ฉํ ์น ๊ฒ์"""
|
348 |
-
if not BRAVE_API_TOKEN:
|
349 |
-
print("[Brave Search] API ํ ํฐ์ด ์์ด ๊ฒ์์ ๊ฑด๋๋๋๋ค.")
|
350 |
-
return []
|
351 |
-
|
352 |
-
print(f"[Brave Search] ๊ฒ์์ด: {query}")
|
353 |
-
|
354 |
-
headers = {
|
355 |
-
"Accept": "application/json",
|
356 |
-
"X-Subscription-Token": BRAVE_API_TOKEN
|
357 |
-
}
|
358 |
-
|
359 |
-
params = {
|
360 |
-
"q": query,
|
361 |
-
"count": 5
|
362 |
-
}
|
363 |
-
|
364 |
-
try:
|
365 |
-
response = requests.get(
|
366 |
-
"https://api.search.brave.com/res/v1/web/search",
|
367 |
-
headers=headers,
|
368 |
-
params=params,
|
369 |
-
timeout=10
|
370 |
-
)
|
371 |
-
|
372 |
-
if response.status_code == 200:
|
373 |
-
data = response.json()
|
374 |
-
results = []
|
375 |
-
for item in data.get("web", {}).get("results", [])[:3]:
|
376 |
-
results.append({
|
377 |
-
"title": item.get("title", ""),
|
378 |
-
"description": item.get("description", ""),
|
379 |
-
"url": item.get("url", "")
|
380 |
-
})
|
381 |
-
print(f"[Brave Search] {len(results)}๊ฐ ๊ฒฐ๊ณผ ํ๋")
|
382 |
-
return results
|
383 |
-
else:
|
384 |
-
print(f"[Brave Search] ์ค๋ฅ: {response.status_code}")
|
385 |
-
return []
|
386 |
-
except Exception as e:
|
387 |
-
print(f"[Brave Search] ์์ธ: {str(e)}")
|
388 |
-
return []
|
389 |
-
|
390 |
-
def read_uploaded_file(file_path: str) -> str:
|
391 |
-
"""์
๋ก๋๋ ํ์ผ ์ฝ๊ธฐ (PDF, CSV, TXT)"""
|
392 |
-
print(f"[ํ์ผ ์ฝ๊ธฐ] {file_path}")
|
393 |
-
|
394 |
-
try:
|
395 |
-
# ํ์ผ ํ์ฅ์ ํ์ธ
|
396 |
-
ext = os.path.splitext(file_path)[1].lower()
|
397 |
-
|
398 |
-
if ext == '.pdf':
|
399 |
-
# PDF ์ฝ๊ธฐ
|
400 |
-
with open(file_path, 'rb') as file:
|
401 |
-
pdf_reader = PyPDF2.PdfReader(file)
|
402 |
-
text = ""
|
403 |
-
for page in pdf_reader.pages:
|
404 |
-
text += page.extract_text() + "\n"
|
405 |
-
return text[:5000] # ์ต๋ 5000์
|
406 |
-
|
407 |
-
elif ext == '.csv':
|
408 |
-
# CSV ์ฝ๊ธฐ
|
409 |
-
# ์ธ์ฝ๋ฉ ๊ฐ์ง
|
410 |
-
with open(file_path, 'rb') as file:
|
411 |
-
raw_data = file.read()
|
412 |
-
result = chardet.detect(raw_data)
|
413 |
-
encoding = result['encoding'] or 'utf-8'
|
414 |
-
|
415 |
-
df = pd.read_csv(file_path, encoding=encoding)
|
416 |
-
return f"CSV ๋ฐ์ดํฐ:\n{df.head(20).to_string()}\n\n์์ฝ: {len(df)} ํ, {len(df.columns)} ์ด"
|
417 |
-
|
418 |
-
elif ext in ['.txt', '.text']:
|
419 |
-
# ํ
์คํธ ํ์ผ ์ฝ๊ธฐ
|
420 |
-
with open(file_path, 'rb') as file:
|
421 |
-
raw_data = file.read()
|
422 |
-
result = chardet.detect(raw_data)
|
423 |
-
encoding = result['encoding'] or 'utf-8'
|
424 |
-
|
425 |
-
with open(file_path, 'r', encoding=encoding) as file:
|
426 |
-
return file.read()[:5000] # ์ต๋ 5000์
|
427 |
-
else:
|
428 |
-
return "์ง์ํ์ง ์๋ ํ์ผ ํ์์
๋๋ค."
|
429 |
-
|
430 |
-
except Exception as e:
|
431 |
-
return f"ํ์ผ ์ฝ๊ธฐ ์ค๋ฅ: {str(e)}"
|
432 |
-
|
433 |
-
def generate_presentation_notes(topic: str, slide_title: str, content: Dict, audience_type: str) -> str:
|
434 |
-
"""๊ฐ ์ฌ๋ผ์ด๋์ ๋ฐํ์ ๋
ธํธ ์์ฑ (๊ตฌ์ด์ฒด)"""
|
435 |
-
print(f"[๋ฐํ์ ๋
ธํธ] {slide_title} ์์ฑ ์ค...")
|
436 |
-
|
437 |
-
# ์ค๋์ธ์ค ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
438 |
-
audience_info = AUDIENCE_TYPES.get(audience_type, AUDIENCE_TYPES["์ผ๋ฐ ์ง์"])
|
439 |
-
|
440 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
441 |
-
headers = {
|
442 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
443 |
-
"Content-Type": "application/json"
|
444 |
-
}
|
445 |
-
|
446 |
-
system_prompt = f"""You are a professional presentation coach who creates natural, conversational speaker notes.
|
447 |
-
|
448 |
-
The audience for this presentation is: {audience_type} - {audience_info['description']}
|
449 |
-
Tone: {audience_info['tone']}
|
450 |
-
Focus areas: {audience_info['focus']}
|
451 |
-
|
452 |
-
The slide content uses concise noun-ending style, but your speaker notes should be natural and conversational.
|
453 |
-
|
454 |
-
Create speaker notes that:
|
455 |
-
1. Sound natural and conversational, as if speaking to {audience_type}
|
456 |
-
2. Expand on the concise bullet points with additional context relevant to this audience
|
457 |
-
3. Include transitions and engagement phrases appropriate for {audience_type}
|
458 |
-
4. Use a warm, professional tone suitable for {audience_type}
|
459 |
-
5. Be 100-150 words long
|
460 |
-
6. Include pauses and emphasis markers where appropriate
|
461 |
-
|
462 |
-
Note: The bullet points may include emojis - incorporate their meaning into your speech.
|
463 |
-
|
464 |
-
Format:
|
465 |
-
- Use conversational language appropriate for {audience_type}
|
466 |
-
- Include transition phrases
|
467 |
-
- Add engagement questions or comments that resonate with this audience
|
468 |
-
- Keep it professional but friendly"""
|
469 |
-
|
470 |
-
bullet_text = "\n".join(content.get("bullet_points", []))
|
471 |
-
user_message = f"""Topic: {topic}
|
472 |
-
Slide Title: {slide_title}
|
473 |
-
Subtitle: {content.get('subtitle', '')}
|
474 |
-
Key Points (concise style with emojis):
|
475 |
-
{bullet_text}
|
476 |
-
|
477 |
-
Create natural speaker notes that expand on these concise points for presenting this slide to {audience_type}."""
|
478 |
-
|
479 |
-
payload = {
|
480 |
-
"model": "dep89a2fld32mcm",
|
481 |
-
"messages": [
|
482 |
-
{
|
483 |
-
"role": "system",
|
484 |
-
"content": system_prompt
|
485 |
-
},
|
486 |
-
{
|
487 |
-
"role": "user",
|
488 |
-
"content": user_message
|
489 |
-
}
|
490 |
-
],
|
491 |
-
"max_tokens": 300,
|
492 |
-
"temperature": 0.8,
|
493 |
-
"stream": False
|
494 |
-
}
|
495 |
-
|
496 |
-
try:
|
497 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
498 |
-
if response.status_code == 200:
|
499 |
-
result = response.json()
|
500 |
-
notes = result['choices'][0]['message']['content'].strip()
|
501 |
-
|
502 |
-
# ํ๊ธ ์ฃผ์ ์ธ ๊ฒฝ์ฐ ๋ฒ๏ฟฝ๏ฟฝ
|
503 |
-
if any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in topic):
|
504 |
-
notes = translate_content_to_korean_natural(notes)
|
505 |
-
|
506 |
-
return notes
|
507 |
-
else:
|
508 |
-
return "์ด ์ฌ๋ผ์ด๋์์๋ ํต์ฌ ๋ด์ฉ์ ์ค๋ช
ํด ์ฃผ์ธ์."
|
509 |
-
except Exception as e:
|
510 |
-
print(f"[๋ฐํ์ ๋
ธํธ] ์ค๋ฅ: {str(e)}")
|
511 |
-
return "์ด ์ฌ๋ผ์ด๋์์๋ ํต์ฌ ๋ด์ฉ์ ์ค๋ช
ํด ์ฃผ์ธ์."
|
512 |
-
|
513 |
-
def generate_closing_notes(topic: str, conclusion_phrase: str, audience_type: str) -> str:
|
514 |
-
"""๋ง์ง๋ง ์ฌ๋ผ์ด๋์ ๋ฐํ์ ๋
ธํธ ์์ฑ"""
|
515 |
-
print(f"[๋ง๋ฌด๋ฆฌ ๋
ธํธ] ์์ฑ ์ค...")
|
516 |
-
|
517 |
-
# ์ค๋์ธ์ค ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
518 |
-
audience_info = AUDIENCE_TYPES.get(audience_type, AUDIENCE_TYPES["์ผ๋ฐ ์ง์"])
|
519 |
-
|
520 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
521 |
-
headers = {
|
522 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
523 |
-
"Content-Type": "application/json"
|
524 |
-
}
|
525 |
-
|
526 |
-
system_prompt = f"""You are a professional presentation coach creating closing speaker notes.
|
527 |
-
|
528 |
-
The audience for this presentation is: {audience_type} - {audience_info['description']}
|
529 |
-
Tone: {audience_info['tone']}
|
530 |
-
|
531 |
-
Create natural closing remarks that:
|
532 |
-
1. Thank the {audience_type} audience warmly and appropriately
|
533 |
-
2. Briefly summarize the key message relevant to {audience_type}
|
534 |
-
3. Reference the conclusion phrase naturally
|
535 |
-
4. End with an invitation for questions or next steps appropriate for {audience_type}
|
536 |
-
5. Be 80-100 words long
|
537 |
-
6. Sound conversational and warm
|
538 |
-
7. NO stage directions or parentheses - only spoken words
|
539 |
-
|
540 |
-
Write only what the speaker would say out loud."""
|
541 |
-
|
542 |
-
user_message = f"""Presentation topic: {topic}
|
543 |
-
Audience: {audience_type}
|
544 |
-
Conclusion phrase on screen: {conclusion_phrase}
|
545 |
-
|
546 |
-
Create natural closing speaker notes that wrap up the presentation effectively for {audience_type}."""
|
547 |
-
|
548 |
-
payload = {
|
549 |
-
"model": "dep89a2fld32mcm",
|
550 |
-
"messages": [
|
551 |
-
{
|
552 |
-
"role": "system",
|
553 |
-
"content": system_prompt
|
554 |
-
},
|
555 |
-
{
|
556 |
-
"role": "user",
|
557 |
-
"content": user_message
|
558 |
-
}
|
559 |
-
],
|
560 |
-
"max_tokens": 200,
|
561 |
-
"temperature": 0.8,
|
562 |
-
"stream": False
|
563 |
-
}
|
564 |
-
|
565 |
-
try:
|
566 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
567 |
-
if response.status_code == 200:
|
568 |
-
result = response.json()
|
569 |
-
notes = result['choices'][0]['message']['content'].strip()
|
570 |
-
|
571 |
-
# ํ๊ธ ์ฃผ์ ์ธ ๊ฒฝ์ฐ ๋ฒ์ญ
|
572 |
-
if any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in topic):
|
573 |
-
notes = translate_content_to_korean_natural(notes)
|
574 |
-
|
575 |
-
return notes
|
576 |
-
else:
|
577 |
-
return "์ค๋ ๋ฐํ๋ฅผ ๋ง๋ฌด๋ฆฌํ๋ฉฐ ๊ฐ์ฌ์ ๋ง์์ ๋๋ฆฝ๋๋ค. ์ง๋ฌธ์ด ์์ผ์๋ฉด ํธํ๊ฒ ๋ง์ํด ์ฃผ์ธ์."
|
578 |
-
except Exception as e:
|
579 |
-
print(f"[๋ง๋ฌด๋ฆฌ ๋
ธํธ] ์ค๋ฅ: {str(e)}")
|
580 |
-
return "์ค๋ ๋ฐํ๋ฅผ ๋ง๋ฌด๋ฆฌํ๋ฉฐ ๊ฐ์ฌ์ ๋ง์์ ๋๋ฆฝ๋๋ค. ์ง๋ฌธ์ด ์์ผ์๋ฉด ํธํ๊ฒ ๋ง์ํด ์ฃผ์ธ์."
|
581 |
-
|
582 |
-
def generate_conclusion_phrase(topic: str, audience_type: str) -> str:
|
583 |
-
"""ํ๋ ์ ํ
์ด์
์ ํต์ฌ์ ๋ด์ ๊ฒฐ๋ก ๋ฌธ๊ตฌ ์์ฑ"""
|
584 |
-
print(f"[๊ฒฐ๋ก ๋ฌธ๊ตฌ] ์์ฑ ์ค...")
|
585 |
-
|
586 |
-
# ์ค๋์ธ์ค ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
587 |
-
audience_info = AUDIENCE_TYPES.get(audience_type, AUDIENCE_TYPES["์ผ๋ฐ ์ง์"])
|
588 |
-
|
589 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
590 |
-
headers = {
|
591 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
592 |
-
"Content-Type": "application/json"
|
593 |
-
}
|
594 |
-
|
595 |
-
system_prompt = f"""You are a professional copywriter creating powerful closing statements for presentations.
|
596 |
-
|
597 |
-
The audience is: {audience_type} - {audience_info['description']}
|
598 |
-
Focus on: {audience_info['focus']}
|
599 |
-
|
600 |
-
Create a concise, impactful closing phrase that:
|
601 |
-
1. Captures the essence of the presentation topic
|
602 |
-
2. Resonates with {audience_type}
|
603 |
-
3. Is memorable and inspirational
|
604 |
-
4. Maximum 5-7 words
|
605 |
-
5. Uses powerful, action-oriented language appropriate for {audience_type}
|
606 |
-
6. Leaves a lasting impression
|
607 |
-
|
608 |
-
Examples for different audiences:
|
609 |
-
- For executives: "Excellence Through Strategic Innovation"
|
610 |
-
- For investors: "Maximum Returns, Minimal Risk"
|
611 |
-
- For technical teams: "Code Today, Transform Tomorrow"
|
612 |
-
- For customers: "Your Success, Our Mission"
|
613 |
-
|
614 |
-
Output only the phrase, no explanation."""
|
615 |
-
|
616 |
-
user_message = f"""Presentation topic: {topic}
|
617 |
-
Target audience: {audience_type}
|
618 |
-
|
619 |
-
Create a powerful closing phrase that encapsulates the main message for {audience_type}."""
|
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": 50,
|
634 |
-
"temperature": 0.9,
|
635 |
-
"stream": False
|
636 |
-
}
|
637 |
-
|
638 |
-
try:
|
639 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
640 |
-
if response.status_code == 200:
|
641 |
-
result = response.json()
|
642 |
-
phrase = result['choices'][0]['message']['content'].strip()
|
643 |
-
|
644 |
-
# ํ๊ธ ์ฃผ์ ์ธ ๊ฒฝ์ฐ ๋ฒ์ญ
|
645 |
-
if any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in topic):
|
646 |
-
phrase = translate_content_to_korean_concise(phrase)
|
647 |
-
|
648 |
-
return phrase
|
649 |
-
else:
|
650 |
-
return "ํจ๊ป ๋ง๋๋ ๋ฏธ๋"
|
651 |
-
except Exception as e:
|
652 |
-
print(f"[๊ฒฐ๋ก ๋ฌธ๊ตฌ] ์ค๋ฅ: {str(e)}")
|
653 |
-
return "ํจ๊ป ๋ง๋๋ ๋ฏธ๋"
|
654 |
-
|
655 |
-
def generate_slide_content(topic: str, slide_title: str, slide_context: str, audience_type: str,
|
656 |
-
uploaded_content: str = None, web_search_results: List[Dict] = None) -> Dict[str, str]:
|
657 |
-
"""๊ฐ ์ฌ๋ผ์ด๋์ ํ
์คํธ ๋ด์ฉ ์์ฑ"""
|
658 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] {slide_title} ํ
์คํธ ์์ฑ ์ค... (๋์: {audience_type})")
|
659 |
-
|
660 |
-
# ์ค๋์ธ์ค ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
661 |
-
audience_info = AUDIENCE_TYPES.get(audience_type, AUDIENCE_TYPES["์ผ๋ฐ ์ง์"])
|
662 |
-
|
663 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
664 |
-
headers = {
|
665 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
666 |
-
"Content-Type": "application/json"
|
667 |
-
}
|
668 |
-
|
669 |
-
system_prompt = f"""You are a professional presentation content writer specializing in creating concise, impactful slide content.
|
670 |
-
|
671 |
-
Target Audience: {audience_type} - {audience_info['description']}
|
672 |
-
Tone: {audience_info['tone']}
|
673 |
-
Focus: {audience_info['focus']}
|
674 |
-
|
675 |
-
Your task is to create content specifically tailored for {audience_type}:
|
676 |
-
1. A compelling subtitle (max 10 words) that resonates with {audience_type}
|
677 |
-
2. Exactly 5 bullet points with emojis relevant to {audience_type}'s interests
|
678 |
-
3. Each bullet point should be 8-12 words
|
679 |
-
4. Use noun-ending style (๋ช
์ฌํ ์ข
๊ฒฐ) for Korean or concise fragments for English
|
680 |
-
5. Content should address {audience_type}'s specific concerns and interests
|
681 |
-
|
682 |
-
IMPORTANT Style Guidelines:
|
683 |
-
- End sentences with nouns or concise phrases
|
684 |
-
- Avoid long verb endings like "์
๋๋ค", "์ต๋๋ค"
|
685 |
-
- Use short endings like "์", "ํจ" or noun forms
|
686 |
-
- Start each bullet with a relevant emoji that {audience_type} would appreciate
|
687 |
-
- Be extremely concise and impactful
|
688 |
-
|
689 |
-
Audience-specific emoji guidelines:
|
690 |
-
- For executives: ๐ ๐ฏ ๐ฐ ๐ ๐ ๐ ๐ ๐ก
|
691 |
-
- For investors: ๐ฐ ๐ ๐ ๐ฆ ๐ธ ๐ ๐ ๐
|
692 |
-
- For technical teams: ๐ง ๐ป ๐ ๏ธ โ๏ธ ๐ ๐ ๐ฑ ๐ค
|
693 |
-
- For general staff: ๐ค ๐ก ๐ โ
๐ฏ ๐ ๐
๐ช
|
694 |
-
- For customers: โญ ๐ ๐ ๐ก๏ธ ๐ โจ ๐
๐
|
695 |
-
- For general public: ๐ ๐ ๐ โค๏ธ ๐ ๐ โจ ๐ฏ
|
696 |
-
|
697 |
-
Output format (EXACTLY FOLLOW THIS FORMAT):
|
698 |
-
Subtitle: [subtitle here]
|
699 |
-
- ๐ฏ [Point 1 - tailored for {audience_type}]
|
700 |
-
- ๐ [Point 2 - tailored for {audience_type}]
|
701 |
-
- ๐ก [Point 3 - tailored for {audience_type}]
|
702 |
-
- ๐ [Point 4 - tailored for {audience_type}]
|
703 |
-
- โก [Point 5 - tailored for {audience_type}]"""
|
704 |
-
|
705 |
-
user_message = f"""Topic: {topic}
|
706 |
-
Slide Title: {slide_title}
|
707 |
-
Context: {slide_context}
|
708 |
-
Target Audience: {audience_type}"""
|
709 |
-
|
710 |
-
# ์
๋ก๋๋ ์ฝํ
์ธ ๊ฐ ์์ผ๋ฉด ์ถ๊ฐ
|
711 |
-
if uploaded_content:
|
712 |
-
user_message += f"\n\nReference Material:\n{uploaded_content[:1000]}"
|
713 |
-
|
714 |
-
# ์น ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ผ๋ฉด ์ถ๊ฐ
|
715 |
-
if web_search_results:
|
716 |
-
search_context = "\n\nWeb Search Results:\n"
|
717 |
-
for result in web_search_results[:3]:
|
718 |
-
search_context += f"- {result['title']}: {result['description']}\n"
|
719 |
-
user_message += search_context
|
720 |
-
|
721 |
-
user_message += f"\n\nCreate compelling content for this presentation slide specifically tailored for {audience_type}. Remember to use emojis and concise noun-ending style."
|
722 |
-
|
723 |
-
payload = {
|
724 |
-
"model": "dep89a2fld32mcm",
|
725 |
-
"messages": [
|
726 |
-
{
|
727 |
-
"role": "system",
|
728 |
-
"content": system_prompt
|
729 |
-
},
|
730 |
-
{
|
731 |
-
"role": "user",
|
732 |
-
"content": user_message
|
733 |
-
}
|
734 |
-
],
|
735 |
-
"max_tokens": 300,
|
736 |
-
"top_p": 0.8,
|
737 |
-
"temperature": 0.7,
|
738 |
-
"stream": False
|
739 |
-
}
|
740 |
-
|
741 |
-
try:
|
742 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
743 |
-
if response.status_code == 200:
|
744 |
-
result = response.json()
|
745 |
-
content = result['choices'][0]['message']['content'].strip()
|
746 |
-
|
747 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] LLM ์๋ต:\n{content}")
|
748 |
-
|
749 |
-
# Parse content - ๋ ๊ฐ๊ฑดํ ํ์ฑ
|
750 |
-
lines = content.split('\n')
|
751 |
-
subtitle = ""
|
752 |
-
bullet_points = []
|
753 |
-
|
754 |
-
for line in lines:
|
755 |
-
line = line.strip()
|
756 |
-
if not line:
|
757 |
-
continue
|
758 |
-
|
759 |
-
# Subtitle ํ์ฑ
|
760 |
-
if line.lower().startswith("subtitle:") or line.startswith("Subtitle:"):
|
761 |
-
subtitle = line.split(':', 1)[1].strip()
|
762 |
-
# Bullet point ํ์ฑ - โข ๋๋ - ๋ก ์์ํ๋ ๊ฒฝ์ฐ ๋ชจ๋ ์ฒ๋ฆฌ
|
763 |
-
elif line.startswith("โข") or line.startswith("-") or (len(line) > 2 and line[1] == ' ' and ord(line[0]) >= 128):
|
764 |
-
# ์ด๋ฏธ โข ๊ฐ ์์ผ๋ฉด ๊ทธ๋๋ก, ์์ผ๋ฉด ์ถ๊ฐ
|
765 |
-
if not line.startswith("โข"):
|
766 |
-
line = "โข " + line.lstrip("- ")
|
767 |
-
bullet_points.append(line)
|
768 |
-
|
769 |
-
# ๋ง์ฝ subtitle์ด ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ
|
770 |
-
if not subtitle:
|
771 |
-
subtitle = f"{slide_title} ๊ฐ์"
|
772 |
-
|
773 |
-
# ๋ง์ฝ bullet_points๊ฐ 5๊ฐ ๋ฏธ๋ง์ด๋ฉด ๊ธฐ๋ณธ๊ฐ ์ถ๊ฐ
|
774 |
-
while len(bullet_points) < 5:
|
775 |
-
bullet_points.append(f"โข ๐ ํฌ์ธํธ {len(bullet_points) + 1}")
|
776 |
-
|
777 |
-
# 5๊ฐ๋ง ์ ํ
|
778 |
-
bullet_points = bullet_points[:5]
|
779 |
-
|
780 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] ํ์ฑ๋ subtitle: {subtitle}")
|
781 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] ํ์ฑ๋ bullets: {bullet_points}")
|
782 |
-
|
783 |
-
# ํ๊ธ๋ก ๋ฒ์ญ์ด ํ์ํ ๊ฒฝ์ฐ
|
784 |
-
if any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in topic):
|
785 |
-
subtitle = translate_content_to_korean(subtitle)
|
786 |
-
# ๋ถ๋ฆฟ ํฌ์ธํธ๋ ์ด๋ชจ์ง๋ฅผ ์ ์งํ๋ฉด์ ๋ฒ์ญ
|
787 |
-
translated_bullets = []
|
788 |
-
for point in bullet_points:
|
789 |
-
# โข ์ ๊ฑฐํ๊ณ ๋ด์ฉ๋ง ์ถ์ถ
|
790 |
-
clean_point = point.replace('โข', '').strip()
|
791 |
-
|
792 |
-
# ์ด๋ชจ์ง์ ํ
์คํธ ๋ถ๋ฆฌ (์ฒซ ๋ฒ์งธ ๊ณต๋ฐฑ์ ๊ธฐ์ค์ผ๋ก)
|
793 |
-
if len(clean_point) > 0 and clean_point[0] in '๐ฏ๐๐ก๐โก๐๐๐ฐ๐๐ง๐๐โญ๐จ๐ฑ๐ค๐๐๏ธ๐๏ธ๐ฑ๐ป๐ ๏ธโ๏ธ๐ค๐โ
๐๐
๐ช๐๐๐ก๏ธโจ๐
๐๐๐ ๐โค๏ธ๐๐':
|
794 |
-
# ์ด๋ชจ์ง๊ฐ ์๋ ๊ฒฝ์ฐ
|
795 |
-
emoji = clean_point[0]
|
796 |
-
text = clean_point[1:].strip()
|
797 |
-
translated_text = translate_content_to_korean_concise(text)
|
798 |
-
translated_bullets.append(f"โข {emoji} {translated_text}")
|
799 |
-
else:
|
800 |
-
# ์ด๋ชจ์ง๊ฐ ์๋ ๊ฒฝ์ฐ
|
801 |
-
translated_bullets.append(f"โข {translate_content_to_korean_concise(clean_point)}")
|
802 |
-
|
803 |
-
bullet_points = translated_bullets
|
804 |
-
|
805 |
-
return {
|
806 |
-
"subtitle": subtitle,
|
807 |
-
"bullet_points": bullet_points
|
808 |
-
}
|
809 |
-
else:
|
810 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] API ์ค๋ฅ: {response.status_code}")
|
811 |
-
return {
|
812 |
-
"subtitle": slide_title,
|
813 |
-
"bullet_points": ["โข ๐ ๋ด์ฉ ์์ฑ ๋ถ๊ฐ"] * 5
|
814 |
-
}
|
815 |
-
except Exception as e:
|
816 |
-
print(f"[์ฌ๋ผ์ด๋ ๋ด์ฉ] ์ค๋ฅ: {str(e)}")
|
817 |
-
return {
|
818 |
-
"subtitle": slide_title,
|
819 |
-
"bullet_points": ["โข โ ๋ด์ฉ ์์ฑ ์ค๋ฅ"] * 5
|
820 |
-
}
|
821 |
-
|
822 |
-
def translate_content_to_korean(text: str) -> str:
|
823 |
-
"""์์ด ํ
์คํธ๋ฅผ ํ๊ธ๋ก ๋ฒ์ญ (์ผ๋ฐ์ฉ)"""
|
824 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
825 |
-
headers = {
|
826 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
827 |
-
"Content-Type": "application/json"
|
828 |
-
}
|
829 |
-
|
830 |
-
payload = {
|
831 |
-
"model": "dep89a2fld32mcm",
|
832 |
-
"messages": [
|
833 |
-
{
|
834 |
-
"role": "system",
|
835 |
-
"content": "You are a translator. Translate the given English text to Korean. Maintain professional business tone. Only return the translation without any explanation."
|
836 |
-
},
|
837 |
-
{
|
838 |
-
"role": "user",
|
839 |
-
"content": text
|
840 |
-
}
|
841 |
-
],
|
842 |
-
"max_tokens": 200,
|
843 |
-
"top_p": 0.8,
|
844 |
-
"stream": False
|
845 |
-
}
|
846 |
-
|
847 |
-
try:
|
848 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
849 |
-
if response.status_code == 200:
|
850 |
-
result = response.json()
|
851 |
-
return result['choices'][0]['message']['content'].strip()
|
852 |
-
else:
|
853 |
-
return text
|
854 |
-
except Exception as e:
|
855 |
-
return text
|
856 |
-
|
857 |
-
def translate_content_to_korean_concise(text: str) -> str:
|
858 |
-
"""์์ด ํ
์คํธ๋ฅผ ๊ฐ๊ฒฐํ ํ๊ธ๋ก ๋ฒ์ญ (๋ช
์ฌํ ์ข
๊ฒฐ)"""
|
859 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
860 |
-
headers = {
|
861 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
862 |
-
"Content-Type": "application/json"
|
863 |
-
}
|
864 |
-
|
865 |
-
payload = {
|
866 |
-
"model": "dep89a2fld32mcm",
|
867 |
-
"messages": [
|
868 |
-
{
|
869 |
-
"role": "system",
|
870 |
-
"content": """You are a translator specializing in concise Korean business presentations.
|
871 |
-
Translate to Korean using noun-ending style (๋ช
์ฌํ ์ข
๊ฒฐ์ด๋ฏธ).
|
872 |
-
End with "์", "ํจ", or noun forms instead of "์
๋๋ค", "์ต๋๋ค".
|
873 |
-
Keep it extremely concise and professional.
|
874 |
-
Examples: "์ ๋ต์ ํ๋", "ํต์ฌ ๊ณผ์ ๋์ถ", "์์ฅ ์ ๋ ์ ๋ต ์๋ฆฝ"
|
875 |
-
Only return the translation without any explanation."""
|
876 |
-
},
|
877 |
-
{
|
878 |
-
"role": "user",
|
879 |
-
"content": text
|
880 |
-
}
|
881 |
-
],
|
882 |
-
"max_tokens": 200,
|
883 |
-
"top_p": 0.8,
|
884 |
-
"stream": False
|
885 |
-
}
|
886 |
-
|
887 |
-
try:
|
888 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
889 |
-
if response.status_code == 200:
|
890 |
-
result = response.json()
|
891 |
-
return result['choices'][0]['message']['content'].strip()
|
892 |
-
else:
|
893 |
-
return text
|
894 |
-
except Exception as e:
|
895 |
-
return text
|
896 |
-
|
897 |
-
def translate_content_to_korean_natural(text: str) -> str:
|
898 |
-
"""์์ด ํ
์คํธ๋ฅผ ์์ฐ์ค๋ฌ์ด ํ๊ธ๋ก ๋ฒ์ญ (๋ฐํ ๋
ธํธ์ฉ)"""
|
899 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
900 |
-
headers = {
|
901 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
902 |
-
"Content-Type": "application/json"
|
903 |
-
}
|
904 |
-
|
905 |
-
payload = {
|
906 |
-
"model": "dep89a2fld32mcm",
|
907 |
-
"messages": [
|
908 |
-
{
|
909 |
-
"role": "system",
|
910 |
-
"content": """You are a translator. Translate the given English text to natural, conversational Korean.
|
911 |
-
Use polite spoken language suitable for presentations.
|
912 |
-
Only return the translation without any explanation."""
|
913 |
-
},
|
914 |
-
{
|
915 |
-
"role": "user",
|
916 |
-
"content": text
|
917 |
-
}
|
918 |
-
],
|
919 |
-
"max_tokens": 300,
|
920 |
-
"top_p": 0.8,
|
921 |
-
"stream": False
|
922 |
-
}
|
923 |
-
|
924 |
-
try:
|
925 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
926 |
-
if response.status_code == 200:
|
927 |
-
result = response.json()
|
928 |
-
return result['choices'][0]['message']['content'].strip()
|
929 |
-
else:
|
930 |
-
return text
|
931 |
-
except Exception as e:
|
932 |
-
return text
|
933 |
-
|
934 |
-
def generate_prompt_with_llm(topic: str, style_example: str = None, slide_context: str = None, uploaded_content: str = None) -> str:
|
935 |
-
"""์ฃผ์ ์ ์คํ์ผ ์์ ๋ฅผ ๋ฐ์์ LLM์ ์ฌ์ฉํด ์ด๋ฏธ์ง ํ๋กฌํํธ๋ฅผ ์์ฑ"""
|
936 |
-
print(f"[LLM] ํ๋กฌํํธ ์์ฑ ์์: {slide_context}")
|
937 |
-
|
938 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
939 |
-
headers = {
|
940 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
941 |
-
"Content-Type": "application/json"
|
942 |
-
}
|
943 |
-
|
944 |
-
system_prompt = """You are an expert image prompt engineer specializing in creating prompts for professional presentation slides.
|
945 |
-
|
946 |
-
Your task is to create prompts that:
|
947 |
-
1. Are highly specific and visual, perfect for PPT backgrounds or main visuals
|
948 |
-
2. Consider the slide's purpose and maintain consistency across a presentation
|
949 |
-
3. Include style references matching the given example
|
950 |
-
4. Focus on clean, professional visuals that won't distract from text overlays
|
951 |
-
5. Ensure high contrast areas for text readability when needed
|
952 |
-
6. Maintain brand consistency and professional aesthetics
|
953 |
-
|
954 |
-
Important guidelines:
|
955 |
-
- If given a style example, adapt the topic to match that specific visual style
|
956 |
-
- Consider the slide context (e.g., "ํ์ง", "ํํฉ ๋ถ์") to create appropriate visuals
|
957 |
-
- Always output ONLY the prompt without any explanation
|
958 |
-
- Keep prompts between 50-150 words for optimal results
|
959 |
-
- Ensure the visual supports rather than overwhelms the slide content"""
|
960 |
-
|
961 |
-
user_message = f"Topic: {topic}"
|
962 |
-
if style_example:
|
963 |
-
user_message += f"\n\nStyle reference to follow:\n{style_example}"
|
964 |
-
if slide_context:
|
965 |
-
user_message += f"\n\nSlide context: {slide_context}"
|
966 |
-
if uploaded_content:
|
967 |
-
user_message += f"\n\nAdditional context from document:\n{uploaded_content[:500]}"
|
968 |
-
|
969 |
-
payload = {
|
970 |
-
"model": "dep89a2fld32mcm",
|
971 |
-
"messages": [
|
972 |
-
{
|
973 |
-
"role": "system",
|
974 |
-
"content": system_prompt
|
975 |
-
},
|
976 |
-
{
|
977 |
-
"role": "user",
|
978 |
-
"content": user_message
|
979 |
-
}
|
980 |
-
],
|
981 |
-
"max_tokens": 300,
|
982 |
-
"top_p": 0.8,
|
983 |
-
"temperature": 0.7,
|
984 |
-
"stream": False
|
985 |
-
}
|
986 |
-
|
987 |
-
try:
|
988 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
989 |
-
if response.status_code == 200:
|
990 |
-
result = response.json()
|
991 |
-
prompt = result['choices'][0]['message']['content'].strip()
|
992 |
-
print(f"[LLM] ํ๋กฌํํธ ์์ฑ ์๋ฃ: {prompt[:50]}...")
|
993 |
-
return prompt
|
994 |
-
else:
|
995 |
-
error_msg = f"ํ๋กฌํํธ ์์ฑ ์คํจ: {response.status_code}"
|
996 |
-
print(f"[LLM] {error_msg}")
|
997 |
-
return error_msg
|
998 |
-
except Exception as e:
|
999 |
-
error_msg = f"ํ๋กฌํํธ ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
1000 |
-
print(f"[LLM] {error_msg}")
|
1001 |
-
return error_msg
|
1002 |
-
|
1003 |
-
def translate_to_english(text: str) -> str:
|
1004 |
-
"""ํ๊ธ ํ
์คํธ๋ฅผ ์์ด๋ก ๋ฒ์ญ (LLM ์ฌ์ฉ)"""
|
1005 |
-
if not any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text):
|
1006 |
-
return text
|
1007 |
-
|
1008 |
-
print(f"[๋ฒ์ญ] ํ๊ธ ๊ฐ์ง, ์์ด๋ก ๋ฒ์ญ ์์")
|
1009 |
-
|
1010 |
-
url = "https://api.friendli.ai/dedicated/v1/chat/completions"
|
1011 |
-
headers = {
|
1012 |
-
"Authorization": f"Bearer {FRIENDLI_TOKEN}",
|
1013 |
-
"Content-Type": "application/json"
|
1014 |
-
}
|
1015 |
-
|
1016 |
-
payload = {
|
1017 |
-
"model": "dep89a2fld32mcm",
|
1018 |
-
"messages": [
|
1019 |
-
{
|
1020 |
-
"role": "system",
|
1021 |
-
"content": "You are a translator. Translate the given Korean text to English. Only return the translation without any explanation."
|
1022 |
-
},
|
1023 |
-
{
|
1024 |
-
"role": "user",
|
1025 |
-
"content": text
|
1026 |
-
}
|
1027 |
-
],
|
1028 |
-
"max_tokens": 500,
|
1029 |
-
"top_p": 0.8,
|
1030 |
-
"stream": False
|
1031 |
-
}
|
1032 |
-
|
1033 |
-
try:
|
1034 |
-
response = requests.post(url, json=payload, headers=headers, timeout=30)
|
1035 |
-
if response.status_code == 200:
|
1036 |
-
result = response.json()
|
1037 |
-
translated = result['choices'][0]['message']['content'].strip()
|
1038 |
-
print(f"[๋ฒ์ญ] ์๋ฃ")
|
1039 |
-
return translated
|
1040 |
-
else:
|
1041 |
-
print(f"[๋ฒ์ญ] ์คํจ, ์๋ณธ ์ฌ์ฉ")
|
1042 |
-
return text
|
1043 |
-
except Exception as e:
|
1044 |
-
print(f"[๋ฒ์ญ] ์ค๋ฅ: {str(e)}, ์๋ณธ ์ฌ์ฉ")
|
1045 |
-
return text
|
1046 |
-
|
1047 |
-
def generate_image(prompt: str, seed: int = 10, slide_info: str = "") -> Tuple[Image.Image, str]:
|
1048 |
-
"""Replicate API๋ฅผ ์ฌ์ฉํด ์ด๋ฏธ์ง ์์ฑ ๋๋ ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ"""
|
1049 |
-
print(f"\n[์ด๋ฏธ์ง ์์ฑ] {slide_info}")
|
1050 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ํ๋กฌํํธ: {prompt[:50]}...")
|
1051 |
-
|
1052 |
-
global current_topic, uploaded_content
|
1053 |
-
|
1054 |
-
# ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ ์กฐ๊ฑด ํ์ธ
|
1055 |
-
should_generate_process_flow = False
|
1056 |
-
|
1057 |
-
# ์ฌ๋ผ์ด๋ ์ ๋ณด์์ ์ ๋ชฉ ์ถ์ถ
|
1058 |
-
slide_title = ""
|
1059 |
-
if ":" in slide_info:
|
1060 |
-
# "์ฌ๋ผ์ด๋ 5: ํ๋ก์ธ์ค" ํํ์์ "ํ๋ก์ธ์ค" ์ถ์ถ
|
1061 |
-
parts = slide_info.split(":")
|
1062 |
-
if len(parts) >= 2:
|
1063 |
-
slide_title = parts[1].strip()
|
1064 |
-
|
1065 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์ถ์ถ๋ ์ฌ๋ผ์ด๋ ์ ๋ชฉ: '{slide_title}'")
|
1066 |
-
|
1067 |
-
# 1. ํ๋ก์ธ์ค ๊ด๋ จ ํค์๋๊ฐ ์ฌ๋ผ์ด๋ ์ ๋ชฉ์ ํฌํจ๋์ด ์๋์ง ํ์ธ
|
1068 |
-
process_keywords = [
|
1069 |
-
"ํ๋ก์ธ์ค", "์๋", "ํ๋ก์ฐ", "ํ๋ฆ", "์ํฌํ๋ก์ฐ",
|
1070 |
-
"์ ์ฐจ", "๋จ๊ณ", "์ฒ๋ฆฌ", "์งํ", "๊ฐ์"
|
1071 |
-
]
|
1072 |
-
|
1073 |
-
# 2. ์คํ์ผ ํ์ธ
|
1074 |
-
is_workflow_style = False
|
1075 |
-
if any(style in prompt for style in ["Business Workflow", "Flowchart", "Business Process"]):
|
1076 |
-
is_workflow_style = True
|
1077 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] Business Workflow ๋๋ Flowchart ์คํ์ผ ๊ฐ์ง")
|
1078 |
-
|
1079 |
-
# 3. ์ฌ๋ผ์ด๋ ์ ๋ชฉ์ ํ๋ก์ธ์ค ํค์๋๊ฐ ์๊ฑฐ๋, ์คํ์ผ์ด ์ํฌํ๋ก์ฐ์ธ ๊ฒฝ์ฐ
|
1080 |
-
title_has_process = any(keyword in slide_title for keyword in process_keywords)
|
1081 |
-
prompt_has_process = any(keyword in prompt.lower() for keyword in ["process", "flow", "workflow"])
|
1082 |
-
|
1083 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์ ๋ชฉ์ ํ๋ก์ธ์ค ํค์๋: {title_has_process}")
|
1084 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์ํฌํ๋ก์ฐ ์คํ์ผ: {is_workflow_style}")
|
1085 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ํ๋กฌํํธ์ ํ๋ก์ธ์ค ํค์๋: {prompt_has_process}")
|
1086 |
-
|
1087 |
-
# ์กฐ๊ฑด ์ํ: ์ ๋ชฉ์ ํ๋ก์ธ์ค ํค์๋๊ฐ ์๊ณ , ์คํ์ผ์ด ๋ง๊ฑฐ๋ ํ๋กฌํํธ์ ๊ด๋ จ ํค์๋๊ฐ ์์ผ๋ฉด ์์ฑ
|
1088 |
-
if title_has_process and (is_workflow_style or prompt_has_process):
|
1089 |
-
should_generate_process_flow = True
|
1090 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] โ
ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ ์กฐ๊ฑด ์ถฉ์กฑ!")
|
1091 |
-
|
1092 |
-
# ํน๋ณ ์ผ์ด์ค: "๋ชฉ์ฐจ"๋ ํ๋ก์ธ์ค ํ๋ก์ฐ๊ฐ ์๋ ์ผ๋ฐ ์ด๋ฏธ์ง๋ก
|
1093 |
-
if "๋ชฉ์ฐจ" in slide_title:
|
1094 |
-
should_generate_process_flow = False
|
1095 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ๋ชฉ์ฐจ๋ ํ๋ก์ธ์ค ํ๋ก์ฐ ์ ์ธ")
|
1096 |
-
|
1097 |
-
# ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ
|
1098 |
-
if PROCESS_FLOW_AVAILABLE and should_generate_process_flow:
|
1099 |
-
try:
|
1100 |
-
print("[์ด๋ฏธ์ง ์์ฑ] ๐ง ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ ์์...")
|
1101 |
-
|
1102 |
-
# ์ฌ๋ผ์ด๋ ์ปจํ
์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ ์ ํ ํ๋ก์ธ์ค ํ๋ก์ฐ ์์ฑ
|
1103 |
-
img = generate_process_flow_for_ppt(
|
1104 |
-
topic=current_topic,
|
1105 |
-
context=slide_info,
|
1106 |
-
style="Business Workflow"
|
1107 |
-
)
|
1108 |
-
|
1109 |
-
if isinstance(img, Image.Image):
|
1110 |
-
print("[์ด๋ฏธ์ง ์์ฑ] โ
ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ ์ฑ๊ณต!")
|
1111 |
-
return img, "Process flow diagram generated with Korean support"
|
1112 |
-
else:
|
1113 |
-
print("[์ด๋ฏธ์ง ์์ฑ] โ ํ๋ก์ธ์ค ํ๋ก์ฐ ์์ฑ ์คํจ, ์ผ๋ฐ ์ด๋ฏธ์ง๋ก ๋์ฒด")
|
1114 |
-
except Exception as e:
|
1115 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] โ ํ๋ก์ธ์ค ํ๋ก์ฐ ์์ฑ ์ค๋ฅ: {str(e)}")
|
1116 |
-
import traceback
|
1117 |
-
traceback.print_exc()
|
1118 |
-
# ์คํจ์ ์ผ๋ฐ ์ด๋ฏธ์ง ์์ฑ์ผ๋ก ํด๋ฐฑ
|
1119 |
-
else:
|
1120 |
-
if not PROCESS_FLOW_AVAILABLE:
|
1121 |
-
print("[์ด๋ฏธ์ง ์์ฑ] โ ๏ธ ํ๋ก์ธ์ค ํ๋ก์ฐ ์์ฑ๊ธฐ๋ฅผ ์ฌ์ฉํ ์ ์์")
|
1122 |
-
else:
|
1123 |
-
print("[์ด๋ฏธ์ง ์์ฑ] โน๏ธ ํ๋ก์ธ์ค ํ๋ก์ฐ ์์ฑ ์กฐ๊ฑด ๋ฏธ์ถฉ์กฑ, ์ผ๋ฐ ์ด๋ฏธ์ง ์์ฑ")
|
1124 |
-
|
1125 |
-
# ๊ธฐ์กด ์ด๋ฏธ์ง ์์ฑ ๋ก์ง
|
1126 |
try:
|
1127 |
-
|
1128 |
-
|
1129 |
-
if not REPLICATE_API_TOKEN:
|
1130 |
-
error_msg = "RAPI_TOKEN ํ๊ฒฝ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค."
|
1131 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์ค๋ฅ: {error_msg}")
|
1132 |
-
return None, error_msg
|
1133 |
-
|
1134 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] Replicate API ํธ์ถ ์ค...")
|
1135 |
-
client = replicate.Client(api_token=REPLICATE_API_TOKEN)
|
1136 |
|
1137 |
-
|
1138 |
-
"
|
1139 |
-
|
1140 |
-
"speed_mode": "Extra Juiced ๐ (even more speed)",
|
1141 |
-
"output_quality": 100
|
1142 |
-
}
|
1143 |
-
|
1144 |
-
start_time = time.time()
|
1145 |
-
output = client.run(
|
1146 |
-
"prunaai/hidream-l1-fast:17c237d753218fed0ed477cb553902b6b75735f48c128537ab829096ef3d3645",
|
1147 |
-
input=input_params
|
1148 |
-
)
|
1149 |
-
|
1150 |
-
elapsed = time.time() - start_time
|
1151 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] API ์๋ต ๋ฐ์ ({elapsed:.1f}์ด)")
|
1152 |
-
|
1153 |
-
if output:
|
1154 |
-
if isinstance(output, str) and output.startswith('http'):
|
1155 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] URL์์ ์ด๋ฏธ์ง ๋ค์ด๋ก๋ ์ค...")
|
1156 |
-
response = requests.get(output, timeout=30)
|
1157 |
-
img = Image.open(BytesIO(response.content))
|
1158 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์๋ฃ!")
|
1159 |
-
return img, english_prompt
|
1160 |
-
else:
|
1161 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ค...")
|
1162 |
-
img = Image.open(BytesIO(output.read()))
|
1163 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์๋ฃ!")
|
1164 |
-
return img, english_prompt
|
1165 |
-
else:
|
1166 |
-
error_msg = "์ด๋ฏธ์ง ์์ฑ ์คํจ - ๋น ์๋ต"
|
1167 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] {error_msg}")
|
1168 |
-
return None, error_msg
|
1169 |
-
|
1170 |
-
except Exception as e:
|
1171 |
-
error_msg = f"์ค๋ฅ: {str(e)}"
|
1172 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] {error_msg}")
|
1173 |
-
print(f"[์ด๋ฏธ์ง ์์ฑ] ์์ธ ์ค๋ฅ:\n{traceback.format_exc()}")
|
1174 |
-
return None, error_msg
|
1175 |
-
|
1176 |
-
def create_slide_preview_html(slide_data: Dict) -> str:
|
1177 |
-
"""16:9 ๋น์จ์ ์ฌ๋ผ์ด๋ ํ๋ฆฌ๋ทฐ HTML ์์ฑ (ํธ์ง ๊ธฐ๋ฅ ์ ๊ฑฐ)"""
|
1178 |
-
|
1179 |
-
# ์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉ
|
1180 |
-
img_base64 = ""
|
1181 |
-
if slide_data.get("image"):
|
1182 |
-
buffered = BytesIO()
|
1183 |
-
slide_data["image"].save(buffered, format="PNG")
|
1184 |
-
img_base64 = base64.b64encode(buffered.getvalue()).decode()
|
1185 |
-
|
1186 |
-
# ํ
์คํธ ๋ด์ฉ ๊ฐ์ ธ์ค๊ธฐ
|
1187 |
-
subtitle = slide_data.get("subtitle", "")
|
1188 |
-
bullet_points = slide_data.get("bullet_points", [])
|
1189 |
-
|
1190 |
-
# HTML ์์ฑ
|
1191 |
-
html = f"""
|
1192 |
-
<div class="slide-container" style="
|
1193 |
-
width: 100%;
|
1194 |
-
max-width: 1200px;
|
1195 |
-
margin: 20px auto;
|
1196 |
-
background: white;
|
1197 |
-
border-radius: 12px;
|
1198 |
-
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
1199 |
-
overflow: hidden;
|
1200 |
-
">
|
1201 |
-
<div class="slide-header" style="
|
1202 |
-
background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
|
1203 |
-
color: white;
|
1204 |
-
padding: 15px 30px;
|
1205 |
-
font-size: 18px;
|
1206 |
-
font-weight: bold;
|
1207 |
-
">
|
1208 |
-
์ฌ๋ผ์ด๋ {slide_data.get('slide_number', '')}: {slide_data.get('title', '')}
|
1209 |
-
</div>
|
1210 |
-
|
1211 |
-
<div class="slide-content" style="
|
1212 |
-
display: flex;
|
1213 |
-
height: 0;
|
1214 |
-
padding-bottom: 56.25%; /* 16:9 ๋น์จ */
|
1215 |
-
position: relative;
|
1216 |
-
background: #fafbfc;
|
1217 |
-
">
|
1218 |
-
<div class="slide-inner" style="
|
1219 |
-
position: absolute;
|
1220 |
-
top: 0;
|
1221 |
-
left: 0;
|
1222 |
-
width: 100%;
|
1223 |
-
height: 100%;
|
1224 |
-
display: flex;
|
1225 |
-
padding: 20px;
|
1226 |
-
gap: 20px;
|
1227 |
-
">
|
1228 |
-
"""
|
1229 |
-
|
1230 |
-
# ํ์ง์ ๋ง์ง๋ง ์ฌ๋ผ์ด๋๋ ์ ์ฒด ํ๋ฉด ์ด๋ฏธ์ง
|
1231 |
-
if slide_data.get('title') in ['ํ์ง', 'Thank You']:
|
1232 |
-
html += f"""
|
1233 |
-
<!-- ์ ์ฒด ํ๋ฉด ์ด๋ฏธ์ง -->
|
1234 |
-
<div style="
|
1235 |
-
width: 100%;
|
1236 |
-
height: 100%;
|
1237 |
-
position: relative;
|
1238 |
-
background: #e9ecef;
|
1239 |
-
border-radius: 12px;
|
1240 |
-
overflow: hidden;
|
1241 |
-
">
|
1242 |
-
"""
|
1243 |
-
|
1244 |
-
if img_base64:
|
1245 |
-
html += f"""
|
1246 |
-
<img src="data:image/png;base64,{img_base64}" style="
|
1247 |
-
width: 100%;
|
1248 |
-
height: 100%;
|
1249 |
-
object-fit: cover;
|
1250 |
-
" alt="Slide Image">
|
1251 |
-
<div style="
|
1252 |
-
position: absolute;
|
1253 |
-
top: 50%;
|
1254 |
-
left: 50%;
|
1255 |
-
transform: translate(-50%, -50%);
|
1256 |
-
text-align: center;
|
1257 |
-
background: rgba(255, 255, 255, 0.9);
|
1258 |
-
padding: 30px 60px;
|
1259 |
-
border-radius: 20px;
|
1260 |
-
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
|
1261 |
-
backdrop-filter: blur(10px);
|
1262 |
-
">
|
1263 |
-
"""
|
1264 |
-
|
1265 |
-
if slide_data.get('title') == 'ํ์ง':
|
1266 |
-
html += f"""
|
1267 |
-
<h1 style="font-size: 48px; margin-bottom: 10px; color: #000000; font-weight: 700;">{slide_data.get('topic', '')}</h1>
|
1268 |
-
<h2 style="font-size: 24px; margin-top: 0; color: #212529; font-weight: 400;">{subtitle}</h2>
|
1269 |
-
"""
|
1270 |
-
else: # Thank You
|
1271 |
-
html += f"""
|
1272 |
-
<h1 style="font-size: 42px; color: #000000; font-weight: 700; line-height: 1.2;">{subtitle}</h1>
|
1273 |
-
"""
|
1274 |
-
|
1275 |
-
html += """
|
1276 |
-
</div>
|
1277 |
-
"""
|
1278 |
-
|
1279 |
-
html += """
|
1280 |
-
</div>
|
1281 |
-
"""
|
1282 |
-
else:
|
1283 |
-
# ์ผ๋ฐ ์ฌ๋ผ์ด๋ ๋ ์ด์์
|
1284 |
-
html += f"""
|
1285 |
-
<!-- ํ
์คํธ ์์ญ (์ข์ธก) -->
|
1286 |
-
<div class="text-area" style="
|
1287 |
-
flex: 1;
|
1288 |
-
padding: 30px;
|
1289 |
-
display: flex;
|
1290 |
-
flex-direction: column;
|
1291 |
-
justify-content: center;
|
1292 |
-
background: rgba(255, 255, 255, 0.95);
|
1293 |
-
border-radius: 12px;
|
1294 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08);
|
1295 |
-
">
|
1296 |
-
<h2 style="
|
1297 |
-
color: #212529;
|
1298 |
-
font-size: 28px;
|
1299 |
-
margin-bottom: 30px;
|
1300 |
-
font-weight: 600;
|
1301 |
-
">{subtitle}</h2>
|
1302 |
-
|
1303 |
-
<ul style="
|
1304 |
-
list-style: none;
|
1305 |
-
padding: 0;
|
1306 |
-
margin: 0;
|
1307 |
-
">
|
1308 |
-
"""
|
1309 |
-
|
1310 |
-
for point in bullet_points:
|
1311 |
-
clean_point = point.replace('โข', '').strip()
|
1312 |
-
html += f"""
|
1313 |
-
<li style="
|
1314 |
-
margin-bottom: 16px;
|
1315 |
-
padding-left: 28px;
|
1316 |
-
position: relative;
|
1317 |
-
color: #495057;
|
1318 |
-
font-size: 16px;
|
1319 |
-
line-height: 1.6;
|
1320 |
-
">
|
1321 |
-
<span style="
|
1322 |
-
position: absolute;
|
1323 |
-
left: 0;
|
1324 |
-
color: #007bff;
|
1325 |
-
font-size: 18px;
|
1326 |
-
">โข</span>
|
1327 |
-
{clean_point}
|
1328 |
-
</li>
|
1329 |
-
"""
|
1330 |
-
|
1331 |
-
html += f"""
|
1332 |
-
</ul>
|
1333 |
-
</div>
|
1334 |
-
|
1335 |
-
<!-- ์ด๋ฏธ์ง ์์ญ (์ฐ์ธก) -->
|
1336 |
-
<div class="image-area" style="
|
1337 |
-
flex: 1;
|
1338 |
-
display: flex;
|
1339 |
-
align-items: center;
|
1340 |
-
justify-content: center;
|
1341 |
-
padding: 20px;
|
1342 |
-
">
|
1343 |
-
"""
|
1344 |
-
|
1345 |
-
if img_base64:
|
1346 |
-
html += f"""
|
1347 |
-
<img src="data:image/png;base64,{img_base64}" style="
|
1348 |
-
max-width: 100%;
|
1349 |
-
max-height: 100%;
|
1350 |
-
object-fit: contain;
|
1351 |
-
border-radius: 8px;
|
1352 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
1353 |
-
" alt="Slide Image">
|
1354 |
-
"""
|
1355 |
-
else:
|
1356 |
-
html += """
|
1357 |
-
<div style="
|
1358 |
-
color: #6c757d;
|
1359 |
-
text-align: center;
|
1360 |
-
">
|
1361 |
-
<div style="font-size: 48px;">๐ผ๏ธ</div>
|
1362 |
-
<p>์ด๋ฏธ์ง ์์ฑ ์ค...</p>
|
1363 |
-
</div>
|
1364 |
-
"""
|
1365 |
|
1366 |
-
|
1367 |
-
|
1368 |
-
|
1369 |
-
|
1370 |
-
html += """
|
1371 |
-
</div>
|
1372 |
-
</div>
|
1373 |
-
</div>
|
1374 |
-
"""
|
1375 |
-
|
1376 |
-
return html
|
1377 |
-
|
1378 |
-
def create_pptx_file(results: List[Dict], topic: str, template_name: str, theme_name: str = "๋ฏธ๋๋ฉ ๋ผ์ดํธ") -> str:
|
1379 |
-
"""์์ฑ๋ ๊ฒฐ๊ณผ๋ฅผ PPTX ํ์ผ๋ก ๋ณํ (๋ฐํ์ ๋
ธํธ ํฌํจ)"""
|
1380 |
-
print(f"[PPTX] ํ์ผ ์์ฑ ์์... ํ
๋ง: {theme_name}")
|
1381 |
-
|
1382 |
-
# ํ๋ ์ ํ
์ด์
์์ฑ (16:9 ๋น์จ)
|
1383 |
-
prs = Presentation()
|
1384 |
-
prs.slide_width = Inches(16)
|
1385 |
-
prs.slide_height = Inches(9)
|
1386 |
-
|
1387 |
-
# ์ ํ๋ ํ
๋ง ๊ฐ์ ธ์ค๊ธฐ
|
1388 |
-
theme = DESIGN_THEMES.get(theme_name, DESIGN_THEMES["๋ฏธ๋๋ฉ ๋ผ์ดํธ"])
|
1389 |
-
|
1390 |
-
# ๊ฐ ๊ฒฐ๊ณผ ์ฌ๋ผ์ด๋ ์ถ๊ฐ
|
1391 |
-
for i, result in enumerate(results):
|
1392 |
-
if not result.get("success", False):
|
1393 |
-
continue
|
1394 |
-
|
1395 |
-
slide_data = result.get("slide_data", {})
|
1396 |
|
1397 |
-
#
|
1398 |
-
|
1399 |
-
slide = prs.slides.add_slide(blank_layout)
|
1400 |
|
1401 |
-
#
|
1402 |
-
if slide_data.get('title') == 'ํ์ง':
|
1403 |
-
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ถ๊ฐ
|
1404 |
-
if slide_data.get('image'):
|
1405 |
-
try:
|
1406 |
-
img_buffer = BytesIO()
|
1407 |
-
slide_data['image'].save(img_buffer, format='PNG')
|
1408 |
-
img_buffer.seek(0)
|
1409 |
-
|
1410 |
-
# ์ ์ฒด ํ๋ฉด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง
|
1411 |
-
pic = slide.shapes.add_picture(
|
1412 |
-
img_buffer,
|
1413 |
-
0, 0,
|
1414 |
-
width=prs.slide_width,
|
1415 |
-
height=prs.slide_height
|
1416 |
-
)
|
1417 |
-
# ๋งจ ๋ค๋ก ๋ณด๋ด๊ธฐ
|
1418 |
-
slide.shapes._spTree.remove(pic._element)
|
1419 |
-
slide.shapes._spTree.insert(2, pic._element)
|
1420 |
-
except Exception as e:
|
1421 |
-
print(f"[PPTX] ํ์ง ์ด๋ฏธ์ง ์ถ๊ฐ ์คํจ: {str(e)}")
|
1422 |
-
|
1423 |
-
# ์ ๋ชฉ ๋ฐฐ๊ฒฝ ๋ฐ์ค (๋ฐํฌ๋ช
- ๋ ํฌ๋ช
ํ๊ฒ)
|
1424 |
-
title_bg = slide.shapes.add_shape(
|
1425 |
-
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1426 |
-
Inches(2), Inches(2.8),
|
1427 |
-
Inches(12), Inches(3.2)
|
1428 |
-
)
|
1429 |
-
title_bg.fill.solid()
|
1430 |
-
title_bg.fill.fore_color.rgb = RGBColor(255, 255, 255) # ํฐ์ ๋ฐฐ๊ฒฝ
|
1431 |
-
title_bg.fill.transparency = 0.8 # 50% ํฌ๋ช
๋ (๋ ํฌ๋ช
ํ๊ฒ)
|
1432 |
-
title_bg.line.fill.background()
|
1433 |
-
|
1434 |
-
# ๊ทธ๋ฆผ์ ํจ๊ณผ ์ถ๊ฐ (๋ ์ฝํ๊ฒ)
|
1435 |
-
shadow = title_bg.shadow
|
1436 |
-
shadow.visible = True
|
1437 |
-
shadow.distance = Pt(6)
|
1438 |
-
shadow.size = 100
|
1439 |
-
shadow.blur_radius = Pt(12)
|
1440 |
-
shadow.transparency = 0.8
|
1441 |
-
shadow.angle = 45
|
1442 |
-
|
1443 |
-
# ์ ๋ชฉ ํ
์คํธ ์ถ๊ฐ
|
1444 |
-
title_box = slide.shapes.add_textbox(
|
1445 |
-
Inches(2), Inches(3.2),
|
1446 |
-
Inches(12), Inches(1.5)
|
1447 |
-
)
|
1448 |
-
title_frame = title_box.text_frame
|
1449 |
-
title_frame.text = topic
|
1450 |
-
title_para = title_frame.paragraphs[0]
|
1451 |
-
title_para.font.size = Pt(48)
|
1452 |
-
title_para.font.bold = True
|
1453 |
-
title_para.font.color.rgb = RGBColor(0, 0, 0) # ์์ ํ ๊ฒ์ ์
|
1454 |
-
title_para.alignment = PP_ALIGN.CENTER
|
1455 |
-
|
1456 |
-
# ๋ถ์ ๋ชฉ ์ถ๊ฐ (์ ๋ชฉ๊ณผ ๊ฐ๊น์ด)
|
1457 |
-
subtitle_box = slide.shapes.add_textbox(
|
1458 |
-
Inches(2), Inches(4.3),
|
1459 |
-
Inches(12), Inches(1.0)
|
1460 |
-
)
|
1461 |
-
subtitle_frame = subtitle_box.text_frame
|
1462 |
-
subtitle_frame.text = slide_data.get('subtitle', f'{template_name} - AI ํ๋ ์ ํ
์ด์
')
|
1463 |
-
subtitle_para = subtitle_frame.paragraphs[0]
|
1464 |
-
subtitle_para.font.size = Pt(28) # 24์์ 28๋ก ์ฆ๊ฐ
|
1465 |
-
subtitle_para.font.color.rgb = RGBColor(33, 37, 41) # ์งํ ํ์
|
1466 |
-
subtitle_para.alignment = PP_ALIGN.CENTER
|
1467 |
-
|
1468 |
-
# Thank You ์ฌ๋ผ์ด๋
|
1469 |
-
elif slide_data.get('title') == 'Thank You':
|
1470 |
-
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์ถ๊ฐ
|
1471 |
-
if slide_data.get('image'):
|
1472 |
-
try:
|
1473 |
-
img_buffer = BytesIO()
|
1474 |
-
slide_data['image'].save(img_buffer, format='PNG')
|
1475 |
-
img_buffer.seek(0)
|
1476 |
-
|
1477 |
-
# ์ ์ฒด ํ๋ฉด ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง
|
1478 |
-
pic = slide.shapes.add_picture(
|
1479 |
-
img_buffer,
|
1480 |
-
0, 0,
|
1481 |
-
width=prs.slide_width,
|
1482 |
-
height=prs.slide_height
|
1483 |
-
)
|
1484 |
-
# ๋งจ ๋ค๋ก ๋ณด๋ด๊ธฐ
|
1485 |
-
slide.shapes._spTree.remove(pic._element)
|
1486 |
-
slide.shapes._spTree.insert(2, pic._element)
|
1487 |
-
except Exception as e:
|
1488 |
-
print(f"[PPTX] Thank You ์ด๋ฏธ์ง ์ถ๊ฐ ์คํจ: {str(e)}")
|
1489 |
-
|
1490 |
-
# Thank You ๋ฐฐ๊ฒฝ ๋ฐ์ค (๋ฐํฌ๋ช
- ๋ ํฌ๋ช
ํ๊ฒ)
|
1491 |
-
thanks_bg = slide.shapes.add_shape(
|
1492 |
-
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1493 |
-
Inches(2), Inches(3.5),
|
1494 |
-
Inches(12), Inches(2.5)
|
1495 |
-
)
|
1496 |
-
thanks_bg.fill.solid()
|
1497 |
-
thanks_bg.fill.fore_color.rgb = RGBColor(255, 255, 255) # ํฐ์ ๋ฐฐ๊ฒฝ
|
1498 |
-
thanks_bg.fill.transparency = 0.8 # 50% ํฌ๋ช
๋ (๋ ํฌ๋ช
ํ๊ฒ)
|
1499 |
-
thanks_bg.line.fill.background()
|
1500 |
-
|
1501 |
-
# ๊ทธ๋ฆผ์ ํจ๊ณผ ์ถ๊ฐ (๋ ์ฝํ๊ฒ)
|
1502 |
-
shadow = thanks_bg.shadow
|
1503 |
-
shadow.visible = True
|
1504 |
-
shadow.distance = Pt(6)
|
1505 |
-
shadow.size = 100
|
1506 |
-
shadow.blur_radius = Pt(12)
|
1507 |
-
shadow.transparency = 0.8
|
1508 |
-
shadow.angle = 45
|
1509 |
-
|
1510 |
-
# Thank You ํ
์คํธ (๊ฒฐ๋ก ๋ฌธ๊ตฌ)
|
1511 |
-
thanks_box = slide.shapes.add_textbox(
|
1512 |
-
Inches(2), Inches(4),
|
1513 |
-
Inches(12), Inches(1.5)
|
1514 |
-
)
|
1515 |
-
thanks_frame = thanks_box.text_frame
|
1516 |
-
thanks_frame.text = slide_data.get('subtitle', 'Thank You') # ๊ฒฐ๋ก ๋ฌธ๊ตฌ ์ฌ์ฉ
|
1517 |
-
thanks_para = thanks_frame.paragraphs[0]
|
1518 |
-
thanks_para.font.size = Pt(42) # ํฌ๊ธฐ๋ฅผ ์กฐ๊ธ ์ค์
|
1519 |
-
thanks_para.font.bold = True
|
1520 |
-
thanks_para.font.color.rgb = RGBColor(0, 0, 0) # ์์ ํ ๊ฒ์ ์
|
1521 |
-
thanks_para.alignment = PP_ALIGN.CENTER
|
1522 |
-
|
1523 |
-
# ์ผ๋ฐ ์ฌ๋ผ์ด๋
|
1524 |
-
else:
|
1525 |
-
# ๋ฐฐ๊ฒฝ์ ์ค์
|
1526 |
-
background = slide.background
|
1527 |
-
fill = background.fill
|
1528 |
-
fill.solid()
|
1529 |
-
fill.fore_color.rgb = theme["background"]
|
1530 |
-
|
1531 |
-
# ์ฌ๋ผ์ด๋ ์ ๋ชฉ ๋ฐฐ๊ฒฝ ๋ฐ์ค (๋ฅ๊ทผ ๋ชจ์๋ฆฌ ํจ๊ณผ)
|
1532 |
-
title_box_bg = slide.shapes.add_shape(
|
1533 |
-
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1534 |
-
Inches(0.3), Inches(0.2),
|
1535 |
-
Inches(15.4), Inches(1.0)
|
1536 |
-
)
|
1537 |
-
title_box_bg.fill.solid()
|
1538 |
-
title_box_bg.fill.fore_color.rgb = theme["box_fill"]
|
1539 |
-
title_box_bg.fill.transparency = 1 - theme["box_opacity"]
|
1540 |
-
|
1541 |
-
# ๊ทธ๋ฆผ์ ํจ๊ณผ
|
1542 |
-
if theme["shadow"]:
|
1543 |
-
shadow = title_box_bg.shadow
|
1544 |
-
shadow.visible = True
|
1545 |
-
shadow.distance = Pt(4)
|
1546 |
-
shadow.size = 100
|
1547 |
-
shadow.blur_radius = Pt(8)
|
1548 |
-
shadow.transparency = 0.75
|
1549 |
-
shadow.angle = 45
|
1550 |
-
|
1551 |
-
title_box_bg.line.fill.background() # ํ
๋๋ฆฌ ์์
|
1552 |
-
|
1553 |
-
# ์ฌ๋ผ์ด๋ ์ ๋ชฉ ์ถ๊ฐ
|
1554 |
-
title_box = slide.shapes.add_textbox(
|
1555 |
-
Inches(0.5), Inches(0.3),
|
1556 |
-
Inches(15), Inches(0.8)
|
1557 |
-
)
|
1558 |
-
title_frame = title_box.text_frame
|
1559 |
-
title_frame.text = f"{slide_data.get('title', '')}"
|
1560 |
-
title_para = title_frame.paragraphs[0]
|
1561 |
-
title_para.font.size = Pt(28)
|
1562 |
-
title_para.font.bold = True
|
1563 |
-
title_para.font.color.rgb = theme["title_color"]
|
1564 |
-
|
1565 |
-
# ์ข์ธก ํ
์คํธ ์์ญ ๋ฐฐ๊ฒฝ ๋ฐ์ค
|
1566 |
-
text_box_bg = slide.shapes.add_shape(
|
1567 |
-
MSO_SHAPE.ROUNDED_RECTANGLE,
|
1568 |
-
Inches(0.3), Inches(1.4),
|
1569 |
-
Inches(7.8), Inches(6.8)
|
1570 |
-
)
|
1571 |
-
text_box_bg.fill.solid()
|
1572 |
-
text_box_bg.fill.fore_color.rgb = theme["box_fill"]
|
1573 |
-
text_box_bg.fill.transparency = 1 - theme["box_opacity"]
|
1574 |
-
|
1575 |
-
if theme["shadow"]:
|
1576 |
-
shadow = text_box_bg.shadow
|
1577 |
-
shadow.visible = True
|
1578 |
-
shadow.distance = Pt(5)
|
1579 |
-
shadow.size = 100
|
1580 |
-
shadow.blur_radius = Pt(10)
|
1581 |
-
shadow.transparency = 0.7
|
1582 |
-
shadow.angle = 45
|
1583 |
-
|
1584 |
-
text_box_bg.line.fill.background()
|
1585 |
-
|
1586 |
-
# ์ข์ธก ํ
์คํธ ์์ญ
|
1587 |
-
text_box = slide.shapes.add_textbox(
|
1588 |
-
Inches(0.8), Inches(1.8),
|
1589 |
-
Inches(7.0), Inches(6.0)
|
1590 |
-
)
|
1591 |
-
text_frame = text_box.text_frame
|
1592 |
-
text_frame.word_wrap = True
|
1593 |
-
|
1594 |
-
# ์์ ๋ชฉ ์ถ๊ฐ
|
1595 |
-
subtitle_para = text_frame.paragraphs[0]
|
1596 |
-
subtitle_para.text = slide_data.get('subtitle', '')
|
1597 |
-
subtitle_para.font.size = Pt(20)
|
1598 |
-
subtitle_para.font.bold = True
|
1599 |
-
subtitle_para.font.color.rgb = theme["subtitle_color"]
|
1600 |
-
subtitle_para.space_after = Pt(20)
|
1601 |
-
|
1602 |
-
# ๋ถ๋ฆฟ ํฌ์ธํธ ์ถ๊ฐ
|
1603 |
-
bullet_points = slide_data.get('bullet_points', [])
|
1604 |
-
for point in bullet_points:
|
1605 |
-
p = text_frame.add_paragraph()
|
1606 |
-
# โข ์ ๊ฑฐํ๊ณ ํ
์คํธ๋ง ์ถ๊ฐ (์ด๋ชจ์ง๋ ์ ์ง)
|
1607 |
-
clean_text = point.replace('โข', '').strip()
|
1608 |
-
p.text = clean_text
|
1609 |
-
p.font.size = Pt(16)
|
1610 |
-
p.font.color.rgb = theme["text_color"]
|
1611 |
-
# ๋ถ๋ฆฟ ์์ด ๋ค์ฌ์ฐ๊ธฐ๋ง
|
1612 |
-
p.level = 0
|
1613 |
-
p.space_after = Pt(12)
|
1614 |
-
p.line_spacing = 1.5
|
1615 |
-
# ์ผ์ชฝ ์ฌ๋ฐฑ ์ค์
|
1616 |
-
p.left_indent = Pt(0)
|
1617 |
-
|
1618 |
-
# ๋ถ๋ฆฟ ์์
|
1619 |
-
p.font.color.rgb = theme["text_color"]
|
1620 |
-
|
1621 |
-
# ์ฐ์ธก ๏ฟฝ๏ฟฝ๋ฏธ์ง ์ถ๊ฐ (๋ฐฐ๊ฒฝ ๋ฐ์ค ์ ๊ฑฐ)
|
1622 |
-
if slide_data.get('image'):
|
1623 |
-
try:
|
1624 |
-
img_buffer = BytesIO()
|
1625 |
-
slide_data['image'].save(img_buffer, format='PNG')
|
1626 |
-
img_buffer.seek(0)
|
1627 |
-
|
1628 |
-
pic = slide.shapes.add_picture(
|
1629 |
-
img_buffer,
|
1630 |
-
Inches(8.5), Inches(1.6),
|
1631 |
-
width=Inches(6.8), height=Inches(6.4)
|
1632 |
-
)
|
1633 |
-
|
1634 |
-
# ์ด๋ฏธ์ง ํ
๋๋ฆฌ ์ ๊ฑฐ
|
1635 |
-
pic.line.fill.background()
|
1636 |
-
|
1637 |
-
except Exception as e:
|
1638 |
-
print(f"[PPTX] ์ด๋ฏธ์ง ์ถ๊ฐ ์คํจ: {str(e)}")
|
1639 |
-
|
1640 |
-
# ํ์ด์ง ๋ฒํธ ์ถ๊ฐ
|
1641 |
-
page_num = slide.shapes.add_textbox(
|
1642 |
-
Inches(15), Inches(8.5),
|
1643 |
-
Inches(1), Inches(0.5)
|
1644 |
-
)
|
1645 |
-
page_frame = page_num.text_frame
|
1646 |
-
page_frame.text = str(i + 1)
|
1647 |
-
page_para = page_frame.paragraphs[0]
|
1648 |
-
page_para.font.size = Pt(12)
|
1649 |
-
page_para.font.color.rgb = theme["text_color"]
|
1650 |
-
page_para.alignment = PP_ALIGN.RIGHT
|
1651 |
-
|
1652 |
-
# ๋ฐํ์ ๋
ธํธ ์ถ๊ฐ
|
1653 |
-
notes_slide = slide.notes_slide
|
1654 |
-
notes_slide.notes_text_frame.text = slide_data.get('speaker_notes', '')
|
1655 |
-
|
1656 |
-
# ํ์ผ ์ ์ฅ
|
1657 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
1658 |
-
filename = f"presentation_{timestamp}.pptx"
|
1659 |
-
filepath = os.path.join("/tmp", filename)
|
1660 |
-
prs.save(filepath)
|
1661 |
-
|
1662 |
-
print(f"[PPTX] ํ์ผ ์์ฑ ์๋ฃ: {filename}")
|
1663 |
-
return filepath
|
1664 |
-
|
1665 |
-
def generate_dynamic_slides(topic: str, template: Dict, slide_count: int) -> List[Dict]:
|
1666 |
-
"""์ ํ๋ ์ฌ๋ผ์ด๋ ์์ ๋ฐ๋ผ ๋์ ์ผ๋ก ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ"""
|
1667 |
-
core_slides = template.get("core_slides", [])
|
1668 |
-
optional_slides = template.get("optional_slides", [])
|
1669 |
-
|
1670 |
-
# ํ์ง์ Thank You๋ฅผ ์ ์ธํ ๋ณธ๋ฌธ ์ฌ๋ผ์ด๋ ์
|
1671 |
-
content_slide_count = slide_count
|
1672 |
-
|
1673 |
-
# ์ฝ์ด ์ฌ๋ผ์ด๋๊ฐ ์์ฒญ๋ ์๋ณด๋ค ๋ง์ผ๋ฉด ์กฐ์
|
1674 |
-
if len(core_slides) > content_slide_count:
|
1675 |
-
selected_slides = core_slides[:content_slide_count]
|
1676 |
-
else:
|
1677 |
-
# ์ฝ์ด ์ฌ๋ผ์ด๋ + ์ต์
๋ ์ฌ๋ผ์ด๋์์ ์ ํ
|
1678 |
-
selected_slides = core_slides.copy()
|
1679 |
-
remaining = content_slide_count - len(core_slides)
|
1680 |
-
|
1681 |
-
if remaining > 0 and optional_slides:
|
1682 |
-
# ์ต์
๋ ์ฌ๋ผ์ด๋์์ ์ถ๊ฐ ์ ํ
|
1683 |
-
additional = optional_slides[:remaining]
|
1684 |
-
selected_slides.extend(additional)
|
1685 |
-
|
1686 |
-
# ํ์ง ์ถ๊ฐ (๋งจ ์)
|
1687 |
-
slides = [{"title": "ํ์ง", "style": "Title Slide (Hero)", "prompt_hint": "ํ๋ ์ ํ
์ด์
ํ์ง"}]
|
1688 |
-
|
1689 |
-
# ๋ณธ๋ฌธ ์ฌ๋ผ์ด๋ ์ถ๊ฐ
|
1690 |
-
slides.extend(selected_slides)
|
1691 |
-
|
1692 |
-
# Thank You ์ฌ๋ผ์ด๋ ์ถ๊ฐ (๋งจ ๋ค)
|
1693 |
-
slides.append({"title": "Thank You", "style": "Thank You Slide", "prompt_hint": "ํ๋ ์ ํ
์ด์
๋ง๋ฌด๋ฆฌ์ ํต์ฌ ๋ฉ์์ง"})
|
1694 |
-
|
1695 |
-
return slides
|
1696 |
-
|
1697 |
-
def create_custom_slides_ui(initial_count=5):
|
1698 |
-
"""์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ UI (3-20์ฅ)"""
|
1699 |
-
slides = []
|
1700 |
-
for i in range(20): # ์ต๋ 20์ฅ
|
1701 |
-
row = gr.Row(visible=(i < initial_count)) # Row๋ฅผ ๋ณ์์ ํ ๋น
|
1702 |
-
with row:
|
1703 |
-
with gr.Column(scale=2):
|
1704 |
-
title = gr.Textbox(
|
1705 |
-
label=f"์ฌ๋ผ์ด๋ {i+1} ์ ๋ชฉ",
|
1706 |
-
placeholder="์: ํํฉ ๋ถ์, ์๋ฃจ์
, ๋ก๋๋งต...",
|
1707 |
-
)
|
1708 |
-
with gr.Column(scale=3):
|
1709 |
-
style = gr.Dropdown(
|
1710 |
-
choices=list(STYLE_TEMPLATES.keys()),
|
1711 |
-
label=f"์คํ์ผ ์ ํ",
|
1712 |
-
value="Colorful Mind Map"
|
1713 |
-
)
|
1714 |
-
with gr.Column(scale=3):
|
1715 |
-
hint = gr.Textbox(
|
1716 |
-
label=f"ํ๋กฌํํธ ํํธ",
|
1717 |
-
placeholder="์ด ์ฌ๋ผ์ด๋์์ ํํํ๊ณ ์ถ์ ๋ด์ฉ"
|
1718 |
-
)
|
1719 |
-
slides.append({"title": title, "style": style, "hint": hint, "row": row})
|
1720 |
-
return slides
|
1721 |
-
|
1722 |
-
def generate_ppt_with_content(topic: str, template_name: str, audience_type: str, custom_slides: List[Dict],
|
1723 |
-
slide_count: int, seed: int, uploaded_file,
|
1724 |
-
use_web_search: bool, theme_name: str = "๋ฏธ๋๋ฉ ๋ผ์ดํธ",
|
1725 |
-
progress=gr.Progress()):
|
1726 |
-
"""PPT ์ด๋ฏธ์ง์ ํ
์คํธ ๋ด์ฉ์ ํจ๊ป ์์ฑ (๋ฐํ์ ๋
ธํธ ํฌํจ)"""
|
1727 |
-
results = []
|
1728 |
-
preview_html = ""
|
1729 |
-
|
1730 |
-
# ์ ์ญ ๋ณ์ ์
๋ฐ์ดํธ
|
1731 |
-
global current_topic, uploaded_content
|
1732 |
-
current_topic = topic
|
1733 |
-
|
1734 |
-
# ์
๋ก๋๋ ํ์ผ ๋ด์ฉ ์ฝ๊ธฐ
|
1735 |
-
uploaded_content = ""
|
1736 |
-
if uploaded_file is not None:
|
1737 |
try:
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
print(f"[ํ์ผ ์
๋ก๋] ์ค๋ฅ: {str(e)}")
|
1742 |
-
uploaded_content = ""
|
1743 |
-
|
1744 |
-
# ํ
ํ๋ฆฟ ์ ํ ๋ฐ ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ
|
1745 |
-
if template_name == "์ฌ์ฉ์ ์ ์" and custom_slides:
|
1746 |
-
slides = [{"title": "ํ์ง", "style": "Title Slide (Hero)", "prompt_hint": "ํ๋ ์ ํ
์ด์
ํ์ง"}]
|
1747 |
-
slides.extend(custom_slides)
|
1748 |
-
slides.append({"title": "Thank You", "style": "Thank You Slide", "prompt_hint": "ํ๋ ์ ํ
์ด์
๋ง๋ฌด๋ฆฌ์ ํต์ฌ ๋ฉ์์ง"})
|
1749 |
-
else:
|
1750 |
-
template = PPT_TEMPLATES[template_name]
|
1751 |
-
slides = generate_dynamic_slides(topic, template, slide_count)
|
1752 |
-
|
1753 |
-
if not slides:
|
1754 |
-
yield "", "์ฌ๋ผ์ด๋๊ฐ ์ ์๋์ง ์์์ต๋๋ค.", None
|
1755 |
-
return
|
1756 |
-
|
1757 |
-
total_slides = len(slides)
|
1758 |
-
print(f"\n[PPT ์์ฑ] ์์ - ์ด {total_slides}๊ฐ ์ฌ๋ผ์ด๋ (ํ์ง + ๋ณธ๋ฌธ {slide_count} + Thank You)")
|
1759 |
-
print(f"[PPT ์์ฑ] ์ฃผ์ : {topic}")
|
1760 |
-
print(f"[PPT ์์ฑ] ํ
ํ๋ฆฟ: {template_name}")
|
1761 |
-
print(f"[PPT ์์ฑ] ์ค๋์ธ์ค: {audience_type}")
|
1762 |
-
print(f"[PPT ์์ฑ] ๋์์ธ ํ
๋ง: {theme_name}")
|
1763 |
-
print(f"[PPT ์์ฑ] ์น ๊ฒ์: {'์ฌ์ฉ' if use_web_search else '๋ฏธ์ฌ์ฉ'}")
|
1764 |
-
|
1765 |
-
# ์น ๊ฒ์ ์คํ (์ ํ๋ ๊ฒฝ์ฐ)
|
1766 |
-
web_search_results = []
|
1767 |
-
if use_web_search and BRAVE_API_TOKEN:
|
1768 |
-
progress(0.05, "์น ๊ฒ์ ์ค...")
|
1769 |
-
web_search_results = brave_search(topic)
|
1770 |
-
|
1771 |
-
# CSS ์คํ์ผ ์ถ๊ฐ
|
1772 |
-
preview_html = """
|
1773 |
-
<style>
|
1774 |
-
.slides-container {
|
1775 |
-
width: 100%;
|
1776 |
-
max-width: 1400px;
|
1777 |
-
margin: 0 auto;
|
1778 |
-
}
|
1779 |
-
</style>
|
1780 |
-
<div class="slides-container">
|
1781 |
-
"""
|
1782 |
-
|
1783 |
-
# ๊ฐ ์ฌ๋ผ์ด๋ ์์ฐจ ์ฒ๋ฆฌ
|
1784 |
-
for i, slide in enumerate(slides):
|
1785 |
-
progress((i + 1) / (total_slides + 1), f"์ฌ๋ผ์ด๋ {i+1}/{total_slides} ์ฒ๋ฆฌ ์ค...")
|
1786 |
-
|
1787 |
-
slide_info = f"์ฌ๋ผ์ด๋ {i+1}: {slide['title']}"
|
1788 |
-
|
1789 |
-
# ํ
์คํธ ๋ด์ฉ ์์ฑ
|
1790 |
-
slide_context = f"{slide['title']} - {slide.get('prompt_hint', '')}"
|
1791 |
-
|
1792 |
-
# Thank You ์ฌ๋ผ์ด๋๋ ๊ฒฐ๋ก ๋ฌธ๊ตฌ ์์ฑ
|
1793 |
-
if slide['title'] == 'Thank You':
|
1794 |
-
conclusion_phrase = generate_conclusion_phrase(topic, audience_type)
|
1795 |
-
content = {
|
1796 |
-
"subtitle": conclusion_phrase,
|
1797 |
-
"bullet_points": []
|
1798 |
-
}
|
1799 |
-
# Thank You ์ฌ๋ผ์ด๋์ฉ ํน๋ณ ๋
ธํธ
|
1800 |
-
speaker_notes = generate_closing_notes(topic, conclusion_phrase, audience_type)
|
1801 |
-
else:
|
1802 |
-
content = generate_slide_content(
|
1803 |
-
topic, slide['title'], slide_context, audience_type,
|
1804 |
-
uploaded_content, web_search_results
|
1805 |
-
)
|
1806 |
-
# ์ผ๋ฐ ์ฌ๋ผ์ด๋ ๋ฐํ์ ๋
ธํธ
|
1807 |
-
speaker_notes = generate_presentation_notes(topic, slide['title'], content, audience_type)
|
1808 |
-
|
1809 |
-
# ํ๋กฌํํธ ์์ฑ ๋ฐ ์ด๋ฏธ์ง ์์ฑ
|
1810 |
-
style_key = slide["style"]
|
1811 |
-
if style_key in STYLE_TEMPLATES:
|
1812 |
-
style_info = STYLE_TEMPLATES[style_key]
|
1813 |
-
prompt = generate_prompt_with_llm(
|
1814 |
-
topic, style_info["example"],
|
1815 |
-
slide_context, uploaded_content
|
1816 |
-
)
|
1817 |
|
1818 |
-
# ์ด๋ฏธ์ง ์์ฑ (ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์ง์ ํฌํจ)
|
1819 |
-
slide_seed = seed + i
|
1820 |
-
img, used_prompt = generate_image(prompt, slide_seed, slide_info)
|
1821 |
-
|
1822 |
-
# ์ฌ๋ผ์ด๋ ๋ฐ์ดํฐ ๊ตฌ์ฑ
|
1823 |
-
slide_data = {
|
1824 |
-
"slide_number": i + 1,
|
1825 |
-
"title": slide["title"],
|
1826 |
-
"subtitle": content["subtitle"],
|
1827 |
-
"bullet_points": content["bullet_points"],
|
1828 |
-
"image": img,
|
1829 |
-
"style": style_info["name"],
|
1830 |
-
"speaker_notes": speaker_notes,
|
1831 |
-
"topic": topic # ํ์ง์ฉ
|
1832 |
-
}
|
1833 |
-
|
1834 |
-
# ํ๋ฆฌ๋ทฐ HTML ์์ฑ (ํธ์ง ๊ธฐ๋ฅ ์ ๊ฑฐ)
|
1835 |
-
preview_html += create_slide_preview_html(slide_data)
|
1836 |
-
|
1837 |
-
# ํ์ฌ๊น์ง์ ์ํ ์
๋ฐ์ดํธ
|
1838 |
-
yield preview_html + "</div>", f"### ๐ {slide_info} ์์ฑ ์ค...", None
|
1839 |
-
|
1840 |
-
results.append({
|
1841 |
-
"slide_data": slide_data,
|
1842 |
-
"success": img is not None
|
1843 |
-
})
|
1844 |
-
|
1845 |
-
# PPTX ํ์ผ ์์ฑ
|
1846 |
-
progress(0.95, "PPTX ํ์ผ ์์ฑ ์ค...")
|
1847 |
-
pptx_path = None
|
1848 |
-
try:
|
1849 |
-
pptx_path = create_pptx_file(results, topic, template_name, theme_name)
|
1850 |
except Exception as e:
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
progress(1.0, "์๋ฃ!")
|
1855 |
-
successful = sum(1 for r in results if r["success"])
|
1856 |
-
final_status = f"### ๐ ์์ฑ ์๋ฃ! ์ด {total_slides}๊ฐ ์ฌ๋ผ์ด๋ ์ค {successful}๊ฐ ์ฑ๊ณต"
|
1857 |
-
|
1858 |
-
# ์ ์ญ ๋ณ์ ์ ์ฅ
|
1859 |
-
global current_slides_data, current_template, current_theme
|
1860 |
-
current_slides_data = results
|
1861 |
-
current_template = template_name
|
1862 |
-
current_theme = theme_name
|
1863 |
-
|
1864 |
-
if pptx_path:
|
1865 |
-
final_status += f"\n\n### ๐ฅ PPTX ํ์ผ์ด ์ค๋น๋์์ต๋๋ค!"
|
1866 |
-
final_status += f"\n\n๐ค **{audience_type}๋ฅผ ์ํ ๋ฐํ์ ๋
ธํธ๊ฐ ๊ฐ ์ฌ๋ผ์ด๋์ ํฌํจ๋์ด ์์ต๋๋ค!**"
|
1867 |
-
if PROCESS_FLOW_AVAILABLE:
|
1868 |
-
final_status += f"\n\n๐ง **ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ์ด ์๋์ผ๋ก ์์ฑ๋ฉ๋๋ค (ํ๊ธ ์ง์)**"
|
1869 |
-
|
1870 |
-
yield preview_html, final_status, pptx_path
|
1871 |
-
|
1872 |
-
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
1873 |
-
with gr.Blocks(title="PPT ์ด๋ฏธ์ง ์์ฑ๊ธฐ", theme=gr.themes.Soft(), css="""
|
1874 |
-
.preview-container { max-width: 1400px; margin: 0 auto; }
|
1875 |
-
.slide-container { transition: all 0.3s ease; }
|
1876 |
-
.slide-container:hover { transform: translateY(-2px); box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15) !important; }
|
1877 |
-
#custom_accordion .form {
|
1878 |
-
max-height: 600px;
|
1879 |
-
overflow-y: auto;
|
1880 |
-
padding-right: 10px;
|
1881 |
-
}
|
1882 |
-
#custom_accordion .form::-webkit-scrollbar {
|
1883 |
-
width: 6px;
|
1884 |
-
}
|
1885 |
-
#custom_accordion .form::-webkit-scrollbar-track {
|
1886 |
-
background: #f1f1f1;
|
1887 |
-
border-radius: 3px;
|
1888 |
-
}
|
1889 |
-
#custom_accordion .form::-webkit-scrollbar-thumb {
|
1890 |
-
background: #888;
|
1891 |
-
border-radius: 3px;
|
1892 |
-
}
|
1893 |
-
#custom_accordion .form::-webkit-scrollbar-thumb:hover {
|
1894 |
-
background: #555;
|
1895 |
-
}
|
1896 |
-
""") as demo:
|
1897 |
-
gr.Markdown("""
|
1898 |
-
# ๐ฏ AI ๊ธฐ๋ฐ PPT ํตํฉ ์์ฑ๊ธฐ (๊ฐ๊ฒฐํ ์คํ์ผ ๋ฒ์ )
|
1899 |
-
|
1900 |
-
### ํ
์คํธ์ ์ด๋ฏธ์ง๊ฐ ์๋ฒฝํ๊ฒ ์กฐํ๋ ํ๋ ์ ํ
์ด์
์ ์๋์ผ๋ก ์์ฑํ์ธ์!
|
1901 |
-
|
1902 |
-
#### ๐ ์๋ก์ด ๊ธฐ๋ฅ:
|
1903 |
-
- ๐ญ **์ค๋์ธ์ค๋ณ ์ต์ ํ**: ๋ฐํ ๋์์ ๋ง์ถ ๋ด์ฉ๊ณผ ํค ์๋ ์กฐ์
|
1904 |
-
- ๐ **๊ฐ๊ฒฐํ ๋ช
์ฌํ ํ
์คํธ**: "~์", "~ํจ" ์คํ์ผ์ ํ๋กํ์
๋ํ ๋ฌธ์ฒด
|
1905 |
-
- ๐จ **์ด๋ชจ์ง ์๋ ์ถ๊ฐ**: ๊ฐ ํฌ์ธํธ๋ณ ์ ์ ํ ์ด๋ชจ์ง๋ก ์๊ฐ์ ๊ตฌ๋ถ
|
1906 |
-
- ๐ **์์ ํ
ํ๋ฆฟ**: ๋ฒํผ ํด๋ฆญ์ผ๋ก ์์ ์ฃผ์ ๋ถ๋ฌ์ค๊ธฐ
|
1907 |
-
- ๐จ **๋์์ธ ํ
๋ง**: 5๊ฐ์ง ์ ๋ฌธ์ ์ธ ๋์์ธ ํ
๋ง ์ ํ ๊ฐ๋ฅ
|
1908 |
-
- ๐ **๊ฐ์ ๋ ์ฌ๋ผ์ด๋ ๋์์ธ**: ๋ ํฌ๋ช
ํ ๋ฐฐ๊ฒฝ๊ณผ ๊น๋ํ ๋ ์ด์์
|
1909 |
-
- ๐ **ํ์ง์ Thank You ์ฌ๋ผ์ด๋** ์๋ ์ถ๊ฐ
|
1910 |
-
- ๐ค **์ค๋์ธ์ค๋ณ ๋ฐํ์ ๋
ธํธ** ์๋ ์์ฑ (๊ตฌ์ด์ฒด)
|
1911 |
-
- ๐ **ํ์ผ ์
๋ก๋** ์ง์ (PDF/CSV/TXT)
|
1912 |
-
- ๐ **์น ๊ฒ์** ๊ธฐ๋ฅ (Brave Search)
|
1913 |
-
- ๐๏ธ **์ฌ๋ผ์ด๋ ์ ์กฐ์ ** (6-20์ฅ)
|
1914 |
-
- ๐ง **ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ** ์๋ ์์ฑ (ํ๊ธ ์ง์)
|
1915 |
-
- ๐ฏ **์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋**: 3-20์ฅ์ ์์ ๋กญ๊ฒ ๊ตฌ์ฑํ์ฌ ๋๋ง์ ํ๋ ์ ํ
์ด์
์ ์
|
1916 |
-
""")
|
1917 |
-
|
1918 |
-
# API ํ ํฐ ์ํ ํ์ธ
|
1919 |
-
token_status = []
|
1920 |
-
if not REPLICATE_API_TOKEN:
|
1921 |
-
token_status.append("โ ๏ธ RAPI_TOKEN ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
1922 |
-
if not FRIENDLI_TOKEN:
|
1923 |
-
token_status.append("โ ๏ธ FRIENDLI_TOKEN ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
1924 |
-
if not BRAVE_API_TOKEN:
|
1925 |
-
token_status.append("โน๏ธ BAPI_TOKEN์ด ์์ด ์น ๊ฒ์ ๊ธฐ๋ฅ์ด ๋นํ์ฑํ๋ฉ๋๋ค.")
|
1926 |
-
if not PROCESS_FLOW_AVAILABLE:
|
1927 |
-
token_status.append("โน๏ธ process_flow_generator๊ฐ ์์ด ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ์ด ๋นํ์ฑํ๋ฉ๋๋ค.")
|
1928 |
-
|
1929 |
-
if token_status:
|
1930 |
-
gr.Markdown("\n".join(token_status))
|
1931 |
-
|
1932 |
-
with gr.Row():
|
1933 |
-
with gr.Column(scale=1):
|
1934 |
-
# ์์ ์ ํ
|
1935 |
-
with gr.Row():
|
1936 |
-
example_btn = gr.Button("๐ ์์ ๋ถ๋ฌ์ค๊ธฐ", size="sm", variant="secondary")
|
1937 |
-
|
1938 |
-
# ๊ธฐ๋ณธ ์
๋ ฅ
|
1939 |
-
topic_input = gr.Textbox(
|
1940 |
-
label="ํ๋ ์ ํ
์ด์
์ฃผ์ ",
|
1941 |
-
placeholder="์: AI ์คํํธ์
ํฌ์ ์ ์น, ์ ์ ํ ๋ฐ์นญ, ๋์งํธ ์ ํ ์ ๋ต",
|
1942 |
-
lines=2
|
1943 |
-
)
|
1944 |
-
|
1945 |
-
# ์ค๋์ธ์ค ์ ํ (์๋ก ์ถ๊ฐ)
|
1946 |
-
audience_select = gr.Dropdown(
|
1947 |
-
choices=list(AUDIENCE_TYPES.keys()),
|
1948 |
-
label="๐ญ ๋ฐํ ๋์ ์ค๋์ธ์ค",
|
1949 |
-
value="์ผ๋ฐ ์ง์",
|
1950 |
-
info="๋ฐํ ๋์์ ๋ฐ๋ผ ๋ด์ฉ๊ณผ ํค์ด ์๋์ผ๋ก ์ต์ ํ๋ฉ๋๋ค"
|
1951 |
-
)
|
1952 |
-
|
1953 |
-
# ์ค๋์ธ์ค ์ค๋ช
ํ์
|
1954 |
-
audience_info = gr.Markdown()
|
1955 |
-
|
1956 |
-
# PPT ํ
ํ๋ฆฟ ์ ํ
|
1957 |
-
template_select = gr.Dropdown(
|
1958 |
-
choices=list(PPT_TEMPLATES.keys()),
|
1959 |
-
label="PPT ํ
ํ๋ฆฟ ์ ํ",
|
1960 |
-
value="๋น์ฆ๋์ค ์ ์์",
|
1961 |
-
info="๋ชฉ์ ์ ๋ง๋ ํ
ํ๋ฆฟ์ ์ ํํ์ธ์"
|
1962 |
-
)
|
1963 |
-
|
1964 |
-
# ๋์์ธ ํ
๋ง ์ ํ
|
1965 |
-
theme_select = gr.Dropdown(
|
1966 |
-
choices=list(DESIGN_THEMES.keys()),
|
1967 |
-
label="๋์์ธ ํ
๋ง ์ ํ",
|
1968 |
-
value="๋ฏธ๋๋ฉ ๋ผ์ดํธ",
|
1969 |
-
info="ํ๋ ์ ํ
์ด์
์ ์ ์ฒด์ ์ธ ๋์์ธ ์คํ์ผ"
|
1970 |
-
)
|
1971 |
-
|
1972 |
-
# ํ
๋ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
1973 |
-
theme_preview = gr.HTML()
|
1974 |
-
|
1975 |
-
# ์ฌ๋ผ์ด๋ ์ ์ ํ
|
1976 |
-
slide_count = gr.Slider(
|
1977 |
-
minimum=6,
|
1978 |
-
maximum=20,
|
1979 |
-
value=8,
|
1980 |
-
step=1,
|
1981 |
-
label="๋ณธ๋ฌธ ์ฌ๋ผ์ด๋ ์ (ํ์ง์ Thank You ์ ์ธ)",
|
1982 |
-
info="์์ฑํ ๋ณธ๋ฌธ ์ฌ๋ผ์ด๋ ์๋ฅผ ์ ํํ์ธ์ (์ฌ์ฉ์ ์ ์ ํ
ํ๋ฆฟ์์๋ ์ฌ์ฉ๋์ง ์์)"
|
1983 |
-
)
|
1984 |
-
|
1985 |
-
# ํ์ผ ์
๋ก๋
|
1986 |
-
file_upload = gr.File(
|
1987 |
-
label="์ฐธ๊ณ ์๋ฃ ์
๋ก๋ (์ ํ)",
|
1988 |
-
file_types=[".pdf", ".csv", ".txt"],
|
1989 |
-
type="filepath",
|
1990 |
-
value=None
|
1991 |
-
)
|
1992 |
-
|
1993 |
-
# ์น ๊ฒ์ ์ต์
|
1994 |
-
use_web_search = gr.Checkbox(
|
1995 |
-
label="์น ๊ฒ์ ์ฌ์ฉ",
|
1996 |
-
value=False,
|
1997 |
-
info="Brave Search๋ฅผ ์ฌ์ฉํ์ฌ ์ต์ ์ ๋ณด ๋ฐ์"
|
1998 |
-
)
|
1999 |
-
|
2000 |
-
# ํ
ํ๋ฆฟ ์ค๋ช
|
2001 |
-
template_info = gr.Markdown()
|
2002 |
-
|
2003 |
-
# ์๋ ๊ฐ
|
2004 |
-
seed_input = gr.Slider(
|
2005 |
-
minimum=1,
|
2006 |
-
maximum=100,
|
2007 |
-
value=10,
|
2008 |
-
step=1,
|
2009 |
-
label="์๋ ๊ฐ"
|
2010 |
-
)
|
2011 |
-
|
2012 |
-
generate_btn = gr.Button("๐ PPT ์์ฑ ์์ (AI๊ฐ ๋ชจ๋ ๋ด์ฉ์ ์๋ ์์ฑ)", variant="primary", size="lg")
|
2013 |
-
|
2014 |
-
# ์ฌ์ฉ ๋ฐฉ๋ฒ ์๋ด
|
2015 |
-
with gr.Accordion("๐ ์ฌ์ฉ ๋ฐฉ๋ฒ", open=False):
|
2016 |
-
gr.Markdown("""
|
2017 |
-
### ๐ ์์
์์:
|
2018 |
-
1. **์์ ๋ถ๋ฌ์ค๊ธฐ** ๋ฒํผ์ผ๋ก ์ํ ์ฃผ์ ๋ฅผ ๋ก๋ํ๊ฑฐ๋ ์ง์ ์
๋ ฅ
|
2019 |
-
2. **์ค๋์ธ์ค ์ ํ**: ๋ฐํ ๋์์ ๋ฐ๋ผ ๋ด์ฉ์ด ์๋์ผ๋ก ์ต์ ํ๋ฉ๋๋ค
|
2020 |
-
3. **ํ
ํ๋ฆฟ๊ณผ ํ
๋ง ์ ํ** ํ ์์ฑ ๋ฒํผ ํด๋ฆญ
|
2021 |
-
4. **๋ค์ด๋ก๋**: ์์ฑ ์๋ฃ ํ PPTX ํ์ผ ๋ค์ด๋ก๋
|
2022 |
-
|
2023 |
-
### ๐ญ ์ค๋์ธ์ค๋ณ ํน์ง:
|
2024 |
-
- **๊ฒฝ์์ง/์์**: ์ ๋ต์ ๊ฐ์น, ROI, ๋น์ฆ๋์ค ์ํฉํธ ์ค์ฌ
|
2025 |
-
- **ํฌ์์**: ์์ฅ ๊ธฐํ, ์ฑ์ฅ ๊ฐ๋ฅ์ฑ, ์์ต์ฑ ๊ฐ์กฐ
|
2026 |
-
- **๊ธฐ์ ํ**: ๊ธฐ์ ์ ์ธ๋ถ์ฌํญ, ๊ตฌํ ๋ฐฉ๋ฒ, ์ฑ๋ฅ ์งํ
|
2027 |
-
- **์ผ๋ฐ ์ง์**: ์ค๋ฌด์ ๋ด์ฉ, ํ์
๋ฐฉ์, ์คํ ๊ณํ
|
2028 |
-
- **๊ณ ๊ฐ/ํํธ๋**: ๊ณ ๊ฐ ๊ฐ์น, ํํ, ์ฑ๊ณต ์ฌ๋ก
|
2029 |
-
- **์ผ๋ฐ ๋์ค**: ์ฌ์ด ์ค๋ช
, ์ฌ์ฉ ํธ์์ฑ, ์ค์ง์ ์ด์
|
2030 |
-
|
2031 |
-
### ๐ก ํ
์คํธ ์คํ์ผ ํน์ง:
|
2032 |
-
- **๊ฐ๊ฒฐํ ๋ช
์ฌํ ์ข
๊ฒฐ**: "~์", "~ํจ" ๋๋ ๋ช
์ฌ๋ก ๋๋จ
|
2033 |
-
- **์ด๋ชจ์ง ํ์ฉ**: ๊ฐ ํฌ์ธํธ ์์ ๋ด์ฉ ๊ด๋ จ ์ด๋ชจ์ง ์๋ ์ถ๊ฐ
|
2034 |
-
- **8-12๋จ์ด**: ๊ฐ ๋ถ๋ฆฟ ํฌ์ธํธ๋ ๋งค์ฐ ๊ฐ๊ฒฐํ๊ฒ ๊ตฌ์ฑ
|
2035 |
-
|
2036 |
-
### ๐ ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋:
|
2037 |
-
- **ํ
ํ๋ฆฟ ๋์ ์ง์ ๊ตฌ์ฑ**: "์ฌ์ฉ์ ์ ์" ํ
ํ๋ฆฟ ์ ํ ์ ํ์ฑํ
|
2038 |
-
- **3-20์ฅ ์์ ๋กญ๊ฒ ๊ตฌ์ฑ**: ์ฌ๋ผ์ด๋๋ก ์ํ๋ ์ฌ๋ผ์ด๋ ์ ์ ํ
|
2039 |
-
- **๊ฐ ์ฌ๋ผ์ด๋๋ณ ์คํ์ผ ์ง์ **: 16๊ฐ์ง ์คํ์ผ ์ค ์ ํ
|
2040 |
-
- **ํํธ ์ ๊ณต**: ๊ฐ ์ฌ๋ผ์ด๋์ ๋ด์ฉ ๋ฐฉํฅ์ ํ๋กฌํํธ ํํธ๋ก ์ง์
|
2041 |
-
|
2042 |
-
### ๐ง ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ:
|
2043 |
-
- **Business Workflow** ๋๋ **Flowchart** ์คํ์ผ ์ ํ ์ ์๋์ผ๋ก ํ๋ก์ธ์ค ํ๋ก์ฐ ๋ค์ด์ด๊ทธ๋จ ์์ฑ
|
2044 |
-
- ํ๊ธ ํ
์คํธ๋ฅผ ์๋ฒฝํ๊ฒ ์ง์ํ๋ ๋ค์ด์ด๊ทธ๋จ
|
2045 |
-
- ํ๋ก์ธ์ค, ์์ฌ๊ฒฐ์ , ์
์ถ๋ ฅ ๋ฑ ๋ค์ํ ๋
ธ๋ ํ์
์ง์
|
2046 |
-
""")
|
2047 |
-
|
2048 |
-
# PPTX ๋ค์ด๋ก๋ ์์ญ
|
2049 |
-
with gr.Row():
|
2050 |
-
download_file = gr.File(
|
2051 |
-
label="๐ฅ ์์ฑ๋ PPTX ํ์ผ ๋ค์ด๋ก๋",
|
2052 |
-
visible=True,
|
2053 |
-
elem_id="download-file"
|
2054 |
-
)
|
2055 |
-
|
2056 |
-
# ์ฌ์ฉ์ ์ ์ ์น์
|
2057 |
-
with gr.Accordion("๐ ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ", open=False, elem_id="custom_accordion") as custom_accordion:
|
2058 |
-
gr.Markdown("ํ
ํ๋ฆฟ์ ์ฌ์ฉํ์ง ์๊ณ ์ง์ ์ฌ๋ผ์ด๋๋ฅผ ๊ตฌ์ฑํ์ธ์. (3-20์ฅ)")
|
2059 |
-
|
2060 |
-
# ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์ ์ ํ
|
2061 |
-
custom_slide_count = gr.Slider(
|
2062 |
-
minimum=3,
|
2063 |
-
maximum=20,
|
2064 |
-
value=5,
|
2065 |
-
step=1,
|
2066 |
-
label="์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์",
|
2067 |
-
info="์์ฑํ ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์๋ฅผ ์ ํํ์ธ์"
|
2068 |
-
)
|
2069 |
-
|
2070 |
-
custom_slides_components = create_custom_slides_ui(initial_count=5)
|
2071 |
-
|
2072 |
-
# ์ํ ํ์
|
2073 |
-
status_output = gr.Markdown(
|
2074 |
-
value="### ๐ ํ
ํ๋ฆฟ์ ์ ํํ๊ณ ์์ฑ ๋ฒํผ์ ํด๋ฆญํ์ธ์!"
|
2075 |
-
)
|
2076 |
-
|
2077 |
-
# ํ๋ฆฌ๋ทฐ ์์ญ
|
2078 |
-
preview_output = gr.HTML(
|
2079 |
-
label="PPT ํ๋ฆฌ๋ทฐ (16:9)",
|
2080 |
-
elem_classes="preview-container"
|
2081 |
-
)
|
2082 |
-
|
2083 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
2084 |
-
def load_example(template_name):
|
2085 |
-
"""ํ
ํ๋ฆฟ์ ๋ง๋ ์์ ์ฃผ์ ๋ก๋"""
|
2086 |
-
example_topic = EXAMPLE_TOPICS.get(template_name, "")
|
2087 |
-
return example_topic
|
2088 |
-
|
2089 |
-
def update_audience_info(audience_type):
|
2090 |
-
"""์ค๋์ธ์ค ์ ๋ณด ํ์"""
|
2091 |
-
info = AUDIENCE_TYPES.get(audience_type, {})
|
2092 |
-
return f"""**{info.get('description', '')}**
|
2093 |
-
- ํค: {info.get('tone', '')}
|
2094 |
-
- ํฌ์ปค์ค: {info.get('focus', '')}"""
|
2095 |
-
|
2096 |
-
def update_theme_preview(theme_name):
|
2097 |
-
"""ํ
๋ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ HTML ์์ฑ"""
|
2098 |
-
theme = DESIGN_THEMES.get(theme_name, DESIGN_THEMES["๋ฏธ๋๋ฉ ๋ผ์ดํธ"])
|
2099 |
-
|
2100 |
-
# RGB ๊ฐ์ hex๋ก ๋ณํ
|
2101 |
-
def rgb_to_hex(rgb_color):
|
2102 |
-
return f"#{rgb_color[0]:02x}{rgb_color[1]:02x}{rgb_color[2]:02x}"
|
2103 |
-
|
2104 |
-
bg_hex = rgb_to_hex(theme["background"])
|
2105 |
-
box_hex = rgb_to_hex(theme["box_fill"])
|
2106 |
-
title_hex = rgb_to_hex(theme["title_color"])
|
2107 |
-
text_hex = rgb_to_hex(theme["text_color"])
|
2108 |
-
accent_hex = rgb_to_hex(theme["accent_color"])
|
2109 |
-
|
2110 |
-
preview_html = f"""
|
2111 |
-
<div style="
|
2112 |
-
background: {bg_hex};
|
2113 |
-
padding: 20px;
|
2114 |
-
border-radius: 8px;
|
2115 |
-
margin: 10px 0;
|
2116 |
-
">
|
2117 |
-
<div style="
|
2118 |
-
background: {box_hex};
|
2119 |
-
opacity: {theme['box_opacity']};
|
2120 |
-
padding: 15px;
|
2121 |
-
border-radius: 12px;
|
2122 |
-
margin-bottom: 10px;
|
2123 |
-
{'box-shadow: 0 4px 8px rgba(0,0,0,0.1);' if theme['shadow'] else ''}
|
2124 |
-
">
|
2125 |
-
<h4 style="color: {title_hex}; margin: 0 0 10px 0;">{theme['name']}</h4>
|
2126 |
-
<p style="color: {text_hex}; margin: 0; font-size: 14px;">
|
2127 |
-
{theme['description']}
|
2128 |
-
</p>
|
2129 |
-
<div style="
|
2130 |
-
width: 40px;
|
2131 |
-
height: 4px;
|
2132 |
-
background: {accent_hex};
|
2133 |
-
margin-top: 10px;
|
2134 |
-
border-radius: 2px;
|
2135 |
-
"></div>
|
2136 |
-
</div>
|
2137 |
-
</div>
|
2138 |
-
"""
|
2139 |
-
return preview_html
|
2140 |
-
|
2141 |
-
def update_template_info(template_name, slide_count):
|
2142 |
-
is_custom = template_name == "์ฌ์ฉ์ ์ ์"
|
2143 |
-
info = ""
|
2144 |
-
|
2145 |
-
if not is_custom and template_name in PPT_TEMPLATES:
|
2146 |
-
template = PPT_TEMPLATES[template_name]
|
2147 |
-
info = f"**{template['description']}**\n\n"
|
2148 |
-
|
2149 |
-
# ๋์ ์ผ๋ก ์์ฑ๋ ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ ํ์
|
2150 |
-
slides = generate_dynamic_slides("", template, slide_count)
|
2151 |
-
info += f"์์ฑ๋ ์ฌ๋ผ์ด๋ ({len(slides)}์ฅ):\n"
|
2152 |
-
for i, slide in enumerate(slides):
|
2153 |
-
style_info = STYLE_TEMPLATES.get(slide['style'], {})
|
2154 |
-
info += f"{i+1}. {slide['title']} - {style_info.get('use_case', '')}"
|
2155 |
-
if style_info.get('is_process_flow'):
|
2156 |
-
info += " ๐ง"
|
2157 |
-
info += "\n"
|
2158 |
-
elif is_custom:
|
2159 |
-
info = "**์ฌ์ฉ์ ์ ์ ํ
ํ๋ฆฟ**\n\n์๋ '์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ๊ตฌ์ฑ' ์น์
์์ ์ง์ ์ฌ๋ผ์ด๋๋ฅผ ๊ตฌ์ฑํ์ธ์."
|
2160 |
-
|
2161 |
-
# ์ฌ์ฉ์ ์ ์ ํ
ํ๋ฆฟ์ผ ๋ ์ฌ๋ผ์ด๋ ์ ์ ํ ์จ๊ธฐ๊ธฐ
|
2162 |
-
slide_count_visible = not is_custom
|
2163 |
-
custom_accordion_open = is_custom
|
2164 |
-
|
2165 |
-
return info, gr.update(visible=slide_count_visible), gr.update(open=custom_accordion_open)
|
2166 |
-
|
2167 |
-
def update_custom_slides_visibility(count):
|
2168 |
-
"""์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์์ ๋ฐ๋ผ UI ํ์/์จ๊น"""
|
2169 |
-
updates = []
|
2170 |
-
for i in range(20):
|
2171 |
-
updates.append(gr.update(visible=(i < count))) # row
|
2172 |
-
return updates
|
2173 |
-
|
2174 |
-
def generate_ppt_handler(topic, template_name, audience_type, theme_name, slide_count, seed, file_upload,
|
2175 |
-
use_web_search, custom_slide_count, progress=gr.Progress(),
|
2176 |
-
*custom_inputs):
|
2177 |
-
if not topic.strip():
|
2178 |
-
yield "", "โ ์ฃผ์ ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.", None
|
2179 |
-
return
|
2180 |
-
|
2181 |
-
# ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์ฒ๋ฆฌ
|
2182 |
-
custom_slides = []
|
2183 |
-
if template_name == "์ฌ์ฉ์ ์ ์":
|
2184 |
-
for i in range(0, custom_slide_count * 3, 3):
|
2185 |
-
if i < len(custom_inputs):
|
2186 |
-
title = custom_inputs[i]
|
2187 |
-
style = custom_inputs[i+1] if i+1 < len(custom_inputs) else None
|
2188 |
-
hint = custom_inputs[i+2] if i+2 < len(custom_inputs) else ""
|
2189 |
-
|
2190 |
-
if title and style:
|
2191 |
-
custom_slides.append({
|
2192 |
-
"title": title,
|
2193 |
-
"style": style,
|
2194 |
-
"prompt_hint": hint
|
2195 |
-
})
|
2196 |
-
|
2197 |
-
# PPT ์์ฑ
|
2198 |
-
for preview, status, pptx_file in generate_ppt_with_content(
|
2199 |
-
topic, template_name, audience_type, custom_slides, slide_count, seed,
|
2200 |
-
file_upload, use_web_search, theme_name, progress
|
2201 |
-
):
|
2202 |
-
yield preview, status, pptx_file
|
2203 |
-
|
2204 |
-
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
2205 |
-
example_btn.click(
|
2206 |
-
fn=load_example,
|
2207 |
-
inputs=[template_select],
|
2208 |
-
outputs=[topic_input]
|
2209 |
-
)
|
2210 |
-
|
2211 |
-
audience_select.change(
|
2212 |
-
fn=update_audience_info,
|
2213 |
-
inputs=[audience_select],
|
2214 |
-
outputs=[audience_info]
|
2215 |
-
)
|
2216 |
-
|
2217 |
-
theme_select.change(
|
2218 |
-
fn=update_theme_preview,
|
2219 |
-
inputs=[theme_select],
|
2220 |
-
outputs=[theme_preview]
|
2221 |
-
)
|
2222 |
-
|
2223 |
-
template_select.change(
|
2224 |
-
fn=update_template_info,
|
2225 |
-
inputs=[template_select, slide_count],
|
2226 |
-
outputs=[template_info, slide_count, custom_accordion]
|
2227 |
-
)
|
2228 |
-
|
2229 |
-
slide_count.change(
|
2230 |
-
fn=lambda t, s: update_template_info(t, s)[0],
|
2231 |
-
inputs=[template_select, slide_count],
|
2232 |
-
outputs=[template_info]
|
2233 |
-
)
|
2234 |
-
|
2235 |
-
custom_slide_count.change(
|
2236 |
-
fn=update_custom_slides_visibility,
|
2237 |
-
inputs=[custom_slide_count],
|
2238 |
-
outputs=[slide["row"] for slide in custom_slides_components]
|
2239 |
-
)
|
2240 |
-
|
2241 |
-
# ์ฌ์ฉ์ ์ ์ ์ฌ๋ผ์ด๋ ์
๋ ฅ ์ปดํฌ๋ํธ ํํํ
|
2242 |
-
all_custom_inputs = []
|
2243 |
-
for slide in custom_slides_components:
|
2244 |
-
all_custom_inputs.extend([slide["title"], slide["style"], slide["hint"]])
|
2245 |
-
|
2246 |
-
generate_btn.click(
|
2247 |
-
fn=generate_ppt_handler,
|
2248 |
-
inputs=[
|
2249 |
-
topic_input, template_select, audience_select, theme_select, slide_count,
|
2250 |
-
seed_input, file_upload, use_web_search, custom_slide_count
|
2251 |
-
] + all_custom_inputs,
|
2252 |
-
outputs=[preview_output, status_output, download_file]
|
2253 |
-
)
|
2254 |
-
|
2255 |
-
# ์ด๊ธฐ ๋ก๋์ ํ
ํ๋ฆฟ/ํ
๋ง ์ ๋ณด ํ์
|
2256 |
-
demo.load(
|
2257 |
-
fn=lambda: (update_template_info(template_select.value, slide_count.value)[0],
|
2258 |
-
update_theme_preview(theme_select.value),
|
2259 |
-
update_audience_info(audience_select.value)),
|
2260 |
-
inputs=[],
|
2261 |
-
outputs=[template_info, theme_preview, audience_info]
|
2262 |
-
)
|
2263 |
|
2264 |
-
# ์ฑ ์คํ
|
2265 |
if __name__ == "__main__":
|
2266 |
-
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import sys
|
3 |
+
import streamlit as st
|
4 |
+
from tempfile import NamedTemporaryFile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
try:
|
8 |
+
# Get the code from secrets
|
9 |
+
code = os.environ.get("MAIN_CODE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
if not code:
|
12 |
+
st.error("โ ๏ธ The application code wasn't found in secrets. Please add the MAIN_CODE secret.")
|
13 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Create a temporary Python file
|
16 |
+
with NamedTemporaryFile(suffix='.py', delete=False, mode='w') as tmp:
|
17 |
+
tmp.write(code)
|
18 |
+
tmp_path = tmp.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
# Execute the code
|
21 |
+
exec(compile(code, tmp_path, 'exec'), globals())
|
|
|
22 |
|
23 |
+
# Clean up the temporary file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
try:
|
25 |
+
os.unlink(tmp_path)
|
26 |
+
except:
|
27 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
except Exception as e:
|
30 |
+
st.error(f"โ ๏ธ Error loading or executing the application: {str(e)}")
|
31 |
+
import traceback
|
32 |
+
st.code(traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
|
|
34 |
if __name__ == "__main__":
|
35 |
+
main()
|