mgbam commited on
Commit
e049e86
·
verified ·
1 Parent(s): c1da7c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +487 -438
app.py CHANGED
@@ -1,444 +1,493 @@
1
- import streamlit as st
2
  import json
3
- import zipfile
4
- import io
5
- import time
6
  import requests
7
- from agents import TopicAgent, ContentAgent, SlideAgent, CodeAgent, DesignAgent, VoiceoverAgent
8
-
9
- # Initialize agents
10
- topic_agent = TopicAgent()
11
- content_agent = ContentAgent()
12
- slide_agent = SlideAgent()
13
- code_agent = CodeAgent()
14
- design_agent = DesignAgent()
15
- voiceover_agent = VoiceoverAgent()
16
-
17
- # =====================
18
- # STREAMLIT APPLICATION
19
- # =====================
20
-
21
- st.set_page_config(
22
- page_title="Workshop in a Box Pro",
23
- layout="wide",
24
- page_icon="🎓"
25
- )
26
-
27
- # Custom CSS for permanent visibility
28
- st.markdown("""
29
- <style>
30
- /* Permanent visibility styles */
31
- .workshop-container {
32
- background: rgba(255, 255, 255, 0.05);
33
- border-radius: 10px;
34
- padding: 25px;
35
- margin-bottom: 20px;
36
- border: 1px solid #0d8bf2;
37
- box-shadow: 0 4px 20px rgba(0,0,0,0.25);
38
- }
39
-
40
- .section-header {
41
- border-left: 4px solid #0d8bf2;
42
- padding-left: 15px;
43
- margin-top: 10px;
44
- margin-bottom: 20px;
45
- }
46
-
47
- .executive-summary {
48
- background: linear-gradient(to right, #1a2980, #26d0ce);
49
- padding: 25px;
50
- border-radius: 15px;
51
- margin-bottom: 25px;
52
- box-shadow: 0 10px 20px rgba(0,0,0,0.2);
53
- }
54
-
55
- /* Override expander styles */
56
- .stApp {
57
- background: linear-gradient(135deg, #0f2027 0%, #203a43 100%);
58
- color: #fff;
59
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
60
- }
61
-
62
- .stTextInput>div>div>input {
63
- background-color: rgba(255,255,255,0.1) !important;
64
- color: white !important;
65
- border: 1px solid #4CAF50;
66
- border-radius: 8px;
67
- }
68
-
69
- .stButton>button {
70
- background: linear-gradient(to right, #0d8bf2, #04befe) !important;
71
- color: white !important;
72
- border: none;
73
- border-radius: 8px;
74
- padding: 12px 30px;
75
- font-size: 16px;
76
- font-weight: bold;
77
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
78
- transition: all 0.3s ease;
79
- }
80
-
81
- .stDownloadButton>button {
82
- background: linear-gradient(to right, #00c853, #64dd17) !important;
83
- }
84
-
85
- .premium-badge {
86
- background: linear-gradient(45deg, #ffd700, #ff9800);
87
- color: #000;
88
- padding: 3px 10px;
89
- border-radius: 12px;
90
- font-size: 0.8em;
91
- font-weight: bold;
92
- display: inline-block;
93
- margin-left: 10px;
94
- }
95
-
96
- .pricing-card {
97
- background: rgba(255,255,255,0.05);
98
- border-radius: 10px;
99
- padding: 20px;
100
- margin: 10px 0;
101
- border: 1px solid #0d8bf2;
102
- }
103
-
104
- .testimonial {
105
- background: rgba(255,255,255,0.05);
106
- border-radius: 10px;
107
- padding: 15px;
108
- margin: 15px 0;
109
- border-left: 4px solid #00c853;
110
- }
111
-
112
- .disabled-widget {
113
- opacity: 0.6;
114
- pointer-events: none;
115
- }
116
- </style>
117
- """, unsafe_allow_html=True)
118
-
119
- # Header
120
- col1, col2 = st.columns([1, 4])
121
- with col1:
122
- st.image("https://cdn-icons-png.flaticon.com/512/1995/1995485.png", width=80)
123
- with col2:
124
- st.title("🤖 Workshop in a Box Pro")
125
- st.markdown("Generate Boardroom-Quality Corporate Training <span class='premium-badge'>PREMIUM</span>", unsafe_allow_html=True)
126
- st.caption("Create $10K+ Value Workshops in Minutes")
127
-
128
- # Initialize session state
129
- if 'workshop_topic' not in st.session_state:
130
- st.session_state.workshop_topic = "AI-Driven Business Transformation"
131
- if 'generated' not in st.session_state:
132
- st.session_state.generated = False
133
- if 'generating' not in st.session_state:
134
- st.session_state.generating = False
135
- if 'voiceovers' not in st.session_state:
136
- st.session_state.voiceovers = {}
137
- if 'selected_voice' not in st.session_state:
138
- st.session_state.selected_voice = "21m00Tcm4TlvDq8ikWAM"
139
- if 'duration' not in st.session_state:
140
- st.session_state.duration = 4.0
141
- if 'difficulty' not in st.session_state:
142
- st.session_state.difficulty = "C-Suite"
143
- if 'include_code' not in st.session_state:
144
- st.session_state.include_code = True
145
- if 'include_design' not in st.session_state:
146
- st.session_state.include_design = True
147
- if 'include_voiceover' not in st.session_state:
148
- st.session_state.include_voiceover = True
149
- if 'premium_mode' not in st.session_state:
150
- st.session_state.premium_mode = True
151
-
152
- # Sidebar configuration
153
- with st.sidebar:
154
- st.header("⚙️ Executive Workshop Configuration")
155
- st.session_state.workshop_topic = st.text_input(
156
- "Workshop Focus",
157
- st.session_state.workshop_topic,
158
- help="Strategic business topic (e.g., 'AI for Financial Services Transformation')"
159
- )
160
-
161
- topic_empty = st.session_state.workshop_topic.strip() == ""
162
-
163
- if topic_empty:
164
- st.warning("Please enter a strategic workshop focus to enable configuration")
165
-
166
- st.session_state.duration = st.slider(
167
- "Duration (hours)",
168
- 2.0, 8.0, st.session_state.duration, 0.5,
169
- help="Full-day or half-day workshop",
170
- disabled=topic_empty
171
- )
172
-
173
- st.session_state.difficulty = st.selectbox(
174
- "Audience Level",
175
- ["C-Suite", "Executives", "Directors", "Managers"],
176
- index=["C-Suite", "Executives", "Directors", "Managers"].index(st.session_state.difficulty),
177
- disabled=topic_empty
178
- )
179
-
180
- st.session_state.include_code = st.checkbox(
181
- "Include Technical Implementation",
182
- st.session_state.include_code,
183
- disabled=topic_empty
184
- )
185
-
186
- st.session_state.include_design = st.checkbox(
187
- "Generate Premium Visuals",
188
- st.session_state.include_design,
189
- disabled=topic_empty
190
- )
191
-
192
- st.session_state.include_voiceover = st.checkbox(
193
- "Generate Voiceovers",
194
- st.session_state.include_voiceover,
195
- disabled=topic_empty
196
- )
197
-
198
- if st.session_state.include_voiceover and not topic_empty:
199
- st.subheader("🎙️ Voice Selection")
200
- voices = voiceover_agent.get_voices()
201
-
202
- if voices:
203
- selected_voice = st.selectbox(
204
- "Choose a voice:",
205
- options=[v['voice_id'] for v in voices],
206
- format_func=lambda id: next((v['name'] for v in voices if v['voice_id'] == id), "Default"),
207
- key="voice_select"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  )
209
- st.session_state.selected_voice = selected_voice
210
- elif voiceover_agent.api_key:
211
- st.warning("Couldn't load voices. Using default voice.")
212
- else:
213
- st.warning("ElevenLabs API key not set. Voiceovers disabled.")
214
-
215
- st.divider()
216
- st.markdown("**Quality Assurance**")
217
- st.session_state.premium_mode = st.checkbox(
218
- "Enable Premium Mode",
219
- st.session_state.premium_mode,
220
- help="Generate boardroom-quality content with real-world case studies",
221
- disabled=topic_empty
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  )
223
 
