Spaces:
Sleeping
Sleeping
Update app.py
Browse files209 unmodified lines210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241209 unmodified linesdef load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):# --- Anti-Abuse Check Start ---if model_name in self.used_models:# Move to the end to mark as the most recently used (prevents it from being forgotten)self.used_models.remove(model_name)self.used_models.append(model_name)else:current_time = datetime.now()# Retain history of new model requests from the last 20 minutes (1200 seconds)self.new_model_history = [t for t in self.new_model_historyif (current_time - t).total_seconds() < 1200]# Allow a maximum of 5 NEW model requests per 20 minutesif len(self.new_model_history) >= 5:yield "Rate limit exceeded: Too many new models requested."raise gr.Error("Too many new models requested. Please reuse your previously loaded models or wait a few minutes before trying new ones.")# Log the new model attemptself.new_model_history.append(current_time)self.used_models.append(model_name)# Prevent the bypass list from growing infinitely (cap at 5 most recent models)if len(self.used_models) > 5:self.used_models.pop(0)# --- Anti-Abuse Check End ---lock_key = model_name209 unmodified lines210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242209 unmodified linesdef load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):if model_name != model_list[0]:# --- Anti-Abuse Check Start ---if model_name in self.used_models:# Move to the end to mark as the most recently used (prevents it from being forgotten)self.used_models.remove(model_name)self.used_models.append(model_name)else:current_time = datetime.now()# Retain history of new model requests from the last 20 minutes (1200 seconds)self.new_model_history = [t for t in self.new_model_historyif (current_time - t).total_seconds() < 1200]# Allow a maximum of 5 NEW model requests per 20 minutesif len(self.new_model_history) >= 5:yield "Rate limit exceeded: Too many new models requested."raise gr.Error("Too many new models requested. Please reuse your previously loaded models or wait a few minutes before trying new ones.")# Log the new model attemptself.new_model_history.append(current_time)self.used_models.append(model_name)# Prevent the bypass list from growing infinitely (cap at 5 most recent models)if len(self.used_models) > 5:self.used_models.pop(0)# --- Anti-Abuse Check End ---lock_key = model_name
app.py+27-26