mgbam commited on
Commit
f0d7cfb
·
verified ·
1 Parent(s): 1b1d401

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -8
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import json
3
  import zipfile
@@ -10,21 +11,133 @@ from dotenv import load_dotenv
10
  # Load environment variables
11
  load_dotenv()
12
 
13
- # Import agents directly
14
- from topic_agent import TopicAgent
15
- from content_agent import ContentAgent
16
- from slide_agent import SlideAgent
17
- from code_agent import CodeAgent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Initialize agents
20
- topic_agent = TopicAgent(os.getenv("OPENAI_API_KEY"))
21
- content_agent = ContentAgent(os.getenv("OPENAI_API_KEY"))
22
  slide_agent = SlideAgent()
23
  code_agent = CodeAgent()
24
 
25
  # Streamlit UI
26
  st.set_page_config(page_title="Workshop in a Box", layout="wide")
27
- st.image("https://i.imgur.com/3fXQ0DB.png", width=200)
28
  st.title("🤖 Workshop in a Box")
29
  st.caption("Generate corporate AI training workshops in minutes")
30
 
 
1
+ # app.py
2
  import streamlit as st
3
  import json
4
  import zipfile
 
11
  # Load environment variables
12
  load_dotenv()
13
 
14
+ # Initialize OpenAI API key
15
+ if os.getenv("OPENAI_API_KEY"):
16
+ openai.api_key = os.getenv("OPENAI_API_KEY")
17
+
18
+ # Combined agent classes
19
+ class TopicAgent:
20
+ def generate_outline(self, topic, duration, difficulty):
21
+ if not openai.api_key:
22
+ return self._mock_outline(topic, duration, difficulty)
23
+
24
+ try:
25
+ response = openai.ChatCompletion.create(
26
+ model="gpt-4",
27
+ messages=[
28
+ {"role": "system", "content": "You're an expert corporate trainer creating AI workshop outlines"},
29
+ {"role": "user", "content": (
30
+ f"Create a {duration}-hour {difficulty} workshop outline on {topic}. "
31
+ "Include: 1) Key learning goals, 2) 4 modules with titles and durations, "
32
+ "3) Hands-on exercises per module. Output as JSON."
33
+ )}
34
+ ]
35
+ )
36
+ return json.loads(response.choices[0].message.content)
37
+ except:
38
+ return self._mock_outline(topic, duration, difficulty)
39
+
40
+ def _mock_outline(self, topic, duration, difficulty):
41
+ return {
42
+ "topic": topic,
43
+ "duration": f"{duration} hours",
44
+ "difficulty": difficulty,
45
+ "goals": [
46
+ f"Master advanced {topic} techniques",
47
+ "Develop industry-specific applications",
48
+ "Build and evaluate complex AI workflows",
49
+ "Implement best practices for production"
50
+ ],
51
+ "modules": [
52
+ {
53
+ "title": f"Fundamentals of {topic}",
54
+ "duration": "30 min",
55
+ "learning_points": [
56
+ "Core principles and terminology",
57
+ "Patterns and anti-patterns",
58
+ "Evaluation frameworks"
59
+ ]
60
+ },
61
+ {
62
+ "title": f"{topic} for Enterprise Applications",
63
+ "duration": "45 min",
64
+ "learning_points": [
65
+ "Industry-specific use cases",
66
+ "Integration with existing systems",
67
+ "Scalability considerations"
68
+ ]
69
+ }
70
+ ]
71
+ }
72
+
73
+ class ContentAgent:
74
+ def generate_content(self, outline):
75
+ if not openai.api_key:
76
+ return self._mock_content(outline)
77
+
78
+ try:
79
+ response = openai.ChatCompletion.create(
80
+ model="gpt-4",
81
+ messages=[
82
+ {"role": "system", "content": "You create detailed workshop content from outlines"},
83
+ {"role": "user", "content": (
84
+ f"Create workshop content from this outline: {json.dumps(outline)}. "
85
+ "Include: 1) Detailed scripts, 2) Speaker notes, 3) 3 quiz questions per module, "
86
+ "4) Hands-on exercises. Output as JSON."
87
+ )}
88
+ ]
89
+ )
90
+ return json.loads(response.choices[0].message.content)
91
+ except:
92
+ return self._mock_content(outline)
93
+
94
+ def _mock_content(self, outline):
95
+ return {
96
+ "workshop_title": f"Mastering {outline['topic']}",
97
+ "modules": [
98
+ {
99
+ "title": module["title"],
100
+ "script": f"Comprehensive script for {module['title']}...",
101
+ "speaker_notes": f"Key talking points: {', '.join(module['learning_points'])}",
102
+ "exercises": [f"Exercise about {point}" for point in module["learning_points"]],
103
+ "quiz": [
104
+ {
105
+ "question": f"Question about {module['title']}",
106
+ "options": ["A", "B", "C", "D"],
107
+ "answer": "A"
108
+ }
109
+ ]
110
+ } for module in outline["modules"]
111
+ ]
112
+ }
113
+
114
+ class SlideAgent:
115
+ def generate_slides(self, content):
116
+ markdown_slides = f"# {content['workshop_title']}\n\n"
117
+ for i, module in enumerate(content["modules"]):
118
+ markdown_slides += f"## Module {i+1}: {module['title']}\n\n"
119
+ markdown_slides += f"### Key Learning Points:\n- {module['speaker_notes']}\n\n"
120
+ markdown_slides += "### Exercises:\n"
121
+ for j, exercise in enumerate(module["exercises"]):
122
+ markdown_slides += f"{j+1}. {exercise}\n"
123
+ markdown_slides += "\n---\n"
124
+ return markdown_slides
125
+
126
+ class CodeAgent:
127
+ def generate_code(self, content):
128
+ return f"# {content['workshop_title']} Code Labs\n\n" + \
129
+ "import pandas as pd\n\n" + \
130
+ "# Hands-on exercises for:\n" + \
131
+ "\n".join([f"# - {module['title']}" for module in content["modules"]])
132
 
133
  # Initialize agents
134
+ topic_agent = TopicAgent()
135
+ content_agent = ContentAgent()
136
  slide_agent = SlideAgent()
137
  code_agent = CodeAgent()
138
 
139
  # Streamlit UI
140
  st.set_page_config(page_title="Workshop in a Box", layout="wide")
 
141
  st.title("🤖 Workshop in a Box")
142
  st.caption("Generate corporate AI training workshops in minutes")
143