224
- generate_disabled = topic_empty or st.session_state.generating
225
- if st.button(
226
- "✨ Generate Premium Workshop",
227
- type="primary",
228
- use_container_width=True,
229
- disabled=generate_disabled
230
- ):
231
- st.session_state.generating = True
232
- st.session_state.voiceovers = {}
233
-
234
- # Generation pipeline
235
- if st.session_state.generating and not topic_empty:
236
- with st.spinner(f"🚀 Creating your executive workshop on '{st.session_state.workshop_topic}'..."):
237
- start_time = time.time()
238
-
239
- outline = topic_agent.generate_outline(
240
- st.session_state.workshop_topic,
241
- st.session_state.duration,
242
- st.session_state.difficulty
243
- )
244
- content = content_agent.generate_content(outline)
245
- slides = slide_agent.generate_slides(content)
246
- code_labs = code_agent.generate_code(content) if st.session_state.include_code else None
247
- design_url = design_agent.generate_design(slides) if st.session_state.include_design else None
248
-
249
- voiceovers = {}
250
- if st.session_state.include_voiceover and voiceover_agent.api_key:
251
- for i, module in enumerate(content.get("modules", [])):
252
- intro_text = f"Module {i+1}: {module['title']}. " + \
253
- f"Key concepts: {', '.join(module.get('learning_points', [''])[:3])}"
254
- audio_data = voiceover_agent.generate_voiceover(
255
- intro_text,
256
- st.session_state.selected_voice
257
- )
258
- if audio_data:
259
- voiceovers[f"module_{i+1}_intro.mp3"] = audio_data
260
-
261
- zip_buffer = io.BytesIO()
262
- with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED) as zip_file:
263
- zip_file.writestr("executive_summary.json", json.dumps(outline, indent=2))
264
- zip_file.writestr("workshop_content.json", json.dumps(content, indent=2))
265
- zip_file.writestr("boardroom_slides.md", slides)
266
- if code_labs:
267
- zip_file.writestr("enterprise_solutions.ipynb", code_labs)
268
- if design_url:
269
- try:
270
- img_data = requests.get(design_url).content
271
- zip_file.writestr("slide_design.png", img_data)
272
- except Exception as e:
273
- st.error(f"Design download error: {str(e)}")
274
- for filename, audio_data in voiceovers.items():
275
- zip_file.writestr(f"voiceovers/{filename}", audio_data)
276
-
277
- st.session_state.outline = outline
278
- st.session_state.content = content
279
- st.session_state.slides = slides
280
- st.session_state.code_labs = code_labs
281
- st.session_state.design_url = design_url
282
- st.session_state.voiceovers = voiceovers
283
- st.session_state.zip_buffer = zip_buffer
284
- st.session_state.gen_time = round(time.time() - start_time, 2)
285
- st.session_state.generated = True
286
- st.session_state.generating = False
287
-
288
- # Results display - PERMANENTLY VISIBLE SECTION
289
- if st.session_state.generated and not topic_empty:
290
- st.success(f"✅ Executive workshop generated in {st.session_state.gen_time} seconds!")
291
-
292
- st.download_button(
293
- label="📥 Download Executive Package",
294
- data=st.session_state.zip_buffer.getvalue(),
295
- file_name=f"{st.session_state.workshop_topic.replace(' ', '_')}_workshop.zip",
296
- mime="application/zip",
297
- use_container_width=True
298
  )
