Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,8 @@ headers = {
|
|
12 |
|
13 |
# Rate limiting configuration
|
14 |
request_times = defaultdict(list)
|
15 |
-
MAX_REQUESTS = 1
|
16 |
-
TIME_WINDOW =
|
17 |
|
18 |
def get_real_ip(request: gr.Request):
|
19 |
"""Extract real IP address using x-forwarded-for header or fallback"""
|
@@ -35,13 +35,8 @@ def check_rate_limit(request: gr.Request):
|
|
35 |
ip = get_real_ip(request)
|
36 |
now = time.time()
|
37 |
|
38 |
-
print(f"Ip: {ip}")
|
39 |
-
print(f"Now: {now}")
|
40 |
-
print(f"Request times: {request_times[ip]}")
|
41 |
-
# Clean up old timestamps outside the time window
|
42 |
request_times[ip] = [t for t in request_times[ip] if now - t < TIME_WINDOW]
|
43 |
|
44 |
-
print(f"Request times: {request_times[ip]}")
|
45 |
|
46 |
# Check if rate limit exceeded
|
47 |
if len(request_times[ip]) >= MAX_REQUESTS:
|
|
|
12 |
|
13 |
# Rate limiting configuration
|
14 |
request_times = defaultdict(list)
|
15 |
+
MAX_REQUESTS = 1
|
16 |
+
TIME_WINDOW = 120
|
17 |
|
18 |
def get_real_ip(request: gr.Request):
|
19 |
"""Extract real IP address using x-forwarded-for header or fallback"""
|
|
|
35 |
ip = get_real_ip(request)
|
36 |
now = time.time()
|
37 |
|
|
|
|
|
|
|
|
|
38 |
request_times[ip] = [t for t in request_times[ip] if now - t < TIME_WINDOW]
|
39 |
|
|
|
40 |
|
41 |
# Check if rate limit exceeded
|
42 |
if len(request_times[ip]) >= MAX_REQUESTS:
|