Hermes Bot commited on
Commit
c4c7f89
·
unverified ·
1 Parent(s): b58e783

fix: handle None genre from Gradio API input

Browse files

- Default genre to 'fantasy' when Gradio passes None
- Fix generate_procedural_step None check
- Resolve AttributeError: 'NoneType' object has no attribute 'lower'

Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -171,7 +171,7 @@ GENRES = {
171
 
172
  def generate_procedural_step(genre: str, step: int, health: int, choice: str = "") -> dict:
173
  """Generate a fallback adventure step without LLM."""
174
- genre_data = GENRES.get(genre.lower(), GENRES["fantasy"])
175
 
176
  if step == 0:
177
  return {
@@ -360,8 +360,10 @@ def create_gradio_app() -> gr.Blocks:
360
  game_over_output = gr.Checkbox(label="Game Over")
361
  history_output = gr.Textbox(label="History JSON")
362
 
363
- def api_start_game(genre: str):
364
  """Start a new interactive text adventure. Exposed as MCP tool."""
 
 
365
  genre = genre.lower()
366
  if genre not in ["fantasy", "scifi", "cyberpunk"]:
367
  genre = "fantasy"
 
171
 
172
  def generate_procedural_step(genre: str, step: int, health: int, choice: str = "") -> dict:
173
  """Generate a fallback adventure step without LLM."""
174
+ genre_data = GENRES.get((genre or "fantasy").lower(), GENRES["fantasy"])
175
 
176
  if step == 0:
177
  return {
 
360
  game_over_output = gr.Checkbox(label="Game Over")
361
  history_output = gr.Textbox(label="History JSON")
362
 
363
+ def api_start_game(genre: str = "fantasy"):
364
  """Start a new interactive text adventure. Exposed as MCP tool."""
365
+ if not genre:
366
+ genre = "fantasy"
367
  genre = genre.lower()
368
  if genre not in ["fantasy", "scifi", "cyberpunk"]:
369
  genre = "fantasy"