Spaces:
Running
Running
Yiqiao Jin
commited on
Commit
·
9ccabd0
1
Parent(s):
5c646c9
Add daily usage limit
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import json
|
2 |
import re
|
|
|
|
|
3 |
from glob import glob
|
4 |
from argparse import Namespace
|
5 |
|
@@ -42,6 +44,39 @@ MAX_NUM_PLAYERS = 5
|
|
42 |
DEFAULT_NUM_PLAYERS = 5
|
43 |
CURRENT_STEP_INDEX = 0
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
def load_examples():
|
46 |
example_configs = {}
|
47 |
# Load json config files from examples folder
|
@@ -572,6 +607,14 @@ Simulate conference reviews on your own papers using LLM agents.
|
|
572 |
|
573 |
def step_game(all_comps: dict):
|
574 |
global CURRENT_STEP_INDEX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
575 |
|
576 |
yield {
|
577 |
btn_step: gr.update(value="Running...", interactive=False),
|
|
|
1 |
import json
|
2 |
import re
|
3 |
+
import os
|
4 |
+
from datetime import datetime
|
5 |
from glob import glob
|
6 |
from argparse import Namespace
|
7 |
|
|
|
44 |
DEFAULT_NUM_PLAYERS = 5
|
45 |
CURRENT_STEP_INDEX = 0
|
46 |
|
47 |
+
|
48 |
+
|
49 |
+
USAGE_FILE = "usage_counter.json"
|
50 |
+
MAX_DAILY_USES = 500
|
51 |
+
|
52 |
+
# Initialize or load usage data
|
53 |
+
if not os.path.exists(USAGE_FILE):
|
54 |
+
usage_data = {"count": 0, "date": str(datetime.now().date())}
|
55 |
+
with open(USAGE_FILE, "w") as f:
|
56 |
+
json.dump(usage_data, f)
|
57 |
+
else:
|
58 |
+
with open(USAGE_FILE, "r") as f:
|
59 |
+
usage_data = json.load(f)
|
60 |
+
|
61 |
+
# Function to update usage count
|
62 |
+
def update_usage_count():
|
63 |
+
today = str(datetime.now().date())
|
64 |
+
print(f"Usage Count: {usage_data['count']}")
|
65 |
+
if usage_data["date"] != today:
|
66 |
+
# Reset the counter for a new day
|
67 |
+
usage_data["date"] = today
|
68 |
+
usage_data["count"] = 0
|
69 |
+
|
70 |
+
if usage_data["count"] >= MAX_DAILY_USES:
|
71 |
+
return False # Limit reached
|
72 |
+
|
73 |
+
# Increment the counter
|
74 |
+
usage_data["count"] += 1
|
75 |
+
with open(USAGE_FILE, "w") as f:
|
76 |
+
json.dump(usage_data, f)
|
77 |
+
|
78 |
+
return True
|
79 |
+
|
80 |
def load_examples():
|
81 |
example_configs = {}
|
82 |
# Load json config files from examples folder
|
|
|
607 |
|
608 |
def step_game(all_comps: dict):
|
609 |
global CURRENT_STEP_INDEX
|
610 |
+
|
611 |
+
# Check usage limit
|
612 |
+
if not update_usage_count():
|
613 |
+
yield {
|
614 |
+
btn_step: gr.update(value="Usage Limit Reached", interactive=False),
|
615 |
+
btn_restart: gr.update(interactive=True),
|
616 |
+
}
|
617 |
+
return
|
618 |
|
619 |
yield {
|
620 |
btn_step: gr.update(value="Running...", interactive=False),
|