Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,8 @@ DATA_DIR = Path("/data")
|
|
| 17 |
DATA_DIR.mkdir(exist_ok=True)
|
| 18 |
USAGE_DB_PATH = DATA_DIR / "usage_limits.json"
|
| 19 |
|
|
|
|
|
|
|
| 20 |
def load_usage_db() -> dict:
|
| 21 |
"""Load the usage database from disk."""
|
| 22 |
if USAGE_DB_PATH.exists():
|
|
@@ -56,7 +58,7 @@ def check_and_update_usage(username: str) -> bool:
|
|
| 56 |
user_data["count"] = 0
|
| 57 |
|
| 58 |
# Check if limit reached
|
| 59 |
-
if user_data["count"] >=
|
| 60 |
return False
|
| 61 |
|
| 62 |
# Increment count
|
|
@@ -72,15 +74,15 @@ def get_remaining_generations(username: str) -> int:
|
|
| 72 |
today = str(date.today())
|
| 73 |
|
| 74 |
if username not in db:
|
| 75 |
-
return
|
| 76 |
|
| 77 |
user_data = db[username]
|
| 78 |
|
| 79 |
# Reset if it's a new day
|
| 80 |
if user_data["date"] != today:
|
| 81 |
-
return
|
| 82 |
|
| 83 |
-
return max(0,
|
| 84 |
|
| 85 |
# --- Google Gemini API Configuration ---
|
| 86 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
|
|
|
|
| 17 |
DATA_DIR.mkdir(exist_ok=True)
|
| 18 |
USAGE_DB_PATH = DATA_DIR / "usage_limits.json"
|
| 19 |
|
| 20 |
+
DAILY_LIMIT = 50
|
| 21 |
+
|
| 22 |
def load_usage_db() -> dict:
|
| 23 |
"""Load the usage database from disk."""
|
| 24 |
if USAGE_DB_PATH.exists():
|
|
|
|
| 58 |
user_data["count"] = 0
|
| 59 |
|
| 60 |
# Check if limit reached
|
| 61 |
+
if user_data["count"] >= DAILY_LIMIT:
|
| 62 |
return False
|
| 63 |
|
| 64 |
# Increment count
|
|
|
|
| 74 |
today = str(date.today())
|
| 75 |
|
| 76 |
if username not in db:
|
| 77 |
+
return DAILY_LIMIT
|
| 78 |
|
| 79 |
user_data = db[username]
|
| 80 |
|
| 81 |
# Reset if it's a new day
|
| 82 |
if user_data["date"] != today:
|
| 83 |
+
return DAILY_LIMIT
|
| 84 |
|
| 85 |
+
return max(0, DAILY_LIMIT - user_data["count"])
|
| 86 |
|
| 87 |
# --- Google Gemini API Configuration ---
|
| 88 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
|