fiel1986 commited on
Commit
9462b28
·
verified ·
1 Parent(s): 949b775

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -186,25 +186,32 @@ def autofix_loop(client, messages, main_code, ext, max_tokens, temperature, top_
186
  return codigo_actual, ultima, False
187
 
188
 
189
- # ─── SISTEMA DE LÍMITES ───
190
 
191
  def decrement_usage():
192
  global _USAGES
193
- _USAGES["count"] += 1
194
- return DEMO_LIMIT - _USAGES["count"]
195
-
 
 
 
 
 
 
196
 
197
  def check_usage(token):
198
- """Retorna (ok, restante, footer_extra)"""
199
  if token:
200
- return True, -1, "" # -1 = ilimitado (usa su propia key)
201
- if _USAGES["blocked"]:
202
- return False, 0, "\n\n⛔ **Demo agotado.** Usa tu propia API key de Groq para continuar."
 
 
 
 
203
  restante = decrement_usage()
204
- if restante <= 0:
205
- _USAGES["blocked"] = True
206
- return True, 0, "\n\n⛔ **Límite de 100 demos alcanzado.** Obtén tu key en [console.groq.com/keys](https://console.groq.com/keys) para uso ilimitado."
207
- return True, restante, None
208
 
209
 
210
  @spaces.GPU
@@ -307,8 +314,8 @@ def run_chat(message, history, user_context, max_tokens, temperature, top_p, tok
307
 
308
  # ─── UI ───
309
 
310
- with gr.Blocks(title="Aura Programadora") as demo:
311
- gr.Markdown("# 💻 Aura Programadora (Groq)")
312
  with gr.Row():
313
  with gr.Column(scale=3):
314
  chatbot = gr.Chatbot(label="Chat", height=500)
 
186
  return codigo_actual, ultima, False
187
 
188
 
189
+ # limite de api
190
 
191
  def decrement_usage():
192
  global _USAGES
193
+ # En lugar de sumar infinitamente y restar,
194
+ # podemos llevar un contador de cuántas le quedan directamente
195
+ if "restantes" not in _USAGES:
196
+ _USAGES["restantes"] = 100 # Tu límite inicial de demos
197
+
198
+ if _USAGES["restantes"] > 0:
199
+ _USAGES["restantes"] -= 1
200
+
201
+ return _USAGES["restantes"]
202
 
203
  def check_usage(token):
204
+ # 1. Si el usuario trae su propio token, se pasa sin límites
205
  if token:
206
+ return True, -1, ""
207
+
208
+ # 2. Verificamos si ya está bloqueado por completo
209
+ if _USAGES.get("blocked", False):
210
+ return False, 0, "\n\n🔴 **Demo agotado.** Usa tu propia API Key para continuar."
211
+
212
+ # 3. Restamos una consulta
213
  restante = decrement_usage()
214
+
 
 
 
215
 
216
 
217
  @spaces.GPU
 
314
 
315
  # ─── UI ───
316
 
317
+ with gr.Blocks(title="Aura Code") as demo:
318
+ gr.Markdown("# 💻 Aura Code")
319
  with gr.Row():
320
  with gr.Column(scale=3):
321
  chatbot = gr.Chatbot(label="Chat", height=500)