File size: 8,325 Bytes
f0d7cfb af64a0f 96005ed f0d7cfb af64a0f f0d7cfb af64a0f 96005ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# app.py
import streamlit as st
import json
import zipfile
import io
import time
import os
import openai
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Initialize OpenAI API key
if os.getenv("OPENAI_API_KEY"):
openai.api_key = os.getenv("OPENAI_API_KEY")
# Combined agent classes
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"]])
# Initialize agents
topic_agent = TopicAgent()
content_agent = ContentAgent()
slide_agent = SlideAgent()
code_agent = CodeAgent()
# Streamlit UI
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")
# Sidebar configuration
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..."):
# Agent pipeline
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 {}
# Prepare download package
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)
# Results display
if "outline" in st.session_state:
st.success(f"Generated workshop materials in {st.session_state.gen_time} seconds!")
# Download button
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"
)
# Preview sections
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)
# Sales CTA
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")
# Debug: Show API status
if os.getenv("OPENAI_API_KEY"):
st.sidebar.success("OpenAI API connected")
else:
st.sidebar.warning("OpenAI API not set - using mock data") |