LeafCat79 commited on
Commit
a505043
·
verified ·
1 Parent(s): 84ab022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -31,7 +31,7 @@ HF_TOKEN = os.environ.get("HF_TOKEN", "")
31
 
32
  CODE_MODEL = "llama-3.1-8b-instant" # Groq — game code
33
  PROMPT_MODEL = "llama-3.3-70b-versatile" # Groq — better model for creative prompts
34
- IMAGE_MODEL = "black-forest-labs/FLUX.1-schnell" # nscale
35
 
36
 
37
  def get_groq_client():
@@ -49,7 +49,7 @@ def get_groq_client():
49
  def get_image_client():
50
  if not HF_TOKEN:
51
  return None
52
- return InferenceClient(provider="nscale", api_key=HF_TOKEN)
53
 
54
 
55
  # ---------------------------------------------------------------------------
@@ -260,15 +260,16 @@ def generate_sprites(image_prompts: dict) -> dict:
260
  sprite_map[sprite_name] = _colored_placeholder(sprite_name.replace(".png", ""))
261
  continue
262
  try:
263
- # Background gets full size, sprites get 64x64
264
  is_bg = "background" in sprite_name
265
  pil_img = image_client.text_to_image(prompt, model=IMAGE_MODEL)
266
  size = None if is_bg else (64, 64)
267
  sprite_map[sprite_name] = _pil_to_data_uri(pil_img, size=size)
268
- print(f"[FLUX] Generated {sprite_name}")
269
  except Exception as exc:
270
- print(f"[FLUX] Failed {sprite_name}: {exc}")
271
- sprite_map[sprite_name] = _colored_placeholder(sprite_name.replace(".png", ""))
 
272
 
273
  return sprite_map
274
 
 
31
 
32
  CODE_MODEL = "llama-3.1-8b-instant" # Groq — game code
33
  PROMPT_MODEL = "llama-3.3-70b-versatile" # Groq — better model for creative prompts
34
+ IMAGE_MODEL = "black-forest-labs/FLUX.1-schnell" # hf-inference
35
 
36
 
37
  def get_groq_client():
 
49
  def get_image_client():
50
  if not HF_TOKEN:
51
  return None
52
+ return InferenceClient(provider="hf-inference", api_key=HF_TOKEN)
53
 
54
 
55
  # ---------------------------------------------------------------------------
 
260
  sprite_map[sprite_name] = _colored_placeholder(sprite_name.replace(".png", ""))
261
  continue
262
  try:
263
+ # Background gets full canvas size, sprites get 64x64
264
  is_bg = "background" in sprite_name
265
  pil_img = image_client.text_to_image(prompt, model=IMAGE_MODEL)
266
  size = None if is_bg else (64, 64)
267
  sprite_map[sprite_name] = _pil_to_data_uri(pil_img, size=size)
268
+ print(f"[FLUX] Generated {sprite_name} OK")
269
  except Exception as exc:
270
+ error_msg = str(exc)
271
+ print(f"[FLUX] FAILED {sprite_name}: {error_msg}")
272
+ sprite_map[sprite_name] = ("ERROR:" + error_msg, _colored_placeholder(sprite_name.replace(".png", "")))[1]
273
 
274
  return sprite_map
275