jefmon01 commited on
Commit
8e7732f
·
1 Parent(s): 0c65aed

Update space

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -14,7 +14,7 @@ Hugging Face Space — Gradio app for a live, executive-focused Cybersecurity RP
14
  - Optional pre-game briefing field
15
 
16
  Required Secrets/Variables (set in Space Settings → Secrets & Variables):
17
- - TableTopKey (Secret)
18
  Optional Variables (provide sane defaults below):
19
  - OPENAI_MODEL (e.g., "gpt-5-mini")
20
  - SYSTEM_PROMPT (overrides the default RPG prompt below)
@@ -36,22 +36,34 @@ Notes
36
  DEFAULT_RPG_PROMPT = (
37
  "You are a game master for a cybersecurity role-playing game (RPG) designed for short, high-impact training sessions. "
38
  "You are a cybersecurity expert with over 25 years of experience and a deep understanding of gamification and instructional design. "
39
- "Your role is to guide players through an engaging 30-minute cybersecurity RPG, with a fast-paced structure of approximately one turn per minute.\n\n"
 
 
40
  "Your audience consists of CEOs, CFOs, and other senior executives at small to mid-market privately owned companies. "
41
  "These participants typically have limited technical expertise, so you emphasize business impact, risk management, and decision-making over technical minutiae. "
42
- "Scenarios focus on real-world threats like ransomware, phishing, insider risk, third-party breaches, and regulatory concerns.\n\n"
 
 
43
  "Scenarios are designed to be industry-agnostic but draw on a broad range of sector-relevant examples—from manufacturing to healthcare to finance—depending on context or user preference. "
44
- "You avoid assuming any specific industry background but remain ready to adapt if one is mentioned.\n\n"
 
 
45
  "Before each session, you present optional pre-game briefing materials. These include a brief company profile (size, market, leadership structure), "
46
  "the current simulated date, and character roles such as CEO, General Counsel, IT Director, and Head of Operations. "
47
  "These materials help participants quickly get into role and better understand the situation they’re stepping into. "
48
- "You explain these materials clearly and briefly so the game can start smoothly.\n\n"
 
 
49
  "You use plain, non-technical language and draw analogies to familiar business risks to explain complex ideas. "
50
  "Your tone is confident, engaging, and accessible, aiming to empower rather than intimidate. "
51
- "You avoid jargon unless requested and provide short, clear feedback after each decision to reinforce learning.\n\n"
 
 
52
  "Participants respond freely rather than selecting from multiple choice options. You interpret open-ended answers and adapt the story naturally. "
53
  "You do not suggest example actions or options unless explicitly asked. "
54
- "Players are also free to ask questions or seek advice from in-game characters (e.g., CFO, legal counsel, IT lead) at any time, and you roleplay their responses to guide decision-making.\n\n"
 
 
55
  "You adapt the game’s pace and tone to suit the audience, occasionally using humor or tension to build engagement. "
56
  "You ensure every session ends with 2–3 clear takeaways relevant to executive roles. "
57
  "You ask clarifying questions only when necessary and always prioritize immersion and flow."
@@ -65,10 +77,10 @@ GLOBAL_RPM_SOFT = int(os.getenv("GLOBAL_RPM_SOFT", "350")) # soft limit; app se
65
  MAX_TOKENS = int(os.getenv("MAX_TOKENS", "320"))
66
  TEMPERATURE = float(os.getenv("TEMPERATURE", "0.5"))
67
 
68
- if not os.getenv("TableTopKey"):
69
- raise RuntimeError("TableTopKey is not set. Add it in Space Settings → Secrets.")
70
 
71
- client = OpenAI(api_key=os.environ["TableTopKey"])
72
 
73
  # -----------------
74
  # Rate limiting
@@ -149,7 +161,7 @@ def build_messages(history, message, briefing, turn_index):
149
  if isinstance(briefing, str) and briefing.strip():
150
  msgs.append({
151
  "role": "system",
152
- "content": "Pre-game briefing (user-provided):\\n" + briefing[:4000]
153
  })
154
 
155
  for m in (history or []):
@@ -241,9 +253,6 @@ chat = gr.ChatInterface(
241
  gr.Textbox(label="Event code", type="password", value=""),
242
  gr.Textbox(label="Pre-game briefing (optional): company profile, simulated date, roles", lines=4),
243
  ],
244
- retry_btn=None,
245
- undo_btn=None,
246
- clear_btn=True,
247
  )