299
-
300
- # Executive summary - ALWAYS VISIBLE
301
- st.markdown("<div class='section-header'><h2>📊 Executive Overview</h2></div>", unsafe_allow_html=True)
302
- st.markdown(f"<div class='executive-summary'>", unsafe_allow_html=True)
303
- st.subheader(st.session_state.outline.get("title", "Strategic Workshop"))
304
- st.caption(f"Duration: {st.session_state.outline.get('duration', '4 hours')} | Level: {st.session_state.outline.get('difficulty', 'Executive')}")
305
-
306
- st.markdown("**Business Value Proposition**")
307
- if "learning_goals" in st.session_state.outline:
308
- for goal in st.session_state.outline["learning_goals"]:
309
- st.markdown(f"- {goal}")
310
-
311
- st.markdown("**Key Deliverables**")
312
- st.markdown("- Boardroom-ready presentation\n"
313
- "- Implementation toolkit\n"
314
- "- ROI calculation framework\n"
315
- "- Enterprise integration guide")
316
- st.markdown("</div>", unsafe_allow_html=True)
317
-
318
- # Workshop content - ALWAYS VISIBLE
319
- st.markdown("<div class='section-header'><h2>📝 Strategic Content Framework</h2></div>", unsafe_allow_html=True)
320
- st.markdown("<div class='workshop-container'>", unsafe_allow_html=True)
321
- if "modules" in st.session_state.content:
322
- for module in st.session_state.content["modules"]:
323
- st.subheader(module.get("title", "Business Module"))
324
- st.markdown(module.get("script", ""))
325
-
326
- st.markdown("**Executive Discussion Points**")
327
- if "discussion_questions" in module:
328
- for q in module["discussion_questions"]:
329
- st.markdown(f"- **{q.get('question', '')}**")
330
- st.caption(q.get("response", ""))
331
- st.divider()
332
- st.markdown("</div>", unsafe_allow_html=True)
333
-
334
- # Slide preview - ALWAYS VISIBLE
335
- st.markdown("<div class='section-header'><h2>🖥️ Boardroom Presentation Preview</h2></div>", unsafe_allow_html=True)
336
- st.markdown("<div class='workshop-container'>", unsafe_allow_html=True)
337
- st.markdown(st.session_state.slides[:2000])
338
- st.markdown("</div>", unsafe_allow_html=True)
339
-
340
- # Technical implementation - ALWAYS VISIBLE
341
- if st.session_state.code_labs:
342
- st.markdown("<div class='section-header'><h2>💻 Enterprise Implementation Toolkit</h2></div>", unsafe_allow_html=True)
343
- st.markdown("<div class='workshop-container'>", unsafe_allow_html=True)
344
- st.code(st.session_state.code_labs)
345
- st.markdown("</div>", unsafe_allow_html=True)
346
-
347
- # Design preview - ALWAYS VISIBLE
348
- if st.session_state.design_url:
349
- st.markdown("<div class='section-header'><h2>🎨 Premium Visual Design</h2></div>", unsafe_allow_html=True)
350
- st.markdown("<div class='workshop-container'>", unsafe_allow_html=True)
351
- try:
352
- st.image(st.session_state.design_url, caption="Corporate Slide Design")
353
- except:
354
- st.warning("Design preview unavailable")
355
- st.markdown("</div>", unsafe_allow_html=True)
356
-
357
- # Voiceover player - ALWAYS VISIBLE
358
- if st.session_state.voiceovers:
359
- st.markdown("<div class='section-header'><h2>🔊 Voiceover Previews</h2></div>", unsafe_allow_html=True)
360
- st.markdown("<div class='workshop-container'>", unsafe_allow_html=True)
361
- for i, (filename, audio_bytes) in enumerate(st.session_state.voiceovers.items()):
362
- module_num = filename.split("_")[1]
363
- st.subheader(f"Module {module_num} Introduction")
364
- st.audio(audio_bytes, format="audio/mp3")
365
- st.markdown("</div>", unsafe_allow_html=True)
366
-
367
- # Pricing section - ALWAYS VISIBLE
368
- st.markdown("<div class='section-header'><h2>🚀 Premium Corporate Offering</h2></div>", unsafe_allow_html=True)
369
- st.markdown(f"""
370
- ### {st.session_state.workshop_topic} Executive Program
371
- <div class="pricing-card">
372
- <h4>Live Workshop</h4>
373
- <h2>$15,000</h2>
374
- <p>Full-day session with Q&A</p>
375
- </div>
376
- <div class="pricing-card">
377
- <h4>On-Demand Course</h4>
378
- <h2>$7,500</h2>
379
- <p>Enterprise-wide access</p>
380
- </div>
381
- <div class="pricing-card">
382
- <h4>Implementation Package</h4>
383
- <h2>$12,500</h2>
384
- <p>Technical integration support</p>
385
- </div>
386
-
387
- **Premium Features:**
388
- - Customized to your industry vertical
389
- - ROI guarantee
390
- - 12-month support agreement
391
- - Executive briefing package
392
- """, unsafe_allow_html=True)
393
-
394
- # Testimonials - ALWAYS VISIBLE
395
- st.markdown("<div class='section-header'><h2>💼 Executive Testimonials</h2></div>", unsafe_allow_html=True)
396
- st.markdown("""
397
- <div class="testimonial">
398
- <p>"This platform helped us create a $50K training program in one afternoon. The ROI was immediate."</p>
399
- <p><strong>— Sarah Johnson, CLO at FinTech Global</strong></p>
400
- </div>
401
- <div class="testimonial">
402
- <p>"The boardroom-quality materials impressed our clients and justified our premium pricing."</p>
403
- <p><strong>— Michael Chen, Partner at McKinsey & Company</strong></p>
404
- </div>
405
- """, unsafe_allow_html=True)
406
-
407
- # CTA - ALWAYS VISIBLE
408
- st.markdown("<div class='section-header'><h2>Get Started</h2></div>", unsafe_allow_html=True)
409
- col1, col2 = st.columns(2)
410
- with col1:
411
- st.link_button("📅 Book Strategy Session", "https://calendly.com/your-link", use_container_width=True)
412
- with col2:
413
- st.link_button("💼 Enterprise Solutions", "https://your-company.com/enterprise", use_container_width=True)
414
-
415
- # Footer - ALWAYS VISIBLE
416
- st.markdown("""
417
- <div style="text-align: center; padding: 20px; color: #aaa; margin-top: 30px;">
418
- Workshop in a Box Pro® | Enterprise-Grade AI Training Solutions | © 2025
419
- </div>
420
- """, unsafe_allow_html=True)
421
-
422
- # Debug info - ALWAYS VISIBLE
423
- with st.sidebar:
424
- st.divider()
425
- if hasattr(topic_agent, 'openai_client') and topic_agent.openai_client:
426
- st.success("OpenAI API Connected")
427
- else:
428
- st.warning("OpenAI API not set - using enhanced mock data")
429
-
430
- if voiceover_agent.api_key:
431
- st.success("ElevenLabs API Key Found")
432
- elif st.session_state.include_voiceover:
433
- st.warning("ElevenLabs API key not set")
434
-
435
- st.info(f"""
436
- **Current Workshop:**
437
- {st.session_state.workshop_topic}
438
-
439
- **Premium Features:**
440
- - AI-generated voiceovers
441
- - Professional slide designs
442
- - Real-world case studies
443
- - Practical code labs
444
- """)
 
