Genia23 commited on
Commit
3ece12e
Β·
verified Β·
1 Parent(s): 255df92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -18
app.py CHANGED
@@ -80,7 +80,7 @@ def update_dynamic_ui(engine):
80
 
81
  # --- ENGINE WRAPPERS FOR GRADIO ---
82
 
83
- def start_engine_ui(world_setting, public_lore, opening_scene, char_list, model, api_key, gm_vibe, steps, memory_len, reflection_int):
84
  if not api_key.strip() or not world_setting.strip() or not char_list or len(char_list) < 1:
85
  yield "❌ Input missing", "", None, gr.update(interactive=False), gr.update(interactive=False)
86
  return
@@ -89,13 +89,14 @@ def start_engine_ui(world_setting, public_lore, opening_scene, char_list, model,
89
  engine = RPGEngine(
90
  world_setting=world_setting,
91
  public_lore=public_lore,
92
- opening_scene=opening_scene,
93
  agents=clean_chars,
94
  model_name=model,
95
  api_key=api_key,
96
  gm_vibe=gm_vibe,
97
  memory_length=memory_len,
98
- reflection_interval=reflection_int
 
 
99
  )
100
 
101
  current_actor = ""
@@ -222,13 +223,17 @@ def load_session(file_obj, api_key):
222
  # Hydrate object directly
223
  engine = RPGEngine.from_dict(data, api_key)
224
 
 
 
 
225
  return (
226
  engine,
227
  "βœ… Save loaded successfully!",
228
  gr.update(value=engine.world_setting),
229
  gr.update(value=engine.public_lore),
230
- gr.update(value=engine.opening_scene),
231
- gr.update(value=engine.gm_vibe),
 
232
  gr.update(value=engine.model_name),
233
  engine.agents,
234
  update_preview(engine.agents),
@@ -239,15 +244,15 @@ def load_session(file_obj, api_key):
239
  gr.update(interactive=True)
240
  )
241
  except Exception as e:
242
- return (None, f"❌ Load error: {str(e)}", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
243
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update())
244
 
245
  # --- GENERATORS WRAPPERS ---
246
 
247
- def gen_full_wrapper(prompt, genre, api_key, model, current_chars):
248
- w_set, w_lore, op_scene, new_chars, status = generate_full_setup(prompt, genre, api_key, model)
249
  combined = (current_chars or []) + new_chars
250
- return w_set, w_lore, op_scene, combined, status, status
251
 
252
  def gen_char_wrapper(prompt, api_key, model, current_chars):
253
  char, status = generate_character_from_prompt(prompt, api_key, model)
@@ -291,10 +296,24 @@ with gr.Blocks(title="🎲 AI RPG Engine", theme=gr.themes.Soft()) as demo:
291
  gr.Markdown("#### 🌍 World Configuration")
292
  world_setting = gr.Textbox(label="GM Secrets & Initial Situation", lines=3, value="The abandoned space station 'Icarus'. The airlock is jammed intentionally by a traitor.")
293
  public_lore = gr.Textbox(label="Public Lore & Genre Rules", lines=3, value="Sci-Fi horror. Everyone knows they have 2 hours of oxygen left. Characters should act paranoid.")
294
- opening_scene = gr.Textbox(label="🎬 Opening Scene (Leave blank for dynamic GM intro)", lines=3, placeholder="A loud crash echoes through the halls, waking everyone up...")
295
  with gr.Row():
296
- gm_vibe = gr.Dropdown(label="🎭 GM Vibe", choices=["Neutral Realism", "Gritty Survival", "Slice of Life", "Fluffy Romance", "Comedy", "Sensual Intimacy", "Explicit NSFW"], value="Gritty Survival", scale=2)
297
- model = gr.Dropdown(label="πŸ€– Model", choices=["deepseek/deepseek-v3.2", "meta-llama/llama-3.3-70b-instruct:free", "arcee-ai/trinity-large-preview:free"], value="deepseek/deepseek-v3.2", allow_custom_value=True, scale=2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  api_key = gr.Textbox(label="πŸ”‘ OpenRouter Key", type="password", value=OPENROUTER_API_KEY)
299
 
300
  with gr.Accordion("βš™οΈ Engine Settings", open=False):
@@ -335,7 +354,7 @@ with gr.Blocks(title="🎲 AI RPG Engine", theme=gr.themes.Soft()) as demo:
335
  char_preview = gr.Markdown("πŸ”Ή _List is empty_")
336
 
337
  with gr.Row():
338
- steps_init = gr.Slider(1, 50, value=4, step=1, label="πŸ”’ Steps to start")
339
  btn_start = gr.Button("πŸš€ Start RPG Simulation", variant="primary", scale=1)
340
  status = gr.Textbox(label="πŸ“Š Status", interactive=False)
341
 
@@ -397,7 +416,7 @@ with gr.Blocks(title="🎲 AI RPG Engine", theme=gr.themes.Soft()) as demo:
397
  # --- UI LOGIC BINDINGS ---
398
 
399
  # Setup Generators
400
- btn_gen_full.click(gen_full_wrapper, inputs=[full_prompt, gen_setting_genre, api_key, model, characters_state], outputs=[world_setting, public_lore, opening_scene, characters_state, full_status, full_status]).then(lambda cl: (cl, update_preview(cl)), inputs=[characters_state], outputs=[df_view, char_preview])
401
  btn_gen_char.click(gen_char_wrapper, inputs=[char_prompt, api_key, model, characters_state], outputs=[characters_state, full_status, edit_name, edit_core, edit_pers, edit_agenda, edit_inv, edit_rel]).then(lambda cl: (cl, update_preview(cl)), inputs=[characters_state], outputs=[df_view, char_preview])
402
 
403
  # Character List Management
@@ -428,13 +447,13 @@ with gr.Blocks(title="🎲 AI RPG Engine", theme=gr.themes.Soft()) as demo:
428
  load_file.upload(
429
  load_session,
430
  inputs=[load_file, api_key],
431
- outputs=[session_state, load_status, world_setting, public_lore, opening_scene, gm_vibe, model, characters_state, char_preview, output_md, memory_length, reflection_interval, btn_cont, btn_exp]
432
  ).then(update_dynamic_ui, inputs=[session_state], outputs=[force_actor, active_char_dropdown, world_state_edit, whisper_char])
433
 
434
  # Core Engine Start & Continue
435
  start_event = btn_start.click(
436
  start_engine_ui,
437
- inputs=[world_setting, public_lore, opening_scene, characters_state, model, api_key, gm_vibe, steps_init, memory_length, reflection_interval],
438
  outputs=[status, output_md, session_state, btn_cont, btn_exp]
439
  )
440
  start_event.then(update_dynamic_ui, inputs=[session_state], outputs=[force_actor, active_char_dropdown, world_state_edit, whisper_char])
@@ -474,5 +493,4 @@ with gr.Blocks(title="🎲 AI RPG Engine", theme=gr.themes.Soft()) as demo:
474
  btn_story.click(stream_chapter_wrapper, inputs=[session_state, api_key, model], outputs=[story_output, story_file])
475
 
476
  if __name__ == "__main__":
477
- demo.launch()
478
-
 
80
 
81
  # --- ENGINE WRAPPERS FOR GRADIO ---
82
 
83
+ def start_engine_ui(world_setting, public_lore, char_list, model, api_key, gm_vibe, custom_vibe_instr, story_arc, steps, memory_len, reflection_int):
84
  if not api_key.strip() or not world_setting.strip() or not char_list or len(char_list) < 1:
85
  yield "❌ Input missing", "", None, gr.update(interactive=False), gr.update(interactive=False)
86
  return
 
89
  engine = RPGEngine(
90
  world_setting=world_setting,
91
  public_lore=public_lore,
 
92
  agents=clean_chars,
93
  model_name=model,
94
  api_key=api_key,
95
  gm_vibe=gm_vibe,
96
  memory_length=memory_len,
97
+ reflection_interval=reflection_int,
98
+ custom_vibe_instructions=custom_vibe_instr,
99
+ story_arc=story_arc
100
  )
101
 
102
  current_actor = ""
 
223
  # Hydrate object directly
224
  engine = RPGEngine.from_dict(data, api_key)
225
 
226
+ # Normalize gm_vibe: support old str format and new list format
227
+ raw_vibe = engine.gm_vibe
228
+ vibe_value = raw_vibe if isinstance(raw_vibe, list) else ([raw_vibe] if raw_vibe else ["Neutral Realism"])
229
  return (
230
  engine,
231
  "βœ… Save loaded successfully!",
232
  gr.update(value=engine.world_setting),
233
  gr.update(value=engine.public_lore),
234
+ gr.update(value=vibe_value),
235
+ gr.update(value=engine.custom_vibe_instructions),
236
+ gr.update(value=getattr(engine, 'story_arc', '')),
237
  gr.update(value=engine.model_name),
238
  engine.agents,
239
  update_preview(engine.agents),
 
244
  gr.update(interactive=True)
245
  )
246
  except Exception as e:
247
+ return (None, f"❌ Load error: {str(e)}", gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(),
248
  gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update())
249
 
250
  # --- GENERATORS WRAPPERS ---
251
 
252
+ def gen_full_wrapper(prompt, genre, api_key, model, current_chars, gm_vibe):
253
+ w_set, w_lore, new_chars, status = generate_full_setup(prompt, genre, api_key, model, gm_vibe=gm_vibe)
254
  combined = (current_chars or []) + new_chars
255
+ return w_set, w_lore, combined, status, status
256
 
257
  def gen_char_wrapper(prompt, api_key, model, current_chars):
258
  char, status = generate_character_from_prompt(prompt, api_key, model)
 
296
  gr.Markdown("#### 🌍 World Configuration")
297
  world_setting = gr.Textbox(label="GM Secrets & Initial Situation", lines=3, value="The abandoned space station 'Icarus'. The airlock is jammed intentionally by a traitor.")
298
  public_lore = gr.Textbox(label="Public Lore & Genre Rules", lines=3, value="Sci-Fi horror. Everyone knows they have 2 hours of oxygen left. Characters should act paranoid.")
 
299
  with gr.Row():
300
+ model = gr.Dropdown(label="πŸ€– Model", choices=["deepseek/deepseek-v3.2", "meta-llama/llama-3.3-70b-instruct:free", "arcee-ai/trinity-large-preview:free"], value="deepseek/deepseek-v3.2", allow_custom_value=True)
301
+ gm_vibe = gr.CheckboxGroup(
302
+ label="🎭 GM Vibe (select one or more)",
303
+ choices=[
304
+ "Neutral Realism", "Gritty Survival", "Slice of Life", "Fluffy Romance",
305
+ "Comedy", "Dark Comedy", "Psychological Horror", "Epic High Drama",
306
+ "Cozy Mystery", "Action Adventure", "Political Intrigue",
307
+ "Mythic Folklore", "Philosophical Slow Burn",
308
+ "── ❀️‍πŸ”₯ Adult / NSFW ──",
309
+ "Sensual Intimacy", "Slow Burn to Explicit", "Explicit NSFW",
310
+ "Dominant & Submissive", "Rough & Primal", "Forbidden Desire",
311
+ "Monster Romance", "Harem Dynamics"
312
+ ],
313
+ value=["Gritty Survival"]
314
+ )
315
+ custom_vibe_instr = gr.Textbox(label="✍️ Custom Vibe Instructions (optional)", lines=2, placeholder="Add your own instructions to complement the selected vibe, e.g.: 'Use lots of sarcasm' or 'Write in a Victorian style'")
316
+ story_arc = gr.Textbox(label="🎯 Global Story Arc Goal (optional)", lines=2, placeholder="e.g. 'The traitor must be exposed before the station loses power' β€” GM will steer the narrative toward this goal.")
317
  api_key = gr.Textbox(label="πŸ”‘ OpenRouter Key", type="password", value=OPENROUTER_API_KEY)
318
 
319
  with gr.Accordion("βš™οΈ Engine Settings", open=False):
 
354
  char_preview = gr.Markdown("πŸ”Ή _List is empty_")
355
 
356
  with gr.Row():
357
+ steps_init = gr.Slider(1, 50, value=3, step=1, label="πŸ”’ Steps to start")
358
  btn_start = gr.Button("πŸš€ Start RPG Simulation", variant="primary", scale=1)
359
  status = gr.Textbox(label="πŸ“Š Status", interactive=False)
360
 
 
416
  # --- UI LOGIC BINDINGS ---
417
 
418
  # Setup Generators
419
+ btn_gen_full.click(gen_full_wrapper, inputs=[full_prompt, gen_setting_genre, api_key, model, characters_state, gm_vibe], outputs=[world_setting, public_lore, characters_state, full_status, full_status]).then(lambda cl: (cl, update_preview(cl)), inputs=[characters_state], outputs=[df_view, char_preview])
420
  btn_gen_char.click(gen_char_wrapper, inputs=[char_prompt, api_key, model, characters_state], outputs=[characters_state, full_status, edit_name, edit_core, edit_pers, edit_agenda, edit_inv, edit_rel]).then(lambda cl: (cl, update_preview(cl)), inputs=[characters_state], outputs=[df_view, char_preview])
421
 
422
  # Character List Management
 
447
  load_file.upload(
448
  load_session,
449
  inputs=[load_file, api_key],
450
+ outputs=[session_state, load_status, world_setting, public_lore, gm_vibe, custom_vibe_instr, story_arc, model, characters_state, char_preview, output_md, memory_length, reflection_interval, btn_cont, btn_exp]
451
  ).then(update_dynamic_ui, inputs=[session_state], outputs=[force_actor, active_char_dropdown, world_state_edit, whisper_char])
452
 
453
  # Core Engine Start & Continue
454
  start_event = btn_start.click(
455
  start_engine_ui,
456
+ inputs=[world_setting, public_lore, characters_state, model, api_key, gm_vibe, custom_vibe_instr, story_arc, steps_init, memory_length, reflection_interval],
457
  outputs=[status, output_md, session_state, btn_cont, btn_exp]
458
  )
459
  start_event.then(update_dynamic_ui, inputs=[session_state], outputs=[force_actor, active_char_dropdown, world_state_edit, whisper_char])
 
493
  btn_story.click(stream_chapter_wrapper, inputs=[session_state, api_key, model], outputs=[story_output, story_file])
494
 
495
  if __name__ == "__main__":
496
+ demo.launch()