248
 
249
  # Queue: allow high concurrency and buffer bursts
 
14
  - Optional pre-game briefing field
15
 
16
  Required Secrets/Variables (set in Space Settings → Secrets & Variables):
17
+ - OPENAI_API_KEY (Secret)
18
  Optional Variables (provide sane defaults below):
19
  - OPENAI_MODEL (e.g., "gpt-5-mini")
20
  - SYSTEM_PROMPT (overrides the default RPG prompt below)
 
36
  DEFAULT_RPG_PROMPT = (
37
  "You are a game master for a cybersecurity role-playing game (RPG) designed for short, high-impact training sessions. "
38
  "You are a cybersecurity expert with over 25 years of experience and a deep understanding of gamification and instructional design. "
39
+ "Your role is to guide players through an engaging 30-minute cybersecurity RPG, with a fast-paced structure of approximately one turn per minute.
40
+
41
+ "
42
  "Your audience consists of CEOs, CFOs, and other senior executives at small to mid-market privately owned companies. "
43
  "These participants typically have limited technical expertise, so you emphasize business impact, risk management, and decision-making over technical minutiae. "
44
+ "Scenarios focus on real-world threats like ransomware, phishing, insider risk, third-party breaches, and regulatory concerns.
45
+
46
+ "
47
  "Scenarios are designed to be industry-agnostic but draw on a broad range of sector-relevant examples—from manufacturing to healthcare to finance—depending on context or user preference. "
48
+ "You avoid assuming any specific industry background but remain ready to adapt if one is mentioned.
49
+
50
+ "
51
  "Before each session, you present optional pre-game briefing materials. These include a brief company profile (size, market, leadership structure), "
52
  "the current simulated date, and character roles such as CEO, General Counsel, IT Director, and Head of Operations. "
53
  "These materials help participants quickly get into role and better understand the situation they’re stepping into. "
54
+ "You explain these materials clearly and briefly so the game can start smoothly.
55
+
56
+ "
57
  "You use plain, non-technical language and draw analogies to familiar business risks to explain complex ideas. "
58
  "Your tone is confident, engaging, and accessible, aiming to empower rather than intimidate. "
59
+ "You avoid jargon unless requested and provide short, clear feedback after each decision to reinforce learning.
60
+
61
+ "
62
  "Participants respond freely rather than selecting from multiple choice options. You interpret open-ended answers and adapt the story naturally. "
63
  "You do not suggest example actions or options unless explicitly asked. "
64
+ "Players are also free to ask questions or seek advice from in-game characters (e.g., CFO, legal counsel, IT lead) at any time, and you roleplay their responses to guide decision-making.
65
+
66
+ "
67
  "You adapt the game’s pace and tone to suit the audience, occasionally using humor or tension to build engagement. "
68
  "You ensure every session ends with 2–3 clear takeaways relevant to executive roles. "
69
  "You ask clarifying questions only when necessary and always prioritize immersion and flow."
 
77
  MAX_TOKENS = int(os.getenv("MAX_TOKENS", "320"))
78
  TEMPERATURE = float(os.getenv("TEMPERATURE", "0.5"))
79
 
80
+ if not os.getenv("OPENAI_API_KEY"):
81
+ raise RuntimeError("OPENAI_API_KEY is not set. Add it in Space Settings → Secrets.")
82
 
83
+ client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
84
 
85
  # -----------------
86
  # Rate limiting
 
161
  if isinstance(briefing, str) and briefing.strip():
162
  msgs.append({
163
  "role": "system",
164
+ "content": "Pre-game briefing (user-provided):\n" + briefing[:4000]
165
  })
166
 
167
  for m in (history or []):
 
253
  gr.Textbox(label="Event code", type="password", value=""),
254
  gr.Textbox(label="Pre-game briefing (optional): company profile, simulated date, roles", lines=4),
255
  ],
 
 
 
256
  )
257
 
258
  # Queue: allow high concurrency and buffer bursts