|
|
|
import streamlit as st |
|
import json |
|
import zipfile |
|
import io |
|
import time |
|
import os |
|
import openai |
|
from dotenv import load_dotenv |
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
if os.getenv("OPENAI_API_KEY"): |
|
openai.api_key = os.getenv("OPENAI_API_KEY") |
|
|
|
|
|
class TopicAgent: |
|
def generate_outline(self, topic, duration, difficulty): |
|
if not openai.api_key: |
|
return self._mock_outline(topic, duration, difficulty) |
|
|
|
try: |
|
response = openai.ChatCompletion.create( |
|
model="gpt-4", |
|
messages=[ |
|
{"role": "system", "content": "You're an expert corporate trainer creating AI workshop outlines"}, |
|
{"role": "user", "content": ( |
|
f"Create a {duration}-hour {difficulty} workshop outline on {topic}. " |
|
"Include: 1) Key learning goals, 2) 4 modules with titles and durations, " |
|
"3) Hands-on exercises per module. Output as JSON." |
|
)} |
|
] |
|
) |
|
return json.loads(response.choices[0].message.content) |
|
except: |
|
return self._mock_outline(topic, duration, difficulty) |
|
|
|
def _mock_outline(self, topic, duration, difficulty): |
|
return { |
|
"topic": topic, |
|
"duration": f"{duration} hours", |
|
"difficulty": difficulty, |
|
"goals": [ |
|
f"Master advanced {topic} techniques", |
|
"Develop industry-specific applications", |
|
"Build and evaluate complex AI workflows", |
|
"Implement best practices for production" |
|
], |
|
"modules": [ |
|
{ |
|
"title": f"Fundamentals of {topic}", |
|
"duration": "30 min", |
|
"learning_points": [ |
|
"Core principles and terminology", |
|
"Patterns and anti-patterns", |
|
"Evaluation frameworks" |
|
] |
|
}, |
|
{ |
|
"title": f"{topic} for Enterprise Applications", |
|
"duration": "45 min", |
|
"learning_points": [ |
|
"Industry-specific use cases", |
|
"Integration with existing systems", |
|
"Scalability considerations" |
|
] |
|
} |
|
] |
|
} |
|
|
|
class ContentAgent: |
|
def generate_content(self, outline): |
|
if not openai.api_key: |
|
return self._mock_content(outline) |
|
|
|
try: |
|
response = openai.ChatCompletion.create( |
|
model="gpt-4", |
|
messages=[ |
|
{"role": "system", "content": "You create detailed workshop content from outlines"}, |
|
{"role": "user", "content": ( |
|
f"Create workshop content from this outline: {json.dumps(outline)}. " |
|
"Include: 1) Detailed scripts, 2) Speaker notes, 3) 3 quiz questions per module, " |
|
"4) Hands-on exercises. Output as JSON." |
|
)} |
|
] |
|
) |
|
return json.loads(response.choices[0].message.content) |
|
except: |
|
return self._mock_content(outline) |
|
|
|
def _mock_content(self, outline): |
|
return { |
|
"workshop_title": f"Mastering {outline['topic']}", |
|
"modules": [ |
|
{ |
|
"title": module["title"], |
|
"script": f"Comprehensive script for {module['title']}...", |
|
"speaker_notes": f"Key talking points: {', '.join(module['learning_points'])}", |
|
"exercises": [f"Exercise about {point}" for point in module["learning_points"]], |
|
"quiz": [ |
|
{ |
|
"question": f"Question about {module['title']}", |
|
"options": ["A", "B", "C", "D"], |
|
"answer": "A" |
|
} |
|
] |
|
} for module in outline["modules"] |
|
] |
|
} |
|
|
|
class SlideAgent: |
|
def generate_slides(self, content): |
|
markdown_slides = f"# {content['workshop_title']}\n\n" |
|
for i, module in enumerate(content["modules"]): |
|
markdown_slides += f"## Module {i+1}: {module['title']}\n\n" |
|
markdown_slides += f"### Key Learning Points:\n- {module['speaker_notes']}\n\n" |
|
markdown_slides += "### Exercises:\n" |
|
for j, exercise in enumerate(module["exercises"]): |
|
markdown_slides += f"{j+1}. {exercise}\n" |
|
markdown_slides += "\n---\n" |
|
return markdown_slides |
|
|
|
class CodeAgent: |
|
def generate_code(self, content): |
|
return f"# {content['workshop_title']} Code Labs\n\n" + \ |
|
"import pandas as pd\n\n" + \ |
|
"# Hands-on exercises for:\n" + \ |
|
"\n".join([f"# - {module['title']}" for module in content["modules"]]) |
|
|
|
|
|
topic_agent = TopicAgent() |
|
content_agent = ContentAgent() |
|
slide_agent = SlideAgent() |
|
code_agent = CodeAgent() |
|
|
|
|
|
st.set_page_config(page_title="Workshop in a Box", layout="wide") |
|
st.title("π€ Workshop in a Box") |
|
st.caption("Generate corporate AI training workshops in minutes") |
|
|
|
|
|
with st.sidebar: |
|
st.header("Configuration") |
|
workshop_topic = st.text_input("Workshop Topic", "Advanced Prompt Engineering") |
|
duration = st.slider("Duration (hours)", 1.0, 8.0, 2.0) |
|
difficulty = st.selectbox("Difficulty", ["Beginner", "Intermediate", "Advanced"]) |
|
include_code = st.checkbox("Include Code Labs", True) |
|
|
|
if st.button("β¨ Generate Workshop", type="primary"): |
|
with st.spinner("Creating your workshop materials..."): |
|
|
|
start_time = time.time() |
|
outline = topic_agent.generate_outline(workshop_topic, duration, difficulty) |
|
content = content_agent.generate_content(outline) |
|
slides = slide_agent.generate_slides(content) |
|
code_labs = code_agent.generate_code(content) if include_code else {} |
|
|
|
|
|
zip_buffer = io.BytesIO() |
|
with zipfile.ZipFile(zip_buffer, "a") as zip_file: |
|
zip_file.writestr("outline.json", json.dumps(outline, indent=2)) |
|
zip_file.writestr("content.json", json.dumps(content, indent=2)) |
|
zip_file.writestr("slides.md", slides) |
|
if code_labs: |
|
zip_file.writestr("code_labs.ipynb", code_labs) |
|
|
|
st.session_state.outline = outline |
|
st.session_state.content = content |
|
st.session_state.slides = slides |
|
st.session_state.code_labs = code_labs |
|
st.session_state.zip_buffer = zip_buffer |
|
st.session_state.gen_time = round(time.time() - start_time, 2) |
|
|
|
|
|
if "outline" in st.session_state: |
|
st.success(f"Generated workshop materials in {st.session_state.gen_time} seconds!") |
|
|
|
|
|
st.download_button( |
|
label="π₯ Download Workshop Package", |
|
data=st.session_state.zip_buffer.getvalue(), |
|
file_name=f"{workshop_topic.replace(' ', '_')}_workshop.zip", |
|
mime="application/zip" |
|
) |
|
|
|
|
|
with st.expander("Workshop Outline"): |
|
st.json(st.session_state.outline) |
|
|
|
with st.expander("Content Script"): |
|
st.write(st.session_state.content) |
|
|
|
with st.expander("Slide Deck Preview"): |
|
st.markdown(st.session_state.slides) |
|
|
|
if st.session_state.code_labs: |
|
with st.expander("Code Labs"): |
|
st.code(st.session_state.code_labs) |
|
|
|
|
|
st.divider() |
|
st.subheader("Ready to deliver this workshop?") |
|
st.write("**$10K per corporate engagement | $1K refundable pilot deposit**") |
|
st.link_button("π Book Pilot Workshop", "https://calendly.com/your-link") |
|
|
|
|
|
if os.getenv("OPENAI_API_KEY"): |
|
st.sidebar.success("OpenAI API connected") |
|
else: |
|
st.sidebar.warning("OpenAI API not set - using mock data") |