1
+ import os
2
  import json
 
 
 
3
  import requests
4
+ from dotenv import load_dotenv
5
+ from openai import OpenAI
6
+ from flask import Flask, render_template_string, request
7
+
8
+ # Load environment variables
9
+ load_dotenv()
10
+
11
+ # Initialize API clients
12
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
13
+ openai_client = OpenAI(api_key=OPENAI_API_KEY) if OPENAI_API_KEY else None
14
+ ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
15
+
16
+ app = Flask(__name__)
17
+
18
+ # ---------- Agent implementations ----------
19
+
20
+ class TopicAgent:
21
+ def generate_outline(self, topic, duration, difficulty):
22
+ if not openai_client:
23
+ print("OpenAI API not set - using enhanced mock data for outline.")
24
+ return self._mock_outline(topic, duration, difficulty)
25
+
26
+ try:
27
+ response = openai_client.chat.completions.create(
28
+ model="gpt-4-turbo",
29
+ messages=[
30
+ {
31
+ "role": "system",
32
+ "content": (
33
+ "You are an expert corporate trainer with 20+ years of experience creating "
34
+ "high-value workshops for Fortune 500 companies. Create a professional workshop outline that "
35
+ "includes: 1) Clear learning objectives, 2) Practical real-world exercises, "
36
+ "3) Industry case studies, 4) Measurable outcomes. Format as JSON."
37
+ )
38
+ },
39
+ {
40
+ "role": "user",
41
+ "content": (
42
+ f"Create a comprehensive {duration}-hour {difficulty} workshop outline on '{topic}' for corporate executives. "
43
+ "Structure: title, duration, difficulty, learning_goals (3-5 bullet points), "
44
+ "modules (5-7 modules). Each module should have: title, duration, learning_points (3 bullet points), "
45
+ "case_study (real company example), exercises (2 practical exercises)."
46
+ )
47
+ }
48
+ ],
49
+ temperature=0.3,
50
+ max_tokens=1500,
51
+ response_format={"type": "json_object"}
52
+ )
53
+ return json.loads(response.choices[0].message.content)
54
+ except Exception as e:
55
+ print(f"Error during OpenAI outline generation: {e}. Falling back to mock outline.")
56
+ return self._mock_outline(topic, duration, difficulty)
57
+
58
+ def _mock_outline(self, topic, duration, difficulty):
59
+ return {
60
+ "title": f"Mastering {topic} for Business Impact",
61
+ "duration": f"{duration} hours",
62
+ "difficulty": difficulty,
63
+ "learning_goals": [
64
+ "Apply advanced techniques to real business challenges",
65
+ "Measure ROI of prompt engineering initiatives",
66
+ "Develop organizational prompt engineering standards",
67
+ "Implement ethical AI governance frameworks"
68
+ ],
69
+ "modules": [
70
+ {
71
+ "title": "Strategic Foundations",
72
+ "duration": "45 min",
73
+ "learning_points": [
74
+ "Business value assessment framework",
75
+ "ROI calculation models",
76
+ "Stakeholder alignment strategies"
77
+ ],
78
+ "case_study": "How JPMorgan reduced operational costs by 37% with prompt optimization",
79
+ "exercises": [
80
+ "Calculate potential ROI for your organization",
81
+ "Develop stakeholder communication plan"
82
+ ]
83
+ },
84
+ {
85
+ "title": "Advanced Pattern Engineering",
86
+ "duration": "60 min",
87
+ "learning_points": [
88
+ "Chain-of-thought implementations",
89
+ "Self-correcting prompt architectures",
90
+ "Domain-specific pattern libraries"
91
+ ],
92
+ "case_study": "McKinsey's knowledge management transformation",
93
+ "exercises": [
94
+ "Design pattern library for your industry",
95
+ "Implement self-correction workflow"
96
+ ]
97
+ }
98
+ ]
99
+ }
100
+
101
+
102
+ class ContentAgent:
103
+ def generate_content(self, outline):
104
+ if not openai_client:
105
+ print("OpenAI API not set - using enhanced mock data for content.")
106
+ return self._mock_content(outline)
107
+
108
+ try:
109
+ response = openai_client.chat.completions.create(
110
+ model="gpt-4-turbo",
111
+ messages=[
112
+ {
113
+ "role": "system",
114
+ "content": (
115
+ "You are a senior instructional designer creating premium corporate training materials. "
116
+ "Develop comprehensive workshop content with: 1) Practitioner-level insights, "
117
+ "2) Actionable frameworks, 3) Real-world examples, 4) Practical exercises. "
118
+ "Avoid generic AI content - focus on business impact."
119
+ )
120
+ },
121
+ {
122
+ "role": "user",
123
+ "content": (
124
+ f"Create premium workshop content for this outline: {json.dumps(outline)}. "
125
+ "For each module: "
126
+ "1) Detailed script (executive summary, 3 key concepts, business applications) "
127
+ "2) Speaker notes (presentation guidance) "
128
+ "3) 3 discussion questions with executive-level responses "
129
+ "4) 2 practical exercises with solution blueprints "
130
+ "Format as JSON."
131
+ )
132
+ }
133
+ ],
134
+ temperature=0.4,
135
+ max_tokens=3000,
136
+ response_format={"type": "json_object"}
137
+ )
138
+ return json.loads(response.choices[0].message.content)
139
+ except Exception as e:
140
+ print(f"Error during OpenAI content generation: {e}. Falling back to mock content.")
141
+ return self._mock_content(outline)
142
+
143
+ def _mock_content(self, outline):
144
+ return {
145
+ "workshop_title": outline.get("title", "Premium AI Workshop"),
146
+ "modules": [
147
+ {
148
+ "title": "Strategic Foundations",
149
+ "script": (
150
+ "## Executive Summary\n"
151
+ "This module establishes the business case for advanced prompt engineering, "
152
+ "focusing on measurable ROI and stakeholder alignment.\n\n"
153
+ "### Key Concepts:\n"
154
+ "1. **Value Assessment Framework**: Quantify potential savings and revenue opportunities\n"
155
+ "2. **ROI Calculation Models**: Custom models for different industries\n"
156
+ "3. **Stakeholder Alignment**: Executive communication strategies\n\n"
157
+ "### Business Applications:\n"
158
+ "- Cost reduction in customer service operations\n"
159
+ "- Acceleration of R&D processes\n"
160
+ "- Enhanced competitive intelligence"
161
+ ),
162
+ "speaker_notes": [
163
+ "Emphasize real dollar impact - use JPMorgan case study numbers",
164
+ "Show ROI calculator template",
165
+ "Highlight C-suite communication strategies"
166
+ ],
167
+ "discussion_questions": [
168
+ {
169
+ "question": "How could prompt engineering impact your bottom line?",
170
+ "response": "Typical results: 30-40% operational efficiency gains, 15-25% innovation acceleration"
171
+ }
172
+ ],
173
+ "exercises": [
174
+ {
175
+ "title": "ROI Calculation Workshop",
176
+ "instructions": "Calculate potential savings using our enterprise ROI model",
177
+ "solution": "Template: (Current Cost × Efficiency Gain) - Implementation Cost"
178
+ }
179
+ ]
180
+ }
181
+ ]
182
+ }
183
+
184
+
185
+ class SlideAgent:
186
+ def generate_slides(self, content):
187
+ if not openai_client:
188
+ print("OpenAI API not set - using enhanced mock slides.")
189
+ return self._professional_slides(content)
190
+
191
+ try:
192
+ response = openai_client.chat.completions.create(
193
+ model="gpt-4-turbo",
194
+ messages=[
195
+ {
196
+ "role": "system",
197
+ "content": (
198
+ "You are a McKinsey-level presentation specialist. Create professional slides with: "
199
+ "1) Clean, executive-friendly design 2) Data visualization frameworks "
200
+ "3) Action-oriented content 4) Brand-compliant styling. "
201
+ "Use Marp Markdown format with the 'gaia' theme."
202
+ )
203
+ },
204
+ {
205
+ "role": "user",
206
+ "content": (
207
+ f"Create a boardroom-quality slide deck for: {json.dumps(content)}. "
208
+ "Structure: Title slide, module slides (objective, 3 key points, case study, exercise), "
209
+ "summary slide. Include placeholders for data visualization."
210
+ )
211
+ }
212
+ ],
213
+ temperature=0.2,
214
+ max_tokens=2500
215
+ )
216
+ return response.choices[0].message.content
217
+ except Exception as e:
218
+ print(f"Error during slide generation: {e}. Using mock slides.")
219
+ return self._professional_slides(content)
220
+
221
+ def _professional_slides(self, content):
222
+ return f"""---
223
+ marp: true
224
+ theme: gaia
225
+ class: lead
226
+ paginate: true
227
+ backgroundColor: #fff
228
+ backgroundImage: url('https://marp.app/assets/hero-background.svg')
229
+ ---
230
+
231
+ # {content.get('workshop_title', 'Executive AI Workshop')}
232
+ ## Transforming Business Through Advanced AI
233
+
234
+ ---
235
+ <!-- _class: invert -->
236
+ ## Module 1: Strategic Foundations
237
+ ### Driving Measurable Business Value
238
+
239
+ ![bg right:40% w:450](https://images.pexels.com/photos/3184292/pexels-photo-3184292.jpeg)
240
+
241
+ - **ROI Framework**: Quantifying impact
242
+ - **Stakeholder Alignment**: Executive buy-in strategies
243
+ - **Implementation Roadmap**: Phased adoption plan
244
+
245
+ ---
246
+ ## Case Study: Financial Services Transformation
247
+ ### JPMorgan Chase
248
+
249
+ | Metric | Before | After | Improvement |
250
+ |--------|--------|-------|-------------|
251
+ | Operation Costs | $4.2M | $2.6M | 38% reduction |
252
+ | Process Time | 14 days | 3 days | 79% faster |
253
+ | Error Rate | 8.2% | 0.4% | 95% reduction |
254
+
255
+ ---
256
+ ## Practical Exercise: ROI Calculation
257
+ ```mermaid
258
+ graph TD
259
+ A[Current Costs] --> B[Potential Savings]
260
+ C[Implementation Costs] --> D[Net ROI]
261
+ B --> D
262
+ Document current process costs
263
+
264
+ Estimate efficiency gains
265
+
266
+ Calculate net ROI
267
+
268
+ Q&A
269
+ Let's discuss your specific challenges
270
+ ```"""
271
+
272
+
273
+ class CodeAgent:
274
+ def generate_code(self, content):
275
+ if not openai_client:
276
+ print("OpenAI API not set - using enhanced mock code.")
277
+ return self._professional_code(content)
278
+
279
+ try:
280
+ response = openai_client.chat.completions.create(
281
+ model="gpt-4-turbo",
282
+ messages=[
283
+ {
284
+ "role": "system",
285
+ "content": (
286
+ "You are an enterprise solutions architect. Create professional-grade code labs with: "
287
+ "1) Production-ready patterns 2) Comprehensive documentation "
288
+ "3) Enterprise security practices 4) Scalable architectures. "
289
+ "Use Python with the latest best practices."
290
+ )
291
+ },
292
+ {
293
+ "role": "user",
294
+ "content": (
295
+ f"Create a professional code lab for: {json.dumps(content)}. "
296
+ "Include: Setup instructions, business solution patterns, "
297
+ "enterprise integration examples, and security best practices."
298
+ )
299
+ }
300
+ ],
301
+ temperature=0.3,
302
+ max_tokens=2500
303
  )
304
+ return response.choices[0].message.content
305
+ except Exception as e:
306
+ print(f"Error during code generation: {e}. Using mock code.")
307
+ return self._professional_code(content)
308
+
309
+ def _professional_code(self, content):
310
+ return f"""# Enterprise-Grade Prompt Engineering Lab
311
+ # Business Solution Framework
312
+ class PromptOptimizer:
313
+ def __init__(self, model="gpt-4-turbo"):
314
+ self.model = model
315
+ self.pattern_library = {{
316
+ "financial_analysis": "Extract key metrics from financial reports",
317
+ "customer_service": "Resolve tier-2 support tickets"
318
+ }}
319
+
320
+ def optimize_prompt(self, business_case):
321
+ # Implement enterprise optimization logic
322
+ return f"Business-optimized prompt for {{business_case}}"
323
+
324
+ def calculate_roi(self, current_cost, expected_efficiency):
325
+ return current_cost * expected_efficiency
326
+
327
+ # Example usage
328
+ optimizer = PromptOptimizer()
329
+ print(optimizer.calculate_roi(500000, 0.35)) # $175,000 savings
330
+
331
+ # Security Best Practices
332
+ def secure_prompt_handling(user_input):
333
+ # Implement OWASP security standards
334
+ sanitized = sanitize_input(user_input)
335
+ validate_business_context(sanitized)
336
+ return apply_enterprise_guardrails(sanitized)
337
+
338
+ # Integration Pattern: CRM System
339
+ def integrate_with_salesforce(prompt, salesforce_data):
340
+ # Enterprise integration example
341
+ enriched_prompt = f"{{prompt}} using {{salesforce_data}}"
342
+ return call_ai_api(enriched_prompt)
343
+ """
344
+
345
+
346
+ class DesignAgent:
347
+ def generate_design(self, slide_content):
348
+ if not openai_client:
349
+ print("OpenAI API not set - skipping design generation.")
350
+ return None
351
+
352
+ try:
353
+ response = openai_client.images.generate(
354
+ model="dall-e-3",
355
+ prompt=(
356
+ f"Professional corporate slide background for '{slide_content[:200]}' workshop. "
357
+ "Modern business style, clean lines, premium gradient, boardroom appropriate. "
358
+ "Include abstract technology elements in corporate colors."
359
+ ),
360
+ n=1,
361
+ size="1024x1024"
362
+ )
363
+ return response.data[0].url
364
+ except Exception as e:
365
+ print(f"Error during design generation: {e}.")
366
+ return None
367
+
368
+
369
+ class VoiceoverAgent:
370
+ def __init__(self):
371
+ self.api_key = ELEVENLABS_API_KEY
372
+ self.voice_id = "21m00Tcm4TlvDq8ikWAM" # Default voice ID
373
+ self.model = "eleven_monolingual_v1"
374
+
375
+ def generate_voiceover(self, text, voice_id=None):
376
+ if not self.api_key:
377
+ print("ElevenLabs API key not set - skipping voiceover generation.")
378
+ return None
379
+
380
+ try:
381
+ voice = voice_id if voice_id else self.voice_id
382
+ url = f"https://api.elevenlabs.io/v1/text-to-speech/{voice}"
383
+ headers = {
384
+ "Accept": "audio/mpeg",
385
+ "Content-Type": "application/json",
386
+ "xi-api-key": self.api_key
387
+ }
388
+ data = {
389
+ "text": text,
390
+ "model_id": self.model,
391
+ "voice_settings": {
392
+ "stability": 0.7,
393
+ "similarity_boost": 0.8,
394
+ "style": 0.5,
395
+ "use_speaker_boost": True
396
+ }
397
+ }
398
+ response = requests.post(url, json=data, headers=headers)
399
+ response.raise_for_status()
400
+ return response.content
401
+ except requests.exceptions.RequestException as e:
402
+ print(f"Error generating voiceover: {e}")
403
+ return None
404
+
405
+ def get_voices(self):
406
+ if not self.api_key:
407
+ print("ElevenLabs API key not set - cannot fetch voices.")
408
+ return []
409
+
410
+ try:
411
+ url = "https://api.elevenlabs.io/v1/voices"
412
+ headers = {"xi-api-key": self.api_key}
413
+ response = requests.get(url, headers=headers)
414
+ response.raise_for_status()
415
+ return response.json().get("voices", [])
416
+ except requests.exceptions.RequestException as e:
417
+ print(f"Error fetching voices: {e}")
418
+ return []
419
+
420
+
421
+ # ---------- Simple frontend to show workshop focus input ----------
422
+
423
+ HTML_PAGE = """
424
+ <!doctype html>
425
+ <html lang="en">
426
+ <head>
427
+ <meta charset="utf-8" />
428
+ <title>Executive Workshop Configuration</title>
429
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
430
+ <style>
431
+ body { font-family: system-ui,-apple-system,BlinkMacSystemFont,sans-serif; background:#f0f4f8; padding:30px; }
432
+ .card { background:#fff; padding:20px; border-radius:12px; max-width:500px; margin:auto; box-shadow:0 10px 25px rgba(0,0,0,0.05); }
433
+ h1 { font-size:1.75rem; margin-bottom:4px; display:flex; align-items:center; gap:8px; }
434
+ label { display:block; margin-top:16px; font-weight:600; }
435
+ input { width:100%; padding:10px 14px; border:1px solid #cbd5e1; border-radius:6px; font-size:1rem; transition: all .2s; color:#1f2937; background:#fff; }
436
+ input:focus { outline:none; border-color:#2563eb; box-shadow:0 0 0 3px rgba(59,130,246,0.35); }
437
+ input::placeholder { color:#94a3b8; }
438
+ ::selection { background: rgba(59,130,246,0.4); color:#000; }
439
+ .status { margin-bottom:12px; padding:12px; border-radius:8px; }
440
+ .warn { background:#fff8e1; border:1px solid #f5e1a4; color:#886f1b; }
441
+ .ok { background:#e6f6ed; border:1px solid #b8e0c5; color:#1e5f3d; }
442
+ .note { margin-top:8px; font-size:.9rem; color:#475569; }
443
+ </style>
444
+ </head>
445
+ <body>
446
+ <div class="card">
447
+ <div class="status {{ 'ok' if openai_set else 'warn' }}">
448
+ {% if openai_set %}
449
+ <div class="ok">OpenAI API Key Found</div>
450
+ {% else %}
451
+ <div class="warn">OpenAI API not set - using enhanced mock data</div>
452
+ {% endif %}
453
+ {% if elevenlabs_set %}
454
+ <div class="ok" style="margin-top:6px;">ElevenLabs API Key Found</div>
455
+ {% else %}
456
+ <div class="warn" style="margin-top:6px;">ElevenLabs API Key not set</div>
457
+ {% endif %}
458
+ </div>
459
+ <h1>Executive Workshop Configuration</h1>
460
+ <form method="post" action="/submit">
461
+ <label for="focus">Workshop Focus</label>
462
+ <input id="focus" name="focus" placeholder="e.g., AI-Driven Business Transformation" value="{{ prefill }}" autocomplete="off" />
463
+ <div class="note">Type here to set the workshop's focus. Selection and text are styled for clarity.</div>
464
+ <button type="submit" style="margin-top:16px; padding:10px 16px; border:none; background:#2563eb; color:#fff; border-radius:6px; cursor:pointer;">Save</button>
465
+ </form>
466
+ </div>
467
+ </body>
468
+ </html>
469
+ """
470
+
471
+ @app.route("/", methods=["GET"])
472
+ def index():
473
+ return render_template_string(
474
+ HTML_PAGE,
475
+ openai_set=bool(OPENAI_API_KEY),
476
+ elevenlabs_set=bool(ELEVENLABS_API_KEY),
477
+ prefill=""
478
  )
479
 
480
+ @app.route("/submit", methods=["POST"])
481
+ def submit():
482
+ focus = request.form.get("focus", "")
483
+ # For demo: echo back with prefill
484
+ return render_template_string(
485
+ HTML_PAGE,
486
+ openai_set=bool(OPENAI_API_KEY),
487
+ elevenlabs_set=bool(ELEVENLABS_API_KEY),
488
+ prefill=focus
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  )
490
+
491
+ if __name__ == "__main__":
492
+ print(f"Loaded OPENAI_API_KEY: {bool(OPENAI_API_KEY)}, ELEVENLABS_API_KEY: {bool(ELEVENLABS_API_KEY)}")
493
+ app.run(host="0.0.0.0", port=8080, debug=True)