turtle170 commited on
Commit
1da1cd0
·
verified ·
1 Parent(s): ca2f825

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -392,7 +392,7 @@ class TokenManager:
392
  def initialize_user(self, username: str):
393
  """Initialize new user with monthly credits (or infinite for owner)"""
394
  if not username:
395
- username = "anonymous"
396
 
397
  if username not in self.user_tokens:
398
  # Owner gets infinite tokens
@@ -438,7 +438,7 @@ class TokenManager:
438
  def charge_usage(self, username: str, duration_ms: float) -> bool:
439
  """Charge user for inference time. Returns True if successful. Owner never charged."""
440
  if not username:
441
- username = "anonymous"
442
 
443
  self.initialize_user(username)
444
  self.check_monthly_reset(username)
@@ -574,7 +574,7 @@ class TokenManager:
574
  def get_balance(self, username: str) -> float:
575
  """Get user's current token balance"""
576
  if not username:
577
- username = "anonymous"
578
 
579
  self.initialize_user(username)
580
  self.check_monthly_reset(username)
@@ -590,7 +590,7 @@ class TokenManager:
590
  def get_purchases(self, username: str) -> dict:
591
  """Get user's current purchases"""
592
  if not username:
593
- username = "anonymous"
594
 
595
  self.initialize_user(username)
596
  return self.user_tokens[username]["purchases"]
@@ -1049,6 +1049,14 @@ class ZeroEngine:
1049
 
1050
  def inference_generator(self, prompt: str, history: List[Dict], ghost_context: str, repo: str, quant: str, profile: gr.OAuthProfile | None) -> Generator:
1051
  username = profile.username if profile else "anonymous"
 
 
 
 
 
 
 
 
1052
  # Update activity timestamp
1053
  self.update_activity()
1054
 
 
392
  def initialize_user(self, username: str):
393
  """Initialize new user with monthly credits (or infinite for owner)"""
394
  if not username:
395
+ return # DO NOT initialize anonymous users
396
 
397
  if username not in self.user_tokens:
398
  # Owner gets infinite tokens
 
438
  def charge_usage(self, username: str, duration_ms: float) -> bool:
439
  """Charge user for inference time. Returns True if successful. Owner never charged."""
440
  if not username:
441
+ return False # DO NOT charge anonymous users
442
 
443
  self.initialize_user(username)
444
  self.check_monthly_reset(username)
 
574
  def get_balance(self, username: str) -> float:
575
  """Get user's current token balance"""
576
  if not username:
577
+ return 0.0 # Anonymous users get 0 balance
578
 
579
  self.initialize_user(username)
580
  self.check_monthly_reset(username)
 
590
  def get_purchases(self, username: str) -> dict:
591
  """Get user's current purchases"""
592
  if not username:
593
+ return {"batch_size": 512, "max_tokens": 2048} # Anonymous users get defaults
594
 
595
  self.initialize_user(username)
596
  return self.user_tokens[username]["purchases"]
 
1049
 
1050
  def inference_generator(self, prompt: str, history: List[Dict], ghost_context: str, repo: str, quant: str, profile: gr.OAuthProfile | None) -> Generator:
1051
  username = profile.username if profile else "anonymous"
1052
+
1053
+ # COMPLETELY BLOCK ANONYMOUS USERS
1054
+ if not profile or not profile.username:
1055
+ error_message = "🚫 Oops, you are not logged in!\n\nPlease log in to use ZeroEngine. Anonymous access is not allowed."
1056
+ history.append({"role": "assistant", "content": error_message})
1057
+ yield history
1058
+ return
1059
+
1060
  # Update activity timestamp
1061
  self.update_activity()
1062