LeafCat79 commited on
Commit
b93c43a
·
verified ·
1 Parent(s): 8572286

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -19
app.py CHANGED
@@ -1,13 +1,10 @@
1
  """
2
- Text-to-Game Generator - Google AI Studio Edition (Truly Free)
3
- - Code : Gemini 2.5 Flash via Google AI Studio (1,500 req/day free, no credit card)
4
  - Images: canvas-drawn graphics only (zero API, zero quota, zero cost)
5
 
6
  No GPU needed. No compilation. No HF quota. No credit card.
7
- Just a Google account and 2 minutes to get a free API key.
8
-
9
- Setup: go to ai.google.dev, sign in with Google, click Get API key.
10
- Then add it as a Space secret named GOOGLE_API_KEY.
11
  """
12
 
13
  import os
@@ -22,26 +19,26 @@ from openai import OpenAI
22
  # Google AI Studio client (OpenAI-compatible endpoint)
23
  # ---------------------------------------------------------------------------
24
 
25
- CODE_MODEL = "gemini-2.5-flash-preview-05-20"
26
- GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY", "")
27
 
28
 
29
  def _check_key():
30
- if not GOOGLE_API_KEY:
31
  raise ValueError(
32
- "GOOGLE_API_KEY is not set.\n"
33
- "1. Go to ai.google.dev\n"
34
- "2. Sign in with any Google account\n"
35
- "3. Click Get API key (free, no credit card, takes 2 minutes)\n"
36
- "4. Add it as a Space secret: Settings > Variables and secrets > Name: GOOGLE_API_KEY"
37
  )
38
 
39
 
40
  def get_client():
41
  _check_key()
42
  return OpenAI(
43
- base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
44
- api_key=GOOGLE_API_KEY,
45
  )
46
 
47
 
@@ -191,9 +188,9 @@ def generate_game_code(game_type: str, theme: str, temperature: float, max_new_t
191
  traceback.print_exc()
192
  err = str(exc)
193
  if "401" in err or "api_key" in err.lower():
194
- err = "Invalid GOOGLE_API_KEY. Check your key at ai.google.dev."
195
- elif "429" in err or "rate" in err.lower() or "quota" in err.lower():
196
- err = "Rate limited - wait a few seconds and try again (1,500 free requests/day)."
197
  else:
198
  err = "Error: " + str(exc)
199
  return "", err, _placeholder_html(err)
 
1
  """
2
+ Text-to-Game Generator - Groq Edition (Truly Free)
3
+ - Code : llama-3.1-8b-instant via Groq API (free, no credit card)
4
  - Images: canvas-drawn graphics only (zero API, zero quota, zero cost)
5
 
6
  No GPU needed. No compilation. No HF quota. No credit card.
7
+ Setup: add GROQ_API_KEY as a Space secret.
 
 
 
8
  """
9
 
10
  import os
 
19
  # Google AI Studio client (OpenAI-compatible endpoint)
20
  # ---------------------------------------------------------------------------
21
 
22
+ CODE_MODEL = "llama-3.1-8b-instant"
23
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
24
 
25
 
26
  def _check_key():
27
+ if not GROQ_API_KEY:
28
  raise ValueError(
29
+ "GROQ_API_KEY is not set.\n"
30
+ "1. Go to console.groq.com and sign in\n"
31
+ "2. Click API Keys > Create API Key\n"
32
+ "3. Copy the key (starts with gsk_)\n"
33
+ "4. Add it as a Space secret: Settings > Variables and secrets > Name: GROQ_API_KEY"
34
  )
35
 
36
 
37
  def get_client():
38
  _check_key()
39
  return OpenAI(
40
+ base_url="https://api.groq.com/openai/v1",
41
+ api_key=GROQ_API_KEY,
42
  )
43
 
44
 
 
188
  traceback.print_exc()
189
  err = str(exc)
190
  if "401" in err or "api_key" in err.lower():
191
+ err = "Invalid GROQ_API_KEY. Check your key at console.groq.com."
192
+ elif "429" in err or "rate" in err.lower():
193
+ err = "Rate limited by Groq - wait a few seconds and try again."
194
  else:
195
  err = "Error: " + str(exc)
196
  return "", err, _placeholder_html